Skip to content

Commit

Permalink
Markdown fixes (#321)
Browse files Browse the repository at this point in the history
* Update packages

* Correctly escape code blocks. Fixes #316

* Wait, why?

* Support shell sessions
  • Loading branch information
jakearchibald committed Jun 19, 2020
1 parent 21f96a5 commit c5f49cf
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 210 deletions.
19 changes: 12 additions & 7 deletions lib/markdown-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@
* limitations under the License.
*/
import { Renderer } from 'marked';
import { escape } from 'marked/src/helpers';
import Prism from 'prismjs';
import 'prismjs/components/prism-shell-session';

export function createRenderer() {
const renderer = new Renderer();
renderer.code = (code, infostring, escaped) => {
// We don’t have syntax highlighting for shell, but we use it in our
// README.md. This is a workaround so that rendering teh README.md
// succeeds and we can rip out the first paragraph.
renderer.code = (code, infostring) => {
// Aliasing sh, as that's common on github
if (infostring === 'sh') {
infostring = '';
infostring = 'shell-session';
}
if (!infostring || infostring.length <= 0) {

if (!infostring) {
return `
<pre class="language-text"><code class="language-text">${code}</code></pre>`;
<pre class="language-text"><code class="language-text">${escape(
code,
)}</code></pre>`;
}

if (!(infostring in Prism.languages)) {
throw Error(`Unsupported language "${infostring}"`);
}

return `
<pre class="language-${infostring}"><code class="language-${infostring}">${Prism.highlight(
code,
Expand Down

0 comments on commit c5f49cf

Please sign in to comment.