-
-
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
toc helper should not parse the text of children element(s) #174
Comments
Is this issue show up in Hexo 4.1.1? I am wondering if the problem is the different behavior between |
@SukkaW I updated hexojs/hexo-renderer-markdown-it#102 |
Can confirm the issue in hexo-util 1.8.1: const { tocObj } = require('hexo-util')
const text = '<h3 id="create-a-new-post"><a class="header-anchor" href="#create-a-new-post">#</a>Create a new post</h3>'
console.log(tocObj(text))
/*
[
{
text: '#Create a new post',
id: 'create-a-new-post',
level: 3
}
]
*/ |
<h1 id="title-3"><span>Title</span> 3</h3> In this case |
Edit: no newline by default |
Currently, <h3 id="create-a-new-post">
<a class="header-anchor" href="#create-a-new-post">#</a>Create a new post
</h3> will become Update
|
Looks like a common question in cheerio/jquery,
Seems possible to fix, if htmlparser has the equivalent function of native DOM's |
When contents likes this <h2><span id="title_1">title 1</span></h2> tocObj won't parse the correct id, So I edit the getId function, then work. const getId = ele => {
const { id } = ele.attribs;
const { children } = ele;
return id || (!children[0] ? null : getId(children[0]));
}; |
@Microbai |
@SukkaW I Knew it.But when I use Hexo 4.2, the page can't render toc correctly.So I edit tocObj for now, and it works. |
Check List
Please check followings before submitting a new feature request.
Feature Request
Fix the toc helper to select only text content and not other sub-elements like links.
In depth explanation here: hexojs/hexo-renderer-markdown-it#102
The text was updated successfully, but these errors were encountered: