pantsdown 2.2.0 → 2.2.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/renderer.ts +11 -5
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "pantsdown",
3
3
  "author": "wallpants",
4
4
  "type": "module",
5
- "version": "2.2.0",
5
+ "version": "2.2.1",
6
6
  "license": "MIT",
7
7
  "description": "Markdown to 'GitHub HTML' parser",
8
8
  "repository": {
package/src/renderer.ts CHANGED
@@ -26,18 +26,24 @@ export class Renderer {
26
26
 
27
27
  code(code: string, infostring: string | undefined, sourceMap: SourceMap): string {
28
28
  const lang = /^\S*/.exec(infostring ?? "")?.[0];
29
- code = code.replace(/\n$/, "") + "\n";
29
+ code = code.replace(/\n$/, "");
30
30
 
31
31
  const attrs: HTMLAttrs = [];
32
32
 
33
33
  if (lang === "mermaid") {
34
34
  attrs.push(["class", "mermaid-container mermaid"]);
35
- } else {
36
- const language = lang && hljs.getLanguage(lang) ? lang : "plaintext";
37
- code = hljs.highlight(code, { language }).value;
38
- code = `<code class="hljs language-${escape(language)}">${code}</code>`;
35
+ const result = `<pre style="position: relative;">` + code + "\n" + `</pre>`;
36
+ return injectHtmlAttributes(result, attrs, sourceMap);
39
37
  }
40
38
 
39
+ if (lang === "math") {
40
+ return this.latexBlock(code, sourceMap);
41
+ }
42
+
43
+ const language = lang && hljs.getLanguage(lang) ? lang : "plaintext";
44
+ code = hljs.highlight(code + "\n", { language }).value;
45
+ code = `<code class="hljs language-${escape(language)}">${code}</code>`;
46
+
41
47
  const result = `<pre style="position: relative;">` + code + `</pre>`;
42
48
  return injectHtmlAttributes(result, attrs, sourceMap);
43
49
  }