diff options
author | John Olheiser <42128690+jolheiser@users.noreply.github.com> | 2019-12-23 16:38:50 -0600 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-12-23 22:38:50 +0000 |
commit | e6ceb6880a8615ad5b8b6a88a0b1bfbd85f4033c (patch) | |
tree | 5ffdd08dbf265b35f1405683242a4c8c80ff41eb /web_src | |
parent | 071e7c4f0a31ee8b2039b90bb478f13cac62abae (diff) | |
download | gitea-e6ceb6880a8615ad5b8b6a88a0b1bfbd85f4033c.tar.gz gitea-e6ceb6880a8615ad5b8b6a88a0b1bfbd85f4033c.zip |
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>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/index.js | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js index 8600acc95c..395a01f059 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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>`); }); }); |