Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion scripts/md2html/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,41 @@ const path = require('path');
const url = require('url');

const hljs = require('highlight.js');
hljs.registerLanguage('uritemplate', function() {
return {
case_insensitive: true,
contains: [
{
scope: "attr",
match: /(?<=[{,])[^,}\n\r]+/,
}
],
}
});
hljs.registerLanguage('uri', function() {
return {
case_insensitive: true,
classNameAliases: {
pathsegment: "attr",
option: "attr",
value: "literal"
},
contains: [
{
scope: "pathsegment",
match: /(?<=[/])[^/?#\n\r]+/,
},
{
scope: "option",
match: /(?<=[?&#])[^=?&#\n\r]+/,
},
{
scope: "value",
match: /(?<=\=)[^?&#\n\r]+/,
}
],
}
});
const cheerio = require('cheerio');

let argv = require('yargs')
Expand All @@ -36,7 +71,8 @@ const md = require('markdown-it')({
'</code></pre>';
}

return '<pre class="highlight '+lang+'" tabindex="0"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
if (lang) console.warn('highlight.js does not support language',lang);
return '<pre class="nohighlight" tabindex="0"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
}
});

Expand Down
8 changes: 7 additions & 1 deletion tests/md2html/fixtures/basic-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
</code></pre>
<pre class="nohighlight" tabindex="0"><code>text/plain
</code></pre>
<pre class="highlight " tabindex="0"><code>no language
<pre class="nohighlight" tabindex="0"><code>no language
</code></pre>
<pre class="nohighlight" tabindex="0"><code>unknown language
</code></pre>
<pre class="nohighlight" tabindex="0"><code>https://<span class="hljs-attr">foo.com</span>/<span class="hljs-attr">bar</span>?<span class="hljs-attr">baz</span>=<span class="hljs-literal">qux</span>&amp;<span class="hljs-attr">fred</span>=<span class="hljs-literal">waldo</span>#<span class="hljs-attr">fragment</span>
</code></pre>
<pre class="nohighlight" tabindex="0"><code>https://foo.com/bar{<span class="hljs-attr">?baz*</span>,<span class="hljs-attr">qux</span>}
</code></pre>
</section></section><section class="appendix"><h1>Appendix A: Revision History</h1>
<table>
Expand Down
12 changes: 12 additions & 0 deletions tests/md2html/fixtures/basic-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ text/plain
no language
```

```unknown
unknown language
```

```uri
https://foo.com/bar?baz=qux&fred=waldo#fragment
```

```uritemplate
https://foo.com/bar{?baz*,qux}
```

## Appendix A: Revision History

Version | Date
Expand Down