mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
[markdown] Remove client-side syntax highlighting (#189)
* Remove client side highlighting * Update CSS rules to render plain code blocks with expected left border * Add back codeColor background color config * Ensure all pre code blocks use Highlight.js classes
This commit is contained in:
parent
f72df94dd3
commit
fb294ab845
4 changed files with 25 additions and 17 deletions
|
@ -7,6 +7,9 @@ const toSlug = require("./toSlug.js");
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
/**
|
||||
* The anchors plugin adds GFM-style anchors to headings.
|
||||
*/
|
||||
function anchors(md) {
|
||||
md.renderer.rules.heading_open = function(tokens, idx /*, options, env */) {
|
||||
return '<h' + tokens[idx].hLevel + '>' + '<a class="anchor" name="' + toSlug(tokens[idx+1].content) + '"></a>';
|
||||
|
@ -53,6 +56,9 @@ class Remarkable extends React.Component {
|
|||
renderMarkdown(source) {
|
||||
if (!this.md) {
|
||||
this.md = new Markdown({
|
||||
// Highlight.js expects hljs css classes on the code element.
|
||||
// This results in <pre><code class="hljs css javascript">
|
||||
langPrefix: 'hljs css ',
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
|
@ -64,7 +70,7 @@ class Remarkable extends React.Component {
|
|||
return hljs.highlightAuto(str).value;
|
||||
} catch (err) {}
|
||||
|
||||
return ''; // use external default escaping
|
||||
return '';
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -81,7 +87,9 @@ class Remarkable extends React.Component {
|
|||
|
||||
}
|
||||
|
||||
return this.md.render(source);
|
||||
// Ensure fenced code blocks use Highlight.js hljs class
|
||||
// https://github.com/jonschlinkert/remarkable/issues/224
|
||||
return this.md.render(source).replace('<pre><code>','<pre><code class="hljs">');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue