Skip to content

Commit

Permalink
chore(deps): update marked (#4636)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Jan 9, 2024
1 parent 2f6a7fb commit a5391fb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/marked": "^4.3.2",
"@types/pluralize": "0.0.33",
"boxen": "^7.1.1",
"chokidar": "^3.5.3",
Expand Down Expand Up @@ -89,7 +88,7 @@
"dependencies": {
"colors": "1.4.0",
"finalhandler": "^1.2.0",
"marked": "^4.3.0",
"marked": "^11.1.1",
"puppeteer": "^21.7.0",
"sade": "^1.8.1",
"serve-static": "^1.15.0"
Expand Down
17 changes: 5 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/core/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
* property of the configuration object to "markdown."
*
* We use marked for parsing Markdown:
* https://github.com/chjj/marked
* https://github.com/markedjs/marked
*
*/

import { getElementIndentation, reindent } from "./utils.js";
import { marked } from "./import-maps.js";

export const name = "core/markdown";

const gtEntity = />/gm;
const ampEntity = /&/gm;

class Renderer extends marked.Renderer {
code(code, infoString, isEscaped) {
const { language, ...metaData } = Renderer.parseInfoString(infoString);
Expand All @@ -26,7 +28,9 @@ class Renderer extends marked.Renderer {
return `<pre class="idl">${code}</pre>`;
}

const html = super.code(code, language, isEscaped);
const html = super
.code(code, language, isEscaped)
.replace(`class="language-`, `class="`);

const { example, illegalExample } = metaData;
if (!example && !illegalExample) return html;
Expand Down Expand Up @@ -72,21 +76,19 @@ class Renderer extends marked.Renderer {
return { language, ...metaData };
}

heading(text, level, raw, slugger) {
heading(text, level, raw) {
const headingWithIdRegex = /(.+)\s+{#([\w-]+)}$/;
if (headingWithIdRegex.test(text)) {
const [, textContent, id] = text.match(headingWithIdRegex);
return `<h${level} id="${id}">${textContent}</h${level}>`;
}
return super.heading(text, level, raw, slugger);
return super.heading(text, level, raw);
}
}

/** @type {import('marked').MarkedOptions} */
const config = {
sanitize: false,
gfm: true,
headerIds: false,
langPrefix: "",
renderer: new Renderer(),
};

Expand Down
4 changes: 1 addition & 3 deletions tests/spec/core/markdown-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ describe("Core - Markdown", () => {
expect(webidlBlock.querySelector(".respec-button-copy-paste")).toBeTruthy();

expect(jsBlock.firstElementChild.localName).toBe("code");
expect(
jsBlock.querySelector("code.hljs").classList.contains("js")
).toBeTruthy();
expect(jsBlock.querySelector("code.hljs").classList).toContain("js");
expect(jsBlock.querySelector("code.hljs span")).not.toBeNull();
expect(jsBlock.querySelector(".respec-button-copy-paste")).toBeNull();

Expand Down

0 comments on commit a5391fb

Please sign in to comment.