Skip to content

Commit 37ec56d

Browse files
authored
docs: Preserve updated query param content and add config option links (#4307)
2 parents bd51e8e + 2f634fb commit 37ec56d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

Diff for: docs/index.html

+34-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
.searchCondition > div {
4242
margin-right: 30px;
4343
}
44+
.header-link {
45+
position: relative;
46+
}
47+
.header-link:hover::before {
48+
position: absolute;
49+
left: -2em;
50+
padding-right: 0.5em;
51+
content: '\2002\00a7\2002';
52+
}
4453
</style>
4554
</head>
4655
<body>
@@ -137,12 +146,27 @@
137146
}, []);
138147
ast.links = {};
139148

149+
queryParams.set('version', this.version);
150+
queryParams.set('search', this.searchCondition);
151+
const curUrl = window.location.pathname +
152+
'?' + queryParams.toString() + window.location.hash;
153+
history.pushState(null, '', curUrl);
154+
155+
const renderer = new marked.Renderer();
156+
renderer.heading = function(text, level) {
157+
const id = htmlToId(text);
158+
return `<h${level}>
159+
<a href="#${id}" name="${id}" class="header-link">${text}</a>
160+
</h${level}>`;
161+
};
162+
140163
return marked.parser(ast, {
141164
highlight(code, lang) {
142165
return hljs.highlight(lang ? lang : 'rust', code).value;
143166
},
144167
headerIds: true,
145-
headerPrefix: ''
168+
headerPrefix: '',
169+
renderer,
146170
});
147171
}
148172
},
@@ -156,13 +180,10 @@
156180
},
157181
mounted() {
158182
if (UrlHash === '') return;
159-
const interval = setInterval(() => {
160-
const target = document.querySelector(`#${UrlHash}`);
161-
if (target != null) {
162-
target.scrollIntoView(true);
163-
clearInterval(interval);
164-
}
165-
}, 100);
183+
const target = document.querySelector(`#${UrlHash}`);
184+
if (target != null) {
185+
target.scrollIntoView(true);
186+
}
166187
}
167188
});
168189
const extractDepthOnes = (ast) => {
@@ -228,6 +249,11 @@
228249
configurationDescriptions
229250
};
230251
}
252+
function htmlToId(text) {
253+
const tmpl = document.createElement('template');
254+
tmpl.innerHTML = text.trim();
255+
return encodeURIComponent(CSS.escape(tmpl.content.textContent));
256+
}
231257
</script>
232258
</body>
233259
</html>

0 commit comments

Comments
 (0)