-
-
Notifications
You must be signed in to change notification settings - Fork 59
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(tocObj): skip permalink symbol #175
Conversation
73ac878
to
efaada6
Compare
test/toc_obj.spec.js
Outdated
const input = [ | ||
'<h1 id="foo"><a>#</a>bar</h1>', | ||
'<h1 id="foo">bar<a>#</a></h1>', | ||
'<h1 id="foo"><a>#</a>bar<a>#</a></h1>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'<h1 id="foo"><a>#</a>bar<a>#</a></h1>' | |
'<h1 id="foo"><a>#</a>bar<a>#</a></h1>', | |
'<h1 id="foo"><a>#</a><span>bar</span><a>#</a></h1>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<h1 id="foo"><a>#</a><span>bar</span><a>#</a></h1>
would result in #bar#
though since bar
is wrapped in a children element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workaround can be if (element.type === 'text' || element.type === 'span')
.
<h1><a>#</a><span>bar</span><a>#</a></h1>
-> bar
But the workaround is not foolproof,
<h1><a>#</a>hey<span>bar</span><a>#</a></h1>
-> hey
<h1><a>#</a><span>bar</span>hey<a>#</a></h1>
-> bar
Since for..of
doesn't necessarily follow order, the result can be erratic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The children tag could be anything: <span>
, <a>
even <p>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
@curbengh So what happened if |
with the new workaround (will commit in a minute),
I think 2nd case is rare, if a user wants to add a link, 1st case would be used. I just thought of another approach, skip |
@curbengh I have a better idea. Using |
efaada6
to
289bdaf
Compare
parameter of which function? |
0f84a37
to
5550c70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation LGTM!
5550c70
to
38a0e5f
Compare
rebased to include #181. |
@curbengh Awesome, this will be released in 1.9.0? 1.8.2? |
should be part of 1.9.0 |
Fixes #174 Closes hexojs/hexo-renderer-markdown-it#102
Permalink (in this context) is a single non-word character, word = [a-Z0-9], and wrapped in
<a>
.It may be wrapped in whitespace(s)
<h1 id="foo"><a>#</a>bar</h1>
<h1 id="foo">bar<a>#</a></h1>
<h1 id="foo"><a>#</a>bar<a>#</a></h1>
bar
bar
bar
#
is treated as a permalink and skipped<h1>号码<a>牌</a></h1>
号码
牌
is treated as a permalink<h1><a>#</a></h1>
#
<h1><a>b</a> two</h1>
b two
b
is not a permalinkreturns empty string
''
instead of null. This is following convention. htmlparser2DomUtils.getText(elNoText)
and camarocamaro.transform(xml, {foo:'invalid'})
also return empty string. This is compatible with toc, as empty string is still falsy (same as null and undefined).