Skip to content

Commit

Permalink
Fix smartypants integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoble committed Jul 15, 2024
1 parent fdb67c4 commit 556f9b8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"dependencies": {
"cheerio": "1.0.0-rc.12",
"marked": "^12.0.2",
"marked-smartypants": "^1.1.6",
"memize": "^2.1.0",
"sanitize-html": "^2.13.0"
"sanitize-html": "^2.13.0",
"smartypants": "^0.2.2"
}
}
16 changes: 3 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/lib/parseMarkdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,25 @@ describe("body", () => {
);

expect(r).toContain("<input type=\"checkbox\" checked />");

it("escapes special characters in tables", () => {
expect(
parseMarkdown(["| foo |", "| --- |", "| <PPR |"].join("\n"), {
strict: false,
}),
).toBe(
[
"<table>",
"<thead>",
"<tr>",
"<th>foo</th>",
"</tr>",
"</thead>",
"<tbody><tr>",
"<td>&lt;PPR</td>",
"</tr>",
"</tbody></table>\n",
].join("\n"),
);
});
});
14 changes: 8 additions & 6 deletions src/lib/parseMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import expandRefs from "./expandRefs.js";
import spaceEMDashes from "./spaceEMDashes.js";
import flattenParagraphs from "./flattenParagraphs.js";
import { marked, type Tokens } from "marked";
import { markedSmartypants } from "marked-smartypants";
import { smartypants } from "smartypants";
import applyIdsToElements from "./applyIdsToElements.js";
import sanitizeHtml from "sanitize-html";
import { SANITIZE_HTML_OPTIONS } from "./parseMarkdown.options.js";
Expand Down Expand Up @@ -37,11 +37,13 @@ const tokenizer = {

marked.use({ tokenizer });

marked.use(
markedSmartypants({
config: "1",
})
);
marked.use({
hooks: {
postprocess(html) {
return smartypants(html, "1");
},
},
});

marked.use({
hooks: {
Expand Down

0 comments on commit 556f9b8

Please sign in to comment.