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

Fix Table Matching Logic and Add Paragraph Blank Lines Example #706

Merged
merged 3 commits into from
May 5, 2023
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
12 changes: 12 additions & 0 deletions __tests__/get-all-tables-in-text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ const getTablesInTextTestCases: tablesInTextTestCase[] = [
expectedTablesInText: 0,
expectedPositions: [],
},
{
name: 'does not match an empty list indicator with a blank line before it',
text: dedent`
## Attendees
${''}
-${' '}
${''}
## Agenda
`,
expectedTablesInText: 0,
expectedPositions: [],
},
];

describe('Get All Tables in Text', () => {
Expand Down
25 changes: 21 additions & 4 deletions __tests__/paragraph-blank-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ ruleTest({
testName: 'Table followed by header should only have 1 line after it',
before: dedent`
### 常量

${''}
| \`[[Link]]\` | A link to the file named "Link" |
|:--------------------|:----------------------------------|
| \`[[Link]]\` | A link to the file named "Link" |
Expand All @@ -293,12 +293,12 @@ ruleTest({
| \`{ a: 1, b: 2 }\` | An object |
| \`date()\` | |
| \`dur()\` | |

${''}
### 表达式
`,
after: dedent`
### 常量

${''}
| \`[[Link]]\` | A link to the file named "Link" |
|:--------------------|:----------------------------------|
| \`[[Link]]\` | A link to the file named "Link" |
Expand All @@ -307,9 +307,26 @@ ruleTest({
| \`{ a: 1, b: 2 }\` | An object |
| \`date()\` | |
| \`dur()\` | |

${''}
### 表达式
`,
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/704
testName: 'Make sure that an empty list indicator does not have an extra empty line added around it',
before: dedent`
## Attendees
${''}
-${' '}
${''}
## Agenda
`,
after: dedent`
## Attendees
${''}
-${' '}
${''}
## Agenda
`,
},
],
});
24 changes: 24 additions & 0 deletions src/rules/paragraph-blank-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ export default class ParagraphBlankLines extends RuleBuilder<ParagraphBlankLines
A paragraph is a line that starts with a letter.
`,
}),
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',
before: dedent`
# H1
Content${' '}
Paragraph content continued <br>
Paragraph content continued once more <br/>
Last line of paragraph
A new paragraph
# H2
`,
after: dedent`
# H1
${''}
Content${' '}
Paragraph content continued <br>
Paragraph content continued once more <br/>
Last line of paragraph
${''}
A new paragraph
${''}
# H2
`,
}),
];
}
get optionBuilders(): OptionBuilderBase<ParagraphBlankLinesOptions>[] {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,8 @@ export function getAllTablesInText(text: string): {startIndex: number, endIndex:

let start = startOfPreviousLine;
let firstLine = text.substring(startOfPreviousLine, startOfCurrentLine - 1);
// if the separator row matches a yaml block indicator and the first line is missing
// a pipe, then we must assume that we are dealing with a header or yaml instead of a table
if (separatorRowMatch === '---' && !firstLine.includes('|')) {
// a table must have a pipe in either the header or the separator row
if (!separatorRowMatch.includes('|') && !firstLine.includes('|')) {
continue;
}

Expand Down