Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support hard line breaks #100

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});