Skip to content

Commit

Permalink
fix: support hard line breaks (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
deer authored Jan 29, 2024
1 parent 1c3f599 commit 3ac5949
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "deno test --allow-read --allow-env --allow-write --allow-run --allow-net"
},
"fmt": {
"exclude": ["./test/fixtures/alerts.md"]
"exclude": ["./test/fixtures/alerts.md", "./test/fixtures/lineBreaks.md"]
},
"lock": false
}
2 changes: 2 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface RenderOptions {
disableHtmlSanitization?: boolean;
renderer?: Renderer;
allowedClasses?: { [index: string]: boolean | Array<string | RegExp> };
breaks?: boolean;
}

export function render(markdown: string, opts: RenderOptions = {}): string {
Expand All @@ -126,6 +127,7 @@ export function render(markdown: string, opts: RenderOptions = {}): string {

const marked_opts = {
baseUrl: opts.baseUrl,
breaks: opts.breaks ?? false,
gfm: true,
mangle: false,
renderer: opts.renderer ? opts.renderer : new Renderer(opts),
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/lineBreaks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>From fairest creatures we desire increase,<br />That thereby beauty’s rose might never die,<br />But as the riper should by time decrease,<br />His tender heir mught bear his memeory:</p>
4 changes: 4 additions & 0 deletions test/fixtures/lineBreaks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
From fairest creatures we desire increase,
That thereby beauty’s rose might never die,
But as the riper should by time decrease,
His tender heir mught bear his memeory:
8 changes: 8 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,11 @@ Deno.test("footnotes", () => {
const html = render(markdown);
assertEquals(html, expected);
});

Deno.test("hard line breaks", () => {
const markdown = Deno.readTextFileSync("./test/fixtures/lineBreaks.md");
const expected = Deno.readTextFileSync("./test/fixtures/lineBreaks.html");

const html = render(markdown, { breaks: true });
assertEquals(html, expected);
});

0 comments on commit 3ac5949

Please sign in to comment.