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: Add Ability for User to Select from Multiple Different Line Break Indicators #1058

Merged
merged 5 commits into from
Apr 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/paragraph-blank-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ ruleTest({
paragraph line 1 <br>
paragraph line 2 ${''}
paragraph line 3 <br/>
paragraph line 4 \\
paragraph final line
${''}
${''}
Expand All @@ -174,6 +175,7 @@ ruleTest({
paragraph line 1 <br>
paragraph line 2 ${''}
paragraph line 3 <br/>
paragraph line 4 \\
paragraph final line
${''}
`,
Expand Down
81 changes: 81 additions & 0 deletions __tests__/two-spaces-between-lines-with-content.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TwoSpacesBetweenLinesWithContent from '../src/rules/two-spaces-between-lines-with-content';
import dedent from 'ts-dedent';
import {ruleTest} from './common';
import {LineBreakIndicators} from '../src/utils/mdast';

ruleTest({
RuleBuilderClass: TwoSpacesBetweenLinesWithContent,
Expand Down Expand Up @@ -86,5 +87,85 @@ ruleTest({
%%
`,
},
{
testName: 'Make sure that using a line break indicator of `<br>` replaces the other line break endings properly',
before: dedent`
Here is some text${' '}
Here is some more text\\
Here is yet some more text<br>
Even more text<br/>
Once more...
`,
after: dedent`
Here is some text<br>
Here is some more text<br>
Here is yet some more text<br>
Even more text<br>
Once more...
`,
options: {
lineBreakIndicator: LineBreakIndicators.LineBreakHtmlNotXml,
},
},
{
testName: 'Make sure that using a line break indicator of `<br/>` replaces the other line break endings properly',
before: dedent`
Here is some text${' '}
Here is some more text\\
Here is yet some more text<br>
Even more text<br/>
Once more...
`,
after: dedent`
Here is some text<br/>
Here is some more text<br/>
Here is yet some more text<br/>
Even more text<br/>
Once more...
`,
options: {
lineBreakIndicator: LineBreakIndicators.LineBreakHtml,
},
},
{
testName: 'Make sure that using a line break indicator of `\\` replaces the other line break endings properly',
before: dedent`
Here is some text${' '}
Here is some more text\\
Here is yet some more text<br>
Even more text<br/>
Once more...
`,
after: dedent`
Here is some text\\
Here is some more text\\
Here is yet some more text\\
Even more text\\
Once more...
`,
options: {
lineBreakIndicator: LineBreakIndicators.Backslash,
},
},
{
testName: 'Make sure that using a line break indicator of ` ` replaces the other line break endings properly',
before: dedent`
Here is some text${' '}
Here is some more text\\
Here is yet some more text<br>
Even more text<br/>
Once more...
`,
after: dedent`
Here is some text${' '}
Here is some more text${' '}
Here is yet some more text${' '}
Even more text${' '}
Once more...
`,
options: {
lineBreakIndicator: LineBreakIndicators.TwoSpaces,
},
},
],
});
2 changes: 1 addition & 1 deletion docs/additional-info/rules/paragraph-blank-lines.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

#### When Is a Blank Line Added?

