Skip to content

Commit

Permalink
Merge pull request #536 from pjkaufman/master
Browse files Browse the repository at this point in the history
Update Versions for Release and Add Ability to Ignore Cased Words for First Letter Capitalization
  • Loading branch information
pjkaufman authored Dec 6, 2022
2 parents 823dde8 + dd15dc1 commit 9d445c4
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Each rule is its own set of logic and is designed to be run independently. This
- [capitalize-headings](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md#capitalize-headings)
- [file-name-heading](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md#file-name-heading)
- [header-increment](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md#header-increment)
- [headings-start-line](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md#headings-start-line)
- [remove-trailing-punctuation-in-heading](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md#remove-trailing-punctuation-in-heading)

### Footnote rules

Expand Down
6 changes: 4 additions & 2 deletions __tests__/capitalize-headings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ruleTest({
`,
options: {
style: 'First letter',
ignoreCasedWords: false,
},
},
{
Expand Down Expand Up @@ -135,15 +136,16 @@ ruleTest({
`,
options: {
style: 'First letter',
ignoreCasedWords: false,
},
},
{
testName: `Make sure that 'First Letter' doesn't ignore cased words just because they are cased when ignore cased words is enabled`,
testName: `Make sure that 'First Letter' ignores cased words just because they are cased when ignore cased words is enabled`,
before: dedent`
### This Header is Cased
`,
after: dedent`
### This header is cased
### This Header is Cased
`,
options: {
style: 'First letter',
Expand Down
99 changes: 98 additions & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ Options:
- Ignore Cased Words: Only apply title case style to words that are all lowercase
- Default: `true`
- Ignore Words: A comma separated list of words to ignore when capitalizing
- Default: `macOS, iOS, iPhone, iPad, JavaScript, TypeScript, AppleScript`
- Default: `macOS, iOS, iPhone, iPad, JavaScript, TypeScript, AppleScript, I`
- Lowercase Words: A comma separated list of words to keep lowercase
- Default: `via, a, an, the, and, or, but, for, nor, so, yet, at, by, in, of, on, to, up, as, is, if, it, for, to, with, without, into, onto, per`

Expand Down Expand Up @@ -1186,6 +1186,86 @@ This resets the decrement section so the H6 below is decremented to an H3
### H6
``````

### Headings Start Line

Alias: `headings-start-line`

Headings that do not start a line will have their preceding whitespace removed to make sure they get recognized as headers.



Example: Removes spaces prior to a heading

Before:

``````markdown
## Other heading preceded by 2 spaces ##
_Note that if the spacing is enough for the header to be considered to be part of a codeblock it will not be affected by this rule._
``````

After:

``````markdown
## Other heading preceded by 2 spaces ##
_Note that if the spacing is enough for the header to be considered to be part of a codeblock it will not be affected by this rule._
``````
Example: Tags are not affected by this

Before:

``````markdown
#test
# Heading &
``````

After:

``````markdown
#test
# Heading &
``````

### Remove Trailing Punctuation in Heading

Alias: `remove-trailing-punctuation-in-heading`

Removes the specified punctuation from the end of headings making sure to ignore the semicolon at the end of [HTML entity references](https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references).

Options:
- Trailing Punctuation: The trailing punctuation to remove from the headings in the file.
- Default: `.,;:!。,;:!`

Example: Removes punctuation from the end of a heading

Before:

``````markdown
# Heading ends in a period.
## Other heading ends in an exclamation mark! ##
``````

After:

``````markdown
# Heading ends in a period
## Other heading ends in an exclamation mark ##
``````
Example: HTML Entities at the end of a heading is ignored

Before:

``````markdown
# Heading 1
## Heading &
``````

After:

``````markdown
# Heading 1
## Heading &
``````

## Footnote
### Footnote after Punctuation

Expand All @@ -1208,6 +1288,23 @@ After:
``````markdown
Lorem.[^1] Ipsum,[^2] doletes.
``````
Example: A footnote at the start of a task is not moved to after the punctuation

Before:

``````markdown
- [ ] [^1]: This is a footnote and a task.
- [ ] This is a footnote and a task that gets swapped with the punctuation[^2]!
[^2]: This footnote got modified
``````

After:

``````markdown
- [ ] [^1]: This is a footnote and a task.
- [ ] This is a footnote and a task that gets swapped with the punctuation![^2]
[^2]: This footnote got modified
``````

### Move Footnotes to the bottom

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-linter",
"name": "Linter",
"version": "1.8.0",
"version": "1.9.0",
"minAppVersion": "0.15.6",
"description": "Formats and styles your notes. It can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular markdown contents like list, italics, and bold styles; and more with the use of custom rule options as well.",
"author": "Victor Tao",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-linter",
"version": "1.8.0",
"version": "1.9.0",
"description": "Enforces consistent markdown styling for Obsidian (https://obsidian.md). It can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular markdown contents like list, italics, and bold styles; and more with the use of custom rule options as well.",
"main": "main.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/rules/capitalize-headings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class CapitalizeHeadings extends RuleBuilder<CapitalizeHeadingsOp
continue;
}

const ignoreCasedWord = (options.ignoreCasedWords && !capitalizeJustFirstLetter) && headerWords[j] !== headerWords[j].toLowerCase();
const ignoreCasedWord = options.ignoreCasedWords && headerWords[j] !== headerWords[j].toLowerCase();
const keepWordCasing = ignoreCasedWord || keepCasing.includes(headerWords[j]);
if (!keepWordCasing) {
headerWords[j] = headerWords[j].toLowerCase();
Expand All @@ -97,6 +97,11 @@ export default class CapitalizeHeadings extends RuleBuilder<CapitalizeHeadingsOp
}

firstWord = false;

// if the user wants to keep casing and capitalize just the first letter then there is no need to lowercase any other word after the first word
if (options.ignoreCasedWords && capitalizeJustFirstLetter) {
break;
}
}

headerText = escapeDollarSigns(`${headerWords.join(' ')}`);
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.9.0": "0.15.6",
"1.8.0": "0.15.6",
"1.7.1": "0.15.6",
"1.7.0": "0.15.6",
Expand Down

0 comments on commit 9d445c4

Please sign in to comment.