some tweaks to the visibility of the code on the readme

This commit is contained in:
Ken
2019-02-27 13:26:45 -08:00
parent 4ce7af1152
commit 37685e102f
5 changed files with 155 additions and 130 deletions

View File

@@ -1,4 +1,4 @@
import marked from 'marked';
import marked, { Renderer } from 'marked';
import hljs from 'highlight.js/lib/highlight';
import javascript from 'highlight.js/lib/languages/javascript';
import typescript from 'highlight.js/lib/languages/typescript';
@@ -10,27 +10,28 @@ async function run() {
const div = document.getElementById('markdownReadme');
// // Create your custom renderer.
// const renderer = new Renderer();
// renderer.code = (code, language) => {
// // Check whether the given language is valid for highlight.js.
// const validLang = !!(language && highlightjs.getLanguage(language));
// // Highlight only if the language is valid.
// const highlighted = validLang ? highlightjs.highlight(language, code).value : code;
// // Render the highlighted code with `hljs` class.
// return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
// };
const renderer = new Renderer();
renderer.code = (code, language) => {
// Check whether the given language is valid for highlight.js.
const validLang = !!(language && hljs.getLanguage(language));
// Highlight only if the language is valid.
const highlighted = validLang ? hljs.highlight(language, code).value : code;
// Render the highlighted code with `hljs` class.
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
marked.setOptions({ renderer });
if (typeof hljs != 'undefined') {
marked.setOptions({
highlight: function(code, lang) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(lang, code).value;
} else {
return code;
}
}
});
}
// if (typeof hljs != 'undefined') {
// marked.setOptions({
// highlight: function(code, lang) {
// if (lang && hljs.getLanguage(lang)) {
// return hljs.highlight(lang, code).value;
// } else {
// return code;
// }
// }
// });
// }
if (div) {
const response = await fetch('../README.md');