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 +0 -6
- package/package.json +1 -1
- package/src/code-copy.ts +3 -0
- package/src/renderer.ts +9 -15
- package/src/tokenizer.ts +4 -3
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
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
|
-
|
|
35
|
+
const attrs: HTMLAttrs = [];
|
|
36
|
+
|
|
36
37
|
if (lang === "mermaid") {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
45
|
-
|
|
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 +
|
|
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
|
|
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) {
|