Skip to content

Commit

Permalink
docs: Preserve updated query param content and add config option links (
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro authored Jul 3, 2020
2 parents bd51e8e + 2f634fb commit 37ec56d
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
.searchCondition > div {
margin-right: 30px;
}
.header-link {
position: relative;
}
.header-link:hover::before {
position: absolute;
left: -2em;
padding-right: 0.5em;
content: '\2002\00a7\2002';
}
</style>
</head>
<body>
Expand Down Expand Up @@ -137,12 +146,27 @@
}, []);
ast.links = {};

queryParams.set('version', this.version);
queryParams.set('search', this.searchCondition);
const curUrl = window.location.pathname +
'?' + queryParams.toString() + window.location.hash;
history.pushState(null, '', curUrl);

const renderer = new marked.Renderer();
renderer.heading = function(text, level) {
const id = htmlToId(text);
return `<h${level}>
<a href="#${id}" name="${id}" class="header-link">${text}</a>
</h${level}>`;
};

return marked.parser(ast, {
highlight(code, lang) {
return hljs.highlight(lang ? lang : 'rust', code).value;
},
headerIds: true,
headerPrefix: ''
headerPrefix: '',
renderer,
});
}
},
Expand All @@ -156,13 +180,10 @@
},
mounted() {
if (UrlHash === '') return;
const interval = setInterval(() => {
const target = document.querySelector(`#${UrlHash}`);
if (target != null) {
target.scrollIntoView(true);
clearInterval(interval);
}
}, 100);
const target = document.querySelector(`#${UrlHash}`);
if (target != null) {
target.scrollIntoView(true);
}
}
});
const extractDepthOnes = (ast) => {
Expand Down Expand Up @@ -228,6 +249,11 @@
configurationDescriptions
};
}
function htmlToId(text) {
const tmpl = document.createElement('template');
tmpl.innerHTML = text.trim();
return encodeURIComponent(CSS.escape(tmpl.content.textContent));
}
</script>
</body>
</html>

0 comments on commit 37ec56d

Please sign in to comment.