Skip to content

Commit

Permalink
Merge pull request #645 from pjkaufman/master
Browse files Browse the repository at this point in the history
Make Sure Inline Code Is not Affected by Footnote Rules
  • Loading branch information
pjkaufman authored Mar 10, 2023
2 parents c78de65 + 7fc17df commit cea8f6b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions __tests__/re-index-footnotes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ReIndexFootnotes from '../src/rules/re-index-footnotes';
import dedent from 'ts-dedent';
import {ruleTest} from './common';

ruleTest({
RuleBuilderClass: ReIndexFootnotes,
testCases: [
{ // accounts for https://github.com/platers/obsidian-linter/issues/641
testName: 'Inline code should not be affected by re-indexing footnotes',
before: dedent`
\`h[^ae]llo\`
`,
after: dedent`
\`h[^ae]llo\`
`,
},
],
});

2 changes: 1 addition & 1 deletion src/rules/footnote-after-punctuation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class FootnoteAfterPunctuation extends RuleBuilder<FootnoteAfterP
return FootnoteAfterPunctuationOptions;
}
apply(text: string, options: FootnoteAfterPunctuationOptions): string {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.footnoteAtStartOfLine, IgnoreTypes.footnoteAfterATask], text, (text) => {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.footnoteAtStartOfLine, IgnoreTypes.footnoteAfterATask], text, (text) => {
return text.replace(/(\[\^\w+\]) ?([,.;!:?])/gm, '$2$1');
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/move-footnotes-to-the-bottom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class MoveFootnotesToTheBottom extends RuleBuilder<MoveFootnotesT
return MoveFootnotesToTheBottomOptions;
}
apply(text: string, options: MoveFootnotesToTheBottomOptions): string {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml], text, (text) => {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml], text, (text) => {
return moveFootnotesToEnd(text);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/re-index-footnotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ReIndexFootnotes extends RuleBuilder<ReIndexFootnotesOption
return ReIndexFootnotesOptions;
}
apply(text: string, options: ReIndexFootnotesOptions): string {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
// re-index footnote-text
let ft_index = 0;
text = text.replace(/^\[\^\w+\]: /gm, function() {
Expand Down

0 comments on commit cea8f6b

Please sign in to comment.