1 Star 0 Fork 34

码农/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_updateHeading.js 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-09-03 17:21 . chore: update
import trim from './utils/lang/trim'
import createElement from './utils/dom/createElement'
import setAttributes from './utils/dom/setAttributes'
import icon from './utils/icons/icon'
const _updateHeading = ($heading, i, options) => {
const CLS_HEADING = 'outline-heading'
const hasAnchor = options.hasAnchor || true
const isAtStart = options.isAtStart || true
const showCode = options.showCode || false
const chapterCode = options.chapterCode || ''
const anchorURL = options.anchorURL || ''
const headingId = `heading-${i}`
const attrs = {
id: headingId,
className: isAtStart ? `${CLS_HEADING} ${CLS_HEADING}_start` : CLS_HEADING,
'data-id': i
}
const text = trim($heading.innerHTML)
let $anchor
let $icon
if (showCode) {
attrs.innerHTML = chapterCode + ' ' + text
}
setAttributes($heading, attrs)
if (!hasAnchor) {
return false
}
$icon = icon('hash', { iconSet: 'outline' })
$anchor = createElement(
'a',
{
id: `anchor-${i}`,
className: `${CLS_HEADING}__anchor anchor-${i}`,
href: anchorURL || `#${headingId}`,
target: anchorURL ? '_blank' : 'self',
'data-id': i
},
$icon
)
$heading.appendChild($anchor)
}
export default _updateHeading
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/1821599293/outline.js.git
git@gitee.com:1821599293/outline.js.git
1821599293
outline.js
outline.js
master

搜索帮助