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

Function linkifyAnchors

public/js/extra.js:1077–1091  ·  view source on GitHub ↗
(level, containingElement)

Source from the content-addressed store, hash-verified

1075}
1076
1077const linkifyAnchors = (level, containingElement) => {
1078 const headers = containingElement.getElementsByTagName(`h${level}`)
1079
1080 for (let i = 0, l = headers.length; i < l; i++) {
1081 const header = headers[i]
1082 if (header.getElementsByClassName('anchor').length === 0) {
1083 if (typeof header.id === 'undefined' || header.id === '') {
1084 header.id = createHeaderId(getHeaderContent(header))
1085 }
1086 if (!(typeof header.id === 'undefined' || header.id === '')) {
1087 header.insertBefore(anchorForId(header.id), header.firstChild)
1088 }
1089 }
1090 }
1091}
1092
1093export function autoLinkify (view) {
1094 const contentBlock = view[0]

Callers 1

autoLinkifyFunction · 0.85

Calls 3

createHeaderIdFunction · 0.85
getHeaderContentFunction · 0.85
anchorForIdFunction · 0.85

Tested by

no test coverage detected