Skip to content

Commit

Permalink
use ::after to show the anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Nov 20, 2018
1 parent 7e442da commit 8553062
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ module.exports = function(grunt) {
},
post: {
files: [
{ expand: true, src: 'viki.html', dest: 'dist/'},
{ expand: true, src: 'viki.html', dest: 'dist/', rename: function(dest, src) {
return dest + 'index.html';
}},
{ expand: true, src: 'js/custom.js', dest: 'dist/'},
{ expand: true, src: 'css/*', dest: 'dist/'},
],
Expand Down
17 changes: 17 additions & 0 deletions css/viki.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,20 @@ x-eqs > span {
text-decoration: none;
opacity: 1;
}

.viki-anchor::after {
content: attr(data-anchor-icon);
}

@media print {
#viki-navi, #viki-toc {
display: none !important;
}

#viki-content {
-ms-flex: 0 0 100% !important;
flex: 0 0 100% !important;
max-width: 100% !important;
padding: 3rem 1.5rem !important;
}
}
8 changes: 1 addition & 7 deletions js/tocrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ class TocRenderer {
for (let i = 0; i < headers.length; ++i) {
let header = headers[i];

let text = header.textContent;
let lastChild = header.lastChild;
if (lastChild && lastChild.tagName === 'A' && lastChild.textContent === '#') {
text = text.substring(0, text.length - 1);
}

this.toc.push({
level: parseInt(header.tagName.substr(1)),
anchor: header.id,
title: utils.escapeHtml(text)
title: utils.escapeHtml(header.textContent)
});
}

Expand Down
10 changes: 6 additions & 4 deletions libs/markdown-it/markdown-it-headinganchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ function makeRule(md, options) {
if (options.addHeadingID) {
// No need to add id in anchor.
anchorToken.content = '<a class="' + options.anchorClass + '" ' +
'href="#' + anchorName + '"' +
'>' + options.anchorIcon + '</a>';
'href="#' + anchorName + '" ' +
'data-anchor-icon="' + options.anchorIcon + '" ' +
'></a>';
} else {
anchorToken.content = '<a id="' + anchorName + '" ' +
'class="' + options.anchorClass + '" ' +
'href="#' + anchorName + '"' +
'>' + options.anchorIcon + '</a>';
'href="#' + anchorName + '" ' +
'data-anchor-icon="' + options.anchorIcon + '" ' +
'></a>';
}

headingInlineToken.children.push(anchorToken);
Expand Down

0 comments on commit 8553062

Please sign in to comment.