(headerContent, headerIds = null)
| 1045 | } |
| 1046 | |
| 1047 | const createHeaderId = (headerContent, headerIds = null) => { |
| 1048 | // to escape characters not allow in css and humanize |
| 1049 | const slug = slugifyWithUTF8(headerContent) |
| 1050 | let id |
| 1051 | if (window.linkifyHeaderStyle === 'keep-case') { |
| 1052 | id = slug |
| 1053 | } else if (window.linkifyHeaderStyle === 'lower-case') { |
| 1054 | // to make compatible with GitHub, GitLab, Pandoc and many more |
| 1055 | id = slug.toLowerCase() |
| 1056 | } else if (window.linkifyHeaderStyle === 'gfm') { |
| 1057 | // see GitHub implementation reference: |
| 1058 | // https://gist.github.com/asabaylus/3071099#gistcomment-1593627 |
| 1059 | // it works like 'lower-case', but ... |
| 1060 | const idBase = slug.toLowerCase() |
| 1061 | id = idBase |
| 1062 | if (headerIds !== null) { |
| 1063 | // ... making sure the id is unique |
| 1064 | let i = 1 |
| 1065 | while (headerIds.has(id)) { |
| 1066 | id = idBase + '-' + i |
| 1067 | i++ |
| 1068 | } |
| 1069 | headerIds.add(id) |
| 1070 | } |
| 1071 | } else { |
| 1072 | throw new Error('Unknown linkifyHeaderStyle value "' + window.linkifyHeaderStyle + '"') |
| 1073 | } |
| 1074 | return id |
| 1075 | } |
| 1076 | |
| 1077 | const linkifyAnchors = (level, containingElement) => { |
| 1078 | const headers = containingElement.getElementsByTagName(`h${level}`) |
no test coverage detected