Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown fixes #321

Merged
merged 4 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg shell-session? Really?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 😞

}
if (!infostring || infostring.length <= 0) {

if (!infostring) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I never think of "" as a false-y value 🙄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, it took me a while to notice it

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