pantsdown 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantsdown",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "author": "wallpants",
5
5
  "description": "Markdown to 'GitHub HTML' parser",
6
6
  "license": "MIT",
package/src/code-copy.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export const codeCopyScript = `
2
2
  <script id="code-copy-script" type="module">
3
3
  document.querySelectorAll("pre").forEach((pre) => {
4
+ const firstElement = pre.firstElementChild;
5
+ if (!firstElement || firstElement.tagName !== "CODE") return;
6
+
4
7
  const copyButton = document.createElement("button");
5
8
 
6
9
  const innerHTML =
package/src/renderer.ts CHANGED
@@ -32,24 +32,18 @@ export class Renderer {
32
32
  const lang = (infostring ?? "").match(/^\S*/)?.[0];
33
33
  code = code.replace(/\n$/, "") + "\n";
34
34
 
35
- // TODO: render pre and code instead of this section
35
+ const attrs: HTMLAttrs = [];
36
+
36
37
  if (lang === "mermaid") {
37
- return injectHtmlAttributes(
38
- `<section><div class="mermaid">${code}</div></section>`,
39
- [["class", "mermaid-container"]],
40
- sourceMap,
41
- );
38
+ attrs.push(["class", "mermaid-container mermaid"]);
39
+ } else {
40
+ const language = lang && hljs.getLanguage(lang) ? lang : "plaintext";
41
+ code = hljs.highlight(code, { language }).value;
42
+ code = `<code class="hljs language-${escape(language)}">${code}</code>`;
42
43
  }
43
44
 
44
- const language = lang && hljs.getLanguage(lang) ? lang : "plaintext";
45
- const highlightedCode = hljs.highlight(code, { language }).value;
46
-
47
- const result =
48
- `<pre style="position: relative;">` +
49
- `<code class="hljs language-${escape(language)}">${highlightedCode}</code>` +
50
- `</pre>`;
51
-
52
- return injectHtmlAttributes(result, [], sourceMap);
45
+ const result = `<pre style="position: relative;">` + code + `</pre>`;
46
+ return injectHtmlAttributes(result, attrs, sourceMap);
53
47
  }
54
48
 
55
49
  alert(body: string, token: Tokens["Alert"]): string {