Skip to content

Commit

Permalink
feat: Renamed line breaks option
Browse files Browse the repository at this point in the history
  • Loading branch information
akabekobeko committed Jan 19, 2021
1 parent 417e944 commit 494185a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cli = meow(
--partial, -p Output markdown fragments
--title Document title (ignored in partial mode)
--language Document language (ignored in partial mode)
--auto-line-breaks Converts line breaks to <br>
--hard-line-breaks Add <br> at the position of hard line breaks, without needing spaces
Examples
$ vfm input.md
Expand All @@ -38,7 +38,7 @@ const cli = meow(
language: {
type: 'string',
},
autoLineBreaks: {
hardLineBreaks: {
type: 'boolean',
},
},
Expand All @@ -53,7 +53,7 @@ function compile(input: string) {
style: cli.flags.style,
title: cli.flags.title,
language: cli.flags.language,
autoLineBreaks: cli.flags.autoLineBreaks,
hardLineBreaks: cli.flags.hardLineBreaks,
}),
);
}
Expand All @@ -64,7 +64,7 @@ function main(
partial: { type: 'boolean'; alias: string };
title: { type: 'string' };
language: { type: 'string' };
autoLineBreaks: { type: 'boolean' };
hardLineBreaks: { type: 'boolean' };
}>,
) {
try {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface StringifyMarkdownOptions {
language?: string;
/** Replacement handler for HTML string. */
replace?: ReplaceRule[];
/** Converts line breaks to `<br>`. */
autoLineBreaks?: boolean;
/** Add `<br>` at the position of hard line breaks, without needing spaces. */
hardLineBreaks?: boolean;
}

export interface Hooks {
Expand All @@ -40,10 +40,10 @@ export function VFM({
title = undefined,
language = undefined,
replace = undefined,
autoLineBreaks = false,
hardLineBreaks = false,
}: StringifyMarkdownOptions = {}): Processor {
const processor = unified()
.use(markdown({ autoLineBreaks }))
.use(markdown({ hardLineBreaks }))
.data('settings', { position: false })
.use(html);

Expand Down
6 changes: 3 additions & 3 deletions src/revive-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { inspect } from './utils/debug';
* Options for Markdown conversion.
*/
export interface MarkdownOptions {
/** Converts line breaks to `<br>`. */
autoLineBreaks: boolean;
/** Add `<br>` at the position of hard line breaks, without needing spaces. */
hardLineBreaks: boolean;
}

/**
Expand All @@ -33,7 +33,7 @@ export const reviveParse = (
[markdown, { gfm: true, commonmark: true }],
fencedBlock,
ruby,
...(options.autoLineBreaks ? [breaks] : []),
...(options.hardLineBreaks ? [breaks] : []),
[footnotes, { inlineNotes: true }],
math,
attr,
Expand Down
6 changes: 3 additions & 3 deletions tests/block/line-breaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stripIndent } from 'common-tags';
import { buildProcessorTestingCode } from '../utils';

// remark-parse GFM seems to support only EOL space, so backslash is excluded.
// remark-parse GFM seems to support only EOL two-spaces, so backslash is excluded.
it(
'default: GFM (EOL two-spaces)',
buildProcessorTestingCode(
Expand All @@ -26,7 +26,7 @@ it(
);

it(
'optional: auto line breaks with GFM (EOL tow-spaces)',
'optional: hard line breaks with GFM (EOL tow-spaces)',
buildProcessorTestingCode(
stripIndent`
a
Expand All @@ -47,6 +47,6 @@ it(
b<br>
c</p>
`,
{ autoLineBreaks: true },
{ hardLineBreaks: true },
),
);
6 changes: 3 additions & 3 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ReplaceRule } from '../src/plugins/replace';
/**
* Run VFM stringify in partial mode.
* @param body Markdown string that becomes `<body>` part.
* @param autoLineBreaks Converts line breaks to `<br>`.
* @param hardLineBreaks Add `<br>` at the position of hard line breaks, without needing spaces.
* @returns HTML string.
*/
function partial(body: string, autoLineBreaks = false) {
return lib.stringify(body, { partial: true, autoLineBreaks });
function partial(body: string, hardLineBreaks = false) {
return lib.stringify(body, { partial: true, hardLineBreaks });
}

// Snippet
Expand Down
2 changes: 1 addition & 1 deletion tests/inline/ruby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ it(
└─2 text "b|c}"
`,
`<p>{a<br>\nb|c}</p>`,
{ autoLineBreaks: true },
{ hardLineBreaks: true },
),
);
4 changes: 2 additions & 2 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const buildProcessorTestingCode = (
title = undefined,
language = undefined,
replace = undefined,
autoLineBreaks = false,
hardLineBreaks = false,
}: StringifyMarkdownOptions = {},
) => (): any => {
const vfm = VFM({
Expand All @@ -27,7 +27,7 @@ export const buildProcessorTestingCode = (
title,
language,
replace,
autoLineBreaks,
hardLineBreaks,
}).freeze();
expect(unistInspect.noColor(vfm.parse(input))).toBe(expectedMdast.trim());
expect(String(vfm.processSync(input))).toBe(expectedHtml);
Expand Down

0 comments on commit 494185a

Please sign in to comment.