Skip to content

Commit

Permalink
fix: Fixed by PR review
Browse files Browse the repository at this point in the history
1. Avoid `as` by explicitly specifying the return type of reviveParse
2. Independent test of line break handle
  • Loading branch information
akabekobeko committed Jan 18, 2021
1 parent 3a691f6 commit 417e944
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 36 deletions.
42 changes: 18 additions & 24 deletions src/revive-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,21 @@ export interface MarkdownOptions {
* @param options Options.
* @returns Parsers.
*/
export const reviveParse = (options: MarkdownOptions) => {
const results = [
[markdown, { gfm: true, commonmark: true }],
fencedBlock,
ruby,
[footnotes, { inlineNotes: true }],
math,
attr,
slug,
section,
code,
toc,
frontmatter,
metadata,
inspect('mdast'),
] as unified.PluggableList<unified.Settings>;

if (options.autoLineBreaks) {
// Line breaks are processed immediately after ruby
results.splice(3, 0, breaks);
}

return results;
};
export const reviveParse = (
options: MarkdownOptions,
): unified.PluggableList<unified.Settings> => [
[markdown, { gfm: true, commonmark: true }],
fencedBlock,
ruby,
...(options.autoLineBreaks ? [breaks] : []),
[footnotes, { inlineNotes: true }],
math,
attr,
slug,
section,
code,
toc,
frontmatter,
metadata,
inspect('mdast'),
];
52 changes: 52 additions & 0 deletions tests/block/line-breaks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { stripIndent } from 'common-tags';
import { buildProcessorTestingCode } from '../utils';

// remark-parse GFM seems to support only EOL space, so backslash is excluded.
it(
'default: GFM (EOL two-spaces)',
buildProcessorTestingCode(
stripIndent`
a
b
c
`,
stripIndent`
root[1]
└─0 paragraph[3]
├─0 text "a\\nb"
├─1 break
└─2 text "c"
`,
stripIndent`
<p>a
b<br>
c</p>
`,
),
);

it(
'optional: auto line breaks with GFM (EOL tow-spaces)',
buildProcessorTestingCode(
stripIndent`
a
b
c
`,
stripIndent`
root[1]
└─0 paragraph[5]
├─0 text "a"
├─1 break
├─2 text "b"
├─3 break
└─4 text "c"
`,
stripIndent`
<p>a<br>
b<br>
c</p>
`,
{ autoLineBreaks: true },
),
);
12 changes: 0 additions & 12 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ A
);
});

it('handle hard line break', () => {
expect(
partial(
`
a
b`,
true,
),
).toBe(`<p>a<br>
b</p>`);
});

it('stringify markdown string into html document', () => {
expect(lib.stringify('# こんにちは', { title: 'Custom' }))
.toBe(`<!doctype html>
Expand Down

0 comments on commit 417e944

Please sign in to comment.