MCPcopy Create free account
hub / github.com/hackmdio/codimd / generateToc

Function generateToc

public/js/extra.js:955–997  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

953
954// toc
955export function generateToc (id) {
956 const target = $(`#${id}`)
957 target.html('')
958 /* eslint-disable no-unused-vars */
959
960 var tocOptions = md.meta.toc || {}
961 var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : window.defaultTocDepth
962
963 var toc = new window.Toc('doc', {
964 level: maxLevel,
965 top: -1,
966 class: 'toc',
967 ulClass: 'nav',
968 targetId: id,
969 process: getHeaderContent
970 })
971 /* eslint-enable no-unused-vars */
972 if (target.text() === 'undefined') { target.html('') }
973 checkExpandToggle()
974 const tocMenu = $('body').children('.toc-menu')
975 target.append(tocMenu.clone().show())
976 const toggle = $('.expand-toggle', target)
977 const backtotop = $('.back-to-top', target)
978 const gotobottom = $('.go-to-bottom', target)
979 toggle.click(e => {
980 e.preventDefault()
981 e.stopPropagation()
982 tocExpand = !tocExpand
983 checkExpandToggle()
984 })
985 backtotop.click(e => {
986 e.preventDefault()
987 e.stopPropagation()
988 if (window.scrollToTop) { window.scrollToTop() }
989 removeHash()
990 })
991 gotobottom.click(e => {
992 e.preventDefault()
993 e.stopPropagation()
994 if (window.scrollToBottom) { window.scrollToBottom() }
995 removeHash()
996 })
997}
998
999// smooth all hash trigger scrolling
1000export function smoothHashScroll () {

Callers 2

pretty.jsFile · 0.90
updateViewInnerFunction · 0.90

Calls 2

checkExpandToggleFunction · 0.85
removeHashFunction · 0.85

Tested by

no test coverage detected