1 Star 0 Fork 34

/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_paintChapters.js 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
import createElement from './utils/dom/createElement'
const _paintChapters = ($list, chapters, showCode = false) => {
const byId = (id) => $list.querySelector(`#${id}`)
chapters.forEach((chapter) => {
const pid = chapter.pid
const id = chapter.id
const rel = chapter.rel
const children = []
const $text = createElement(
'span',
{
className: 'outline-chapters__text'
},
chapter.text
)
let $link
let $code
let $li
let $subject
let $chapter
if (showCode) {
$code = createElement(
'span',
{
className: 'outline-chapters__code',
'data-id': id
},
chapter.code
)
children.push($code)
}
children.push($text)
$link = createElement(
'a',
{
id: `chapter__anchor-${id}`,
className: 'outline-chapters__anchor',
href: '#' + rel,
rel: rel,
'data-id': id
},
children
)
$li = createElement(
'li',
{
id: `chapter-${id}`,
className: 'outline-chapters__item',
'data-id': id
},
$link
)
if (pid === -1) {
$list.appendChild($li)
} else {
$chapter = byId(`chapter-${pid}`)
$subject = byId(`subject-${pid}`)
if (!$subject) {
$subject = createElement(
'ul',
{
id: 'subject-' + pid,
className: 'outline-chapters__subject'
},
$li
)
$chapter.appendChild($subject)
} else {
$subject.appendChild($li)
}
}
})
}
export default _paintChapters
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/qdplatform/outline.js.git
git@gitee.com:qdplatform/outline.js.git
qdplatform
outline.js
outline.js
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385