Fix: Fix for the non-English character generation of Anchor Link#2045
Fix: Fix for the non-English character generation of Anchor Link#2045fhemberger merged 2 commits intomasterfrom unknown repository
Conversation
|
Looks good to me, but I definitely defer to @fhemberger and others on this stuff. |
|
@Trott:Thanks! |
fhemberger
left a comment
There was a problem hiding this comment.
Thank you, this looks really great. I'd probably add handling of unwanted whitespaces, though. Just to be sure.
There was a problem hiding this comment.
const ANCHOR_COMMENTREG = /<!--\x20?([\w-]+)\x20?-->/gi
Matches <!--comment-->, <!-- comment --> and even <!-- comment -->
(20 hex = 32 dec = space character)
There was a problem hiding this comment.
If we do the matching directly in the RegExp above, we can use anchorTitle = anchorTitleArray[1].
There was a problem hiding this comment.
Now const raw = '<!-- anchor-With-Non-English-Characters -->这是[链接](b)c[测试!](d)' would work as well.
I. In the recent days we've fixed the non-English character generation of anchor link by directly using the pure HTML tags, however a better way is: 1) Check whether the current title has the comment symbol (<!---->). 2) If yes, just take the characters out of the symbol as the anchor link's name, with the real text as the title behind it. 3) If not, just do replacements as what it used to be. The advantage is that you can keep the anchor link the same as what it is in the English version or define by yourself. What's more: It's much more flexible when your change the level of titles, compared with #2028. II. Add '--fix' for local test to automatically fix some simple formation typo errors.
|
Thanks @fhemberger! |
|
@Maledong : in Arabic anchors #1973 you can just change Unicode and the same in "CJK" |
|
@Aissaoui-Ahmed:Yes, it's been in this submit, thanks for tipping me :) |
|
Great, thank you! |
I. In the recent days we've fixed the non-English character generation
of anchor link by directly using the pure HTML tags, however a better
way is:
link's name, with the real text as the title behind it.
This will be processed as <h2>这是非英语的标题<a href = '#abc'……>……</h2>
The advantage is that you can keep the anchor link the same as what
it is in the English version or define by yourself. What's more: It's
much more flexible when your change the level of titles, compared with
#2028.
II. Add '--fix' for local test to automatically fix some simple formation typo errors.