When a paragraph has another line after the current one and it does not end in 2 or more spaces or `<br>` or `<br/>`.
When a paragraph has another line after the current one and it does not end in 2 or more spaces, `<br>`, `<br/>`, or `\`.
5 changes: 5 additions & 0 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,5 +785,10 @@ export default {
'‘’': '‘’', // leave as is
'""': '""', // leave as is
'“”': '“”', // leave as is
// yaml.ts
'\\': '\\', // leave as is
'<br>': '<br>', // leave as is
' ': ' ', // leave as is
'<br/>': '<br/>', // leave as is
},
};
13 changes: 11 additions & 2 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,12 @@ export default {
},
// two-spaces-between-lines-with-content.ts
'two-spaces-between-lines-with-content': {
'name': 'Two Spaces Between Lines with Content',
'description': 'Makes sure that two spaces are added to the ends of lines with content continued on the next line for paragraphs, blockquotes, and list items',
'name': 'Line Break Between Lines with Content',
'description': 'Makes sure that the specified line break is added to the ends of lines with content continued on the next line for paragraphs, blockquotes, and list items',
'line-break-indicator': {
'name': 'Line Break Indicator',
'description': 'The line break indicator to use.',
},
},
// unordered-list-style.ts
'unordered-list-style': {
Expand Down Expand Up @@ -857,5 +861,10 @@ export default {
'‘’': '‘’', // leave as is
'""': '""', // leave as is
'“”': '“”', // leave as is
// yaml.ts
'\\': '\\', // leave as is
'<br>': '<br>', // leave as is
' ': ' ', // leave as is
'<br/>': '<br/>', // leave as is
},
};
11 changes: 10 additions & 1 deletion src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,11 @@ export default {
},
'two-spaces-between-lines-with-content': {
'name': 'Dos espacios entre líneas con contenido',
'description': 'Se asegura de que se agreguen dos espacios al final de las líneas con contenido que continúa en la siguiente línea para párrafos, comillas y elementos de lista',
'description': 'Se asegura de que el salto de línea especificado se agregue al final de las líneas y el contenido continúe en la línea siguiente para párrafos, citas en bloque y elementos de lista.',
'line-break-indicator': {
'name': 'Indicador de salto de línea',
'description': 'El indicador de salto de línea a utilizar.',
},
},
'unordered-list-style': {
'name': 'Estilo de lista desordenada',
Expand Down Expand Up @@ -694,5 +698,10 @@ export default {
'‘’': '‘’', // leave as is
'""': '""', // leave as is
'“”': '“”', // leave as is
// yaml.ts
'\\': '\\', // leave as is
'<br>': '<br>', // leave as is
' ': ' ', // leave as is
'<br/>': '<br/>', // leave as is
},
};
5 changes: 5 additions & 0 deletions src/lang/locale/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,5 +781,10 @@ export default {
'‘’': '‘’', // leave as is
'""': '""', // leave as is
'“”': '“”', // leave as is
// yaml.ts
'\\': '\\', // leave as is
'<br>': '<br>', // leave as is
' ': ' ', // leave as is
'<br/>': '<br/>', // leave as is
},
};
5 changes: 5 additions & 0 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,5 +789,10 @@ export default {
'‘’': '‘’', // leave as is
'""': '""', // leave as is
'“”': '“”', // leave as is
// yaml.ts
'\\': '\\', // leave as is
'<br>': '<br>', // leave as is
' ': ' ', // leave as is
'<br/>': '<br/>', // leave as is
},
};
4 changes: 3 additions & 1 deletion src/rules/paragraph-blank-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export default class ParagraphBlankLines extends RuleBuilder<ParagraphBlankLines
`,
}),
new ExampleBuilder({
description: 'Paragraphs can be extended via the use of 2 or more spaces at the end of a line or line break html',
description: 'Paragraphs can be extended via the use of 2 or more spaces at the end of a line, a line break html or xml, or a backslash (\\)',
before: dedent`
# H1
Content${' '}
Paragraph content continued <br>
Paragraph content continued once more <br/>
Paragraph content yet again\\
Last line of paragraph
A new paragraph
# H2
Expand All @@ -56,6 +57,7 @@ export default class ParagraphBlankLines extends RuleBuilder<ParagraphBlankLines
Content${' '}
Paragraph content continued <br>
Paragraph content continued once more <br/>
Paragraph content yet again\\
Last line of paragraph
${''}
A new paragraph
Expand Down
50 changes: 40 additions & 10 deletions src/rules/two-spaces-between-lines-with-content.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {Options, RuleType} from '../rules';
import RuleBuilder, {ExampleBuilder, OptionBuilderBase} from './rule-builder';
import RuleBuilder, {DropdownOptionBuilder, ExampleBuilder, OptionBuilderBase} from './rule-builder';
import dedent from 'ts-dedent';
import {IgnoreTypes} from '../utils/ignore-types';
import {addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent} from '../utils/mdast';
import {LineBreakIndicators, addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent} from '../utils/mdast';

class TwoSpacesBetweenLinesWithContentOptions implements Options {}
class TwoSpacesBetweenLinesWithContentOptions implements Options {
lineBreakIndicator?: LineBreakIndicators = LineBreakIndicators.TwoSpaces;
}

@RuleBuilder.register
export default class TwoSpacesBetweenLinesWithContent extends RuleBuilder<TwoSpacesBetweenLinesWithContentOptions> {
Expand All @@ -20,12 +22,12 @@ export default class TwoSpacesBetweenLinesWithContent extends RuleBuilder<TwoSpa
return TwoSpacesBetweenLinesWithContentOptions;
}
apply(text: string, options: TwoSpacesBetweenLinesWithContentOptions): string {
return addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent(text);
return addTwoSpacesAtEndOfLinesFollowedByAnotherLineOfTextContent(text, options.lineBreakIndicator);
}
get exampleBuilders(): ExampleBuilder<TwoSpacesBetweenLinesWithContentOptions>[] {
return [
new ExampleBuilder({
description: 'Make sure two spaces are added to the ends of lines that have content on it and the next line for lists, blockquotes, and paragraphs',
description: 'Make sure two spaces are added to the ends of lines that have content on it and the next line for lists, blockquotes, and paragraphs when the line break indicator is ` `',
before: dedent`
# Heading 1
First paragraph stays as the first paragraph
Expand All @@ -46,7 +48,7 @@ export default class TwoSpacesBetweenLinesWithContent extends RuleBuilder<TwoSpa
${''}
Paragraph lines that end in <br/>
Or lines that end in <br>
Are left alone
Are left swapped
Since they mean the same thing
${''}
\`\`\` text
Expand Down Expand Up @@ -84,9 +86,9 @@ export default class TwoSpacesBetweenLinesWithContent extends RuleBuilder<TwoSpa
Continuation *of* the paragraph has \`inline code block\` __in it__. ${''}
Even more continuation
${''}
Paragraph lines that end in <br/>
Or lines that end in <br>
Are left alone ${''}
Paragraph lines that end in ${''}
Or lines that end in ${''}
Are left swapped ${''}
Since they mean the same thing
${''}
\`\`\` text
Expand All @@ -106,10 +108,38 @@ export default class TwoSpacesBetweenLinesWithContent extends RuleBuilder<TwoSpa
Even more content here
${''}
`,
options: {
lineBreakIndicator: LineBreakIndicators.TwoSpaces,
},
}),
];
}
get optionBuilders(): OptionBuilderBase<TwoSpacesBetweenLinesWithContentOptions>[] {
return [];
return [
new DropdownOptionBuilder<TwoSpacesBetweenLinesWithContentOptions, LineBreakIndicators>({
OptionsClass: TwoSpacesBetweenLinesWithContentOptions,
nameKey: 'rules.two-spaces-between-lines-with-content.line-break-indicator.name',
descriptionKey: 'rules.two-spaces-between-lines-with-content.line-break-indicator.description',
optionsKey: 'lineBreakIndicator',
records: [
{
value: LineBreakIndicators.TwoSpaces,
description: LineBreakIndicators.TwoSpaces,
},
{
value: LineBreakIndicators.LineBreakHtml,
description: LineBreakIndicators.LineBreakHtml,
},
{
value: LineBreakIndicators.LineBreakHtmlNotXml,
description: LineBreakIndicators.LineBreakHtmlNotXml,
},
{
value: LineBreakIndicators.Backslash,
description: LineBreakIndicators.Backslash,
},
],
}),
];
}
}