Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2982: Improve _HTMLWordTruncator #3002

Merged

Conversation

manhhomienbienthuy
Copy link
Contributor

Pull Request Checklist

Resolves: #2982

  • Ensured tests pass and (if applicable) updated functional test output
  • Conformed to code style guidelines by running appropriate linting tools
  • Added tests for changed code
  • Updated documentation for changed code (Not necessary)

@avaris
Copy link
Member

avaris commented May 6, 2022

I was thinking about this recently. I don't like the maintainability of keep adding alphabet blocks. I'm sure it is probably not generally true but can we assume anything outside DBC is latin-like (words separated by space)? That should simplify the regex with some generalizability. Something like, special casing DBC but reverting to original implementation as a fallback:

    _word_regex = re.compile(r"{DBC}|(\w[\w'-]*)".format(
        # DBC means CJK-like characters. An character can stand for a word.
        DBC=("([\u4E00-\u9FFF])|"          # CJK Unified Ideographs
             "([\u3400-\u4DBF])|"          # CJK Unified Ideographs Extension A
             "([\uF900-\uFAFF])|"          # CJK Compatibility Ideographs
             "([\U00020000-\U0002A6DF])|"  # CJK Unified Ideographs Extension B
             "([\U0002F800-\U0002FA1F])|"  # CJK Compatibility Ideographs Supplement
             "([\u3040-\u30FF])|"          # Hiragana and Katakana
             "([\u1100-\u11FF])|"          # Hangul Jamo
             "([\uAC00-\uD7FF])|"          # Hangul Compatibility Jamo
             "([\u3130-\u318F])"           # Hangul Syllables
             )), re.UNICODE)

If I remember correctly, this was producing correct results but I didn't test extensively. Mainly because I don't speak Vietnamese, so I wasn't sure about my tests being proper :).

@manhhomienbienthuy
Copy link
Contributor Author

@avaris
Thanks for your comments. I completely agree with you that we can assume anything outside DBC is latin-like. I changed the code and it works perfectly for Vietnamese 😃

Copy link
Member

@avaris avaris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@justinmayer
Copy link
Member

Many thanks to @manhhomienbienthuy for the enhancement and to @avaris for reviewing. 🏅

@justinmayer justinmayer merged commit d5d7920 into getpelican:master Jul 11, 2022
pauloxnet pushed a commit to pauloxnet/pelican that referenced this pull request Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SUMMARY_MAX_LENGTH is applied in a wrong way to Vietnamese content
3 participants