summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorWu Cheng-Han2015-09-25 14:27:23 +0800
committerWu Cheng-Han2015-09-25 14:27:23 +0800
commitbc31e9fe3b5a720c369826fe959f9830b98c2ccc (patch)
treeea1b853718e6f3a533b34f9a9225ffef8e18c082 /public
parent44cd5d4b567b1cd69c2b56f6b6b5da3f5e2f7042 (diff)
Added deduplicatedHeaderId to avoid multiple same header id
Diffstat (limited to 'public')
-rw-r--r--public/js/extra.js21
-rw-r--r--public/js/index.js1
-rw-r--r--public/js/pretty.js1
3 files changed, 22 insertions, 1 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index aed97417..f2fd6a72 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -322,7 +322,26 @@ function autoLinkify(view) {
for (var level = 1; level <= 6; level++) {
linkifyAnchors(level, contentBlock);
}
-};
+}
+
+function deduplicatedHeaderId(view) {
+ var headers = view.find(':header').toArray();
+ for (var i = 0; i < headers.length; i++) {
+ var id = $(headers[i]).attr('id');
+ if (!id) continue;
+ var duplicatedHeaders = view.find(':header[id=' + id + ']').toArray();
+ for (var j = 0; j < duplicatedHeaders.length; j++) {
+ if (duplicatedHeaders[j] != headers[i]) {
+ var newId = id + j;
+ var $duplicatedHeader = $(duplicatedHeaders[j]);
+ $duplicatedHeader.attr('id', newId);
+ var $headerLink = $duplicatedHeader.find('> .header-link');
+ $headerLink.attr('href', '#' + newId);
+ $headerLink.attr('title', newId);
+ }
+ }
+ }
+}
function scrollToHash() {
var hash = location.hash;
diff --git a/public/js/index.js b/public/js/index.js
index 86bba7f5..c414b0b5 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1725,6 +1725,7 @@ function updateView() {
lastResult = $(result).clone();
finishView(ui.area.view);
autoLinkify(ui.area.view);
+ deduplicatedHeaderId(ui.area.view);
generateToc('toc');
generateToc('toc-affix');
generateScrollspy();
diff --git a/public/js/pretty.js b/public/js/pretty.js
index 52882e98..ad5655d6 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -5,6 +5,7 @@ markdown.html(result.html());
$(document.body).show();
finishView(markdown);
autoLinkify(markdown);
+deduplicatedHeaderId(markdown);
generateToc('toc');
generateToc('toc-affix');
smoothHashScroll();