mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
feat(v2): render Markdown on server-side instead (#1077)
* feat(v2): render Markdown on server-side instead * move to folder
This commit is contained in:
parent
d479f42ff5
commit
6cec7ce982
6 changed files with 173 additions and 177 deletions
30
v2/lib/webpack/loaders/markdown/anchors.js
Normal file
30
v2/lib/webpack/loaders/markdown/anchors.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const toSlug = require('./toSlug');
|
||||
|
||||
function anchors(md) {
|
||||
const originalRender = md.renderer.rules.heading_close;
|
||||
|
||||
// eslint-disable-next-line
|
||||
md.renderer.rules.heading_close = function(tokens, idx, options, env) {
|
||||
const textToken = tokens[idx - 1];
|
||||
|
||||
if (textToken.content) {
|
||||
const anchor = toSlug(textToken.content, env);
|
||||
|
||||
return ` <a aria-hidden="true" id="${anchor}"></a><a aria-hidden="true" class="hash-link" href="#${anchor}">#</a></h${
|
||||
tokens[idx].hLevel
|
||||
}>
|
||||
`;
|
||||
}
|
||||
|
||||
return originalRender(tokens, idx, options, env);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = anchors;
|
Loading…
Add table
Add a link
Reference in a new issue