|
41 | 41 | .searchCondition > div {
|
42 | 42 | margin-right: 30px;
|
43 | 43 | }
|
| 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 | + } |
44 | 53 | </style>
|
45 | 54 | </head>
|
46 | 55 | <body>
|
|
137 | 146 | }, []);
|
138 | 147 | ast.links = {};
|
139 | 148 |
|
| 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 | + |
140 | 163 | return marked.parser(ast, {
|
141 | 164 | highlight(code, lang) {
|
142 | 165 | return hljs.highlight(lang ? lang : 'rust', code).value;
|
143 | 166 | },
|
144 | 167 | headerIds: true,
|
145 |
| - headerPrefix: '' |
| 168 | + headerPrefix: '', |
| 169 | + renderer, |
146 | 170 | });
|
147 | 171 | }
|
148 | 172 | },
|
|
156 | 180 | },
|
157 | 181 | mounted() {
|
158 | 182 | 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 | + } |
166 | 187 | }
|
167 | 188 | });
|
168 | 189 | const extractDepthOnes = (ast) => {
|
|
228 | 249 | configurationDescriptions
|
229 | 250 | };
|
230 | 251 | }
|
| 252 | + function htmlToId(text) { |
| 253 | + const tmpl = document.createElement('template'); |
| 254 | + tmpl.innerHTML = text.trim(); |
| 255 | + return encodeURIComponent(CSS.escape(tmpl.content.textContent)); |
| 256 | + } |
231 | 257 | </script>
|
232 | 258 | </body>
|
233 | 259 | </html>
|
0 commit comments