Prefix all user-generated IDs in markup (#9477)

* Prefix all user-generated IDs in markup
* Add user-content- to IDs in unit-tests
* fixup markdown_test.go
* update the hrefs for the wiki test
* Add blackfriday extension regex

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser 2019-12-23 16:38:50 -06:00 committed by zeripath
parent 071e7c4f0a
commit e6ceb6880a
5 changed files with 24 additions and 24 deletions

View file

@ -2472,21 +2472,10 @@ $(document).ready(() => {
// Set anchor.
$('.markdown').each(function () {
const headers = {};
$(this).find('h1, h2, h3, h4, h5, h6').each(function () {
let node = $(this);
const val = encodeURIComponent(node.text().toLowerCase().replace(/[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]/g, '').replace(/[ ]/g, '-'));
let name = val;
if (headers[val] > 0) {
name = `${val}-${headers[val]}`;
}
if (headers[val] === undefined) {
headers[val] = 1;
} else {
headers[val] += 1;
}
node = node.wrap(`<div id="${name}" class="anchor-wrap" ></div>`);
node.append(`<a class="anchor" href="#${name}"><span class="octicon octicon-link"></span></a>`);
node = node.wrap('<div class="anchor-wrap"></div>');
node.append(`<a class="anchor" href="#${encodeURIComponent(node.attr('id'))}"><span class="octicon octicon-link"></span></a>`);
});
});