(view)
| 1115 | } |
| 1116 | |
| 1117 | export function deduplicatedHeaderId (view) { |
| 1118 | // headers contained in the last change |
| 1119 | const headers = view.find(':header.raw').removeClass('raw').toArray() |
| 1120 | if (headers.length === 0) { |
| 1121 | return |
| 1122 | } |
| 1123 | if (window.linkifyHeaderStyle === 'gfm') { |
| 1124 | // consistent with GitHub, GitLab, Pandoc & co. |
| 1125 | // all headers contained in the document, in order of appearance |
| 1126 | const allHeaders = view.find(':header').toArray() |
| 1127 | // list of finaly assigned header IDs |
| 1128 | const headerIds = new Set() |
| 1129 | for (let j = 0; j < allHeaders.length; j++) { |
| 1130 | const $header = $(allHeaders[j]) |
| 1131 | const id = $header.attr('id') |
| 1132 | const newId = createHeaderId(getHeaderContent($header), headerIds) |
| 1133 | changeHeaderId($header, id, newId) |
| 1134 | } |
| 1135 | } else { |
| 1136 | // the legacy way |
| 1137 | for (let i = 0; i < headers.length; i++) { |
| 1138 | const id = $(headers[i]).attr('id') |
| 1139 | if (!id) continue |
| 1140 | const duplicatedHeaders = view.find(`:header[id="${id}"]`).toArray() |
| 1141 | for (let j = 0; j < duplicatedHeaders.length; j++) { |
| 1142 | if (duplicatedHeaders[j] !== headers[i]) { |
| 1143 | const newId = id + j |
| 1144 | const $header = $(duplicatedHeaders[j]) |
| 1145 | changeHeaderId($header, id, newId) |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | export function renderTOC (view) { |
| 1153 | const tocs = view.find('.toc').toArray() |
no test coverage detected