

解析 Html 自动生成目录 TOC 的相关代码
source link: https://surest.cn/archives/170/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

解析 Html 自动生成目录 TOC 的相关代码
function create_content_TOC(dom, config, target) {
let hList = dom.find('h1,h2,h3,h4,h5,h6');
console.log(hList);
target.html('');
if (!hList[0]) {
target.html('');
target.hide();
return;
}
target.show();
let haStyle = {
opacity: 0.65,
position: 'absolute',
marginLeft: '-1em',
paddingRight: '0.5em'
};
hList.each(function(i, item) {
let hTag = $(item),
title = hTag.text();
let tag = hTag.get(0).localName;
let id = `md-title-item${i}`;
let mgLeft = (tag[1] - 2) * 15;
let ha = $(`<a class="anchor-link</a>"`);
let a = $(`<a data-tag="${tag}" class="${tag == 'h1' ? '' : config.class}" href="#${id}"> ${hTag.text()}</a>`);
ha.attr('href', '#' + id).css(haStyle);
hTag.attr('id', id)
.addClass('content-htag')
.prepend(ha);
a.attr('title', title)
.addClass('toc-' + tag)
.css({ marginLeft: mgLeft, display: 'block' });
console.log(a);
target.append(a);
});
}

https://github.com/posthtml/posthtml-toc
本文由 邓尘锋 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: May 8, 2021 at 11:09 am
Recommend
-
35
-
4
org module之org-toc org-toc可以为当前Org文件生成一个目录,在这个目录中导航可以跳转到相应的Org位置上。 不过鉴于org本来就是个大纲类的模式,所以我觉得这个module意义不大啊。 在带标题的Org文件(没有标题的话会提示错误)中运行
-
16
markdown-toc Table of Contents A simple mode to create TOC in a well-formed markdown file. Note that the TOC is well-formed if the markdown is (cf. #15). Create Inside a markdown file...
-
23
日常工作/生活中,遇到的比较好的ToC或ToB的产品有哪些? 目前只找到了producthunt、创造者日报、新趣集有收录一些新的产品,国内其它的36kr、IT桔子、爱范儿旗下的新产品收录平台也都关了,大家在工作中有什么好的平...
-
5
ToC端高客单价产品的社群转化模型 东巴拉运营 2021-08-29 0 评论...
-
8
Boris Jamot ✊ / Posted on Sep 7, 2018 ...
-
16
V2EX › Python fastapi 中自动生成的 openapi3 怎样设置二级目录 skyone123 · 4 小...
-
3
toB和toC业务,数据分析怎么做? 接地气的陈老师 2022-04-11 2 评论...
-
4
Extracting a TOC from MarkupFebruary 5, 2017 · 2 min · Benjamin BengfortIn today’s addition of “really simple things that come in handy all the time” I present a simple script to extract the table of contents from mar...
-
4
【笔记】通过i5ting_toc将md文件转换为html文件 2022-12-11 通过i5ting_toc将md文件转换为html文件 npm install -g i5ting_toc
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK