Skip to content

Commit

Permalink
try not encodeing < and >=
Browse files Browse the repository at this point in the history
  • Loading branch information
lcflight committed Oct 18, 2024
1 parent 30ec247 commit 0121d39
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/lib/marked/extentions/smartypants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import smartypants from "./smartypants.js";
marked.use(smartypants);

describe("marked ids extension", () => {
it("handles encoding arrows", () => {
it("handles arrows", () => {
const r = marked.parse("-> `a`");

expect(r).toContain("<p>-&gt; <code>a</code></p>");
expect(r).toContain("<p>-> <code>a</code></p>");
});

it("does not encode html comments", () => {
const r = marked.parse(`a\n <!--\nb\n\nc\n-->`);

expect(r).not.toContain("&lt;!&#8212;");
});
});
5 changes: 2 additions & 3 deletions src/lib/marked/extentions/smartypants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { smartypants } from "smartypants";
const extension: MarkedExtension = {
tokenizer: {
inlineText(src: string): false | Tokens.Text | undefined {
// don't escape inlineText, unless it's < and >
// don't escape inlineText
const cap = this.rules.inline.text.exec(src);
const raw = cap?.[0] ?? "";
const text = raw.replace("<", "&lt;").replace(">", "&gt;");

return {
type: "text",
raw,
text,
text: raw,
};
},
},
Expand Down
8 changes: 8 additions & 0 deletions src/lib/marked/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ describe("marked ids extension", () => {

expect(r).toContain('&lt;a id="foo1" href="#foo"&gt;[N]&lt;/a&gt;');
});

it("does not encode html comments", () => {
const r = parse(`a\n <!--\nb\n\nc\n-->`);

console.log(r);

expect(r).not.toContain("&lt;!&#8212;");
});
});

0 comments on commit 0121d39

Please sign in to comment.