pantsdown 1.8.1 → 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/README.md CHANGED
@@ -137,9 +137,3 @@ console.log(html);
137
137
 
138
138
  Pantsdown is based on [Marked](https://github.com/markedjs/marked).
139
139
  Without their hard work, Pantsdown would not exist.
140
-
141
- ## 🚀 Roadmap
142
-
143
- - [ ] fix alerts css. see "alerts" in demo
144
- - [ ] check if copy code button works with current vite docs
145
- - [ ] [Mermaid](https://mermaid.js.org/) usage docs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantsdown",
3
- "version": "1.8.1",
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 {
package/src/tokenizer.ts CHANGED
@@ -725,7 +725,7 @@ export class Tokenizer {
725
725
  endReg.lastIndex = 0;
726
726
 
727
727
  // Clip maskedSrc to same section of string as src (move to lexer?)
728
- maskedSrc = maskedSrc.slice(-1 * src.length + match[0].length - 1);
728
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
729
729
 
730
730
  while ((match = endReg.exec(maskedSrc)) != null) {
731
731
  // eslint-disable-next-line
@@ -755,8 +755,9 @@ export class Tokenizer {
755
755
 
756
756
  // Remove extra characters. *a*** -> *a*
757
757
  rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
758
-
759
- const raw = [...src].slice(0, lLength + match.index + rLength + 1).join("");
758
+ // char length can be >1 for unicode characters;
759
+ const lastCharLength = [...match[0]]![0]!.length;
760
+ const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
760
761
 
761
762
  // Create `em` if smallest delimiter has odd char count. *a***
762
763
  if (Math.min(lLength, rLength) % 2) {