From 494185a606e13d26710d9dac1d153eb184686d7b Mon Sep 17 00:00:00 2001 From: akabeko Date: Wed, 20 Jan 2021 07:45:49 +0900 Subject: [PATCH] feat: Renamed line breaks option --- src/cli.ts | 8 ++++---- src/index.ts | 8 ++++---- src/revive-parse.ts | 6 +++--- tests/block/line-breaks.test.ts | 6 +++--- tests/index.test.ts | 6 +++--- tests/inline/ruby.test.ts | 2 +- tests/utils.ts | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index dc7c5c1..de9dae4 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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
+ --hard-line-breaks Add
at the position of hard line breaks, without needing spaces Examples $ vfm input.md @@ -38,7 +38,7 @@ const cli = meow( language: { type: 'string', }, - autoLineBreaks: { + hardLineBreaks: { type: 'boolean', }, }, @@ -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, }), ); } @@ -64,7 +64,7 @@ function main( partial: { type: 'boolean'; alias: string }; title: { type: 'string' }; language: { type: 'string' }; - autoLineBreaks: { type: 'boolean' }; + hardLineBreaks: { type: 'boolean' }; }>, ) { try { diff --git a/src/index.ts b/src/index.ts index ee31e39..f04549e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,8 +21,8 @@ export interface StringifyMarkdownOptions { language?: string; /** Replacement handler for HTML string. */ replace?: ReplaceRule[]; - /** Converts line breaks to `
`. */ - autoLineBreaks?: boolean; + /** Add `
` at the position of hard line breaks, without needing spaces. */ + hardLineBreaks?: boolean; } export interface Hooks { @@ -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); diff --git a/src/revive-parse.ts b/src/revive-parse.ts index debe565..b528c66 100644 --- a/src/revive-parse.ts +++ b/src/revive-parse.ts @@ -18,8 +18,8 @@ import { inspect } from './utils/debug'; * Options for Markdown conversion. */ export interface MarkdownOptions { - /** Converts line breaks to `
`. */ - autoLineBreaks: boolean; + /** Add `
` at the position of hard line breaks, without needing spaces. */ + hardLineBreaks: boolean; } /** @@ -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, diff --git a/tests/block/line-breaks.test.ts b/tests/block/line-breaks.test.ts index 5012acd..3c2c90b 100644 --- a/tests/block/line-breaks.test.ts +++ b/tests/block/line-breaks.test.ts @@ -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( @@ -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 @@ -47,6 +47,6 @@ it( b
c

`, - { autoLineBreaks: true }, + { hardLineBreaks: true }, ), ); diff --git a/tests/index.test.ts b/tests/index.test.ts index 4f419a6..d298e69 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -4,11 +4,11 @@ import { ReplaceRule } from '../src/plugins/replace'; /** * Run VFM stringify in partial mode. * @param body Markdown string that becomes `` part. - * @param autoLineBreaks Converts line breaks to `
`. + * @param hardLineBreaks Add `
` 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 diff --git a/tests/inline/ruby.test.ts b/tests/inline/ruby.test.ts index c56491d..591a34a 100644 --- a/tests/inline/ruby.test.ts +++ b/tests/inline/ruby.test.ts @@ -74,6 +74,6 @@ it( └─2 text "b|c}" `, `

{a
\nb|c}

`, - { autoLineBreaks: true }, + { hardLineBreaks: true }, ), ); diff --git a/tests/utils.ts b/tests/utils.ts index f1f86bb..f585d9c 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -18,7 +18,7 @@ export const buildProcessorTestingCode = ( title = undefined, language = undefined, replace = undefined, - autoLineBreaks = false, + hardLineBreaks = false, }: StringifyMarkdownOptions = {}, ) => (): any => { const vfm = VFM({ @@ -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);