diff --git a/README.md b/README.md index 08d34826..19bbf59a 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Each rule is its own set of logic and is designed to be run independently. This ### YAML rules - [add-blank-line-after-yaml](https://platers.github.io/obsidian-linter/settings/yaml-rules/#add-blank-line-after-yaml) +- [dedupe-yaml-array-values](https://platers.github.io/obsidian-linter/settings/yaml-rules/#dedupe-yaml-array-values) - [escape-yaml-special-characters](https://platers.github.io/obsidian-linter/settings/yaml-rules/#escape-yaml-special-characters) - [force-yaml-escape](https://platers.github.io/obsidian-linter/settings/yaml-rules/#force-yaml-escape) - [format-tags-in-yaml](https://platers.github.io/obsidian-linter/settings/yaml-rules/#format-tags-in-yaml) @@ -27,6 +28,7 @@ Each rule is its own set of logic and is designed to be run independently. This - [insert-yaml-attributes](https://platers.github.io/obsidian-linter/settings/yaml-rules/#insert-yaml-attributes) - [move-tags-to-yaml](https://platers.github.io/obsidian-linter/settings/yaml-rules/#move-tags-to-yaml) - [remove-yaml-keys](https://platers.github.io/obsidian-linter/settings/yaml-rules/#remove-yaml-keys) +- [sort-yaml-array-values](https://platers.github.io/obsidian-linter/settings/yaml-rules/#sort-yaml-array-values) - [yaml-key-sort](https://platers.github.io/obsidian-linter/settings/yaml-rules/#yaml-key-sort) - [yaml-timestamp](https://platers.github.io/obsidian-linter/settings/yaml-rules/#yaml-timestamp) - [yaml-title](https://platers.github.io/obsidian-linter/settings/yaml-rules/#yaml-title) diff --git a/docs/docs/settings/yaml-rules.md b/docs/docs/settings/yaml-rules.md index cbf5f8e9..b7216f20 100644 --- a/docs/docs/settings/yaml-rules.md +++ b/docs/docs/settings/yaml-rules.md @@ -85,6 +85,153 @@ Here is some text `````` +## Dedupe YAML Array Values + +Alias: `dedupe-yaml-array-values` + +Removes duplicate array values in a case sensitive manner. + +### Options + +| Name | Description | List Items | Default Value | +| ---- | ----------- | ---------- | ------------- | +| `Dedupe YAML aliases section` | Turns on removing duplicate aliases. | N/A | `true` | +| `Dedupe YAML tags section` | Turns on removing duplicate tags. | N/A | `true` | +| `Dedupe YAML array sections` | Turns on removing duplicate values for regular YAML arrays | N/A | `true` | +| `YAML Keys to Ignore` | A list of YAML keys without the ending colon on their own lines that are not meant to have duplicate values removed from them. | N/A | | + + + +### Examples + +
Dedupe YAML tags is case sensitive and will use your default format for tags. + +Before: + +`````` markdown +--- +tags: [computer, research, computer, Computer] +aliases: + - Title 1 + - Title2 +--- +`````` + +After: + +`````` markdown +--- +tags: [computer, research, Computer] +aliases: + - Title 1 + - Title2 +--- +`````` +
+
Dedupe YAML aliases is case sensitive and will use your default format for aliases. + +Before: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 + - Title 1 + - Title2 + - Title 3 +--- +`````` + +After: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 + - Title 3 +--- +`````` +
+
Dedupe YAML array keys is case sensitive and will try to preserve the original array format. + +Before: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 +arr1: [val, val1, val, val2, Val] +arr2: + - Val + - Val + - val + - val2 + - Val2 +--- +`````` + +After: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 +arr1: [val, val1, val2, Val] +arr2: + - Val + - val + - val2 + - Val2 +--- +`````` +
+
Dedupe YAML respects list of keys to not remove duplicates of for normal arrays (keys to ignore is just `arr2` for this example) + +Before: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 +arr1: [val, val1, val, val2, Val] +arr2: + - Val + - Val + - val + - val2 + - Val2 +--- +`````` + +After: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title2 +arr1: [val, val1, val2, Val] +arr2: + - Val + - Val + - val + - val2 + - Val2 +--- +`````` +
+ ## Escape YAML Special Characters Alias: `escape-yaml-special-characters` @@ -685,6 +832,109 @@ Text `````` +## Sort YAML Array Values + +Alias: `sort-yaml-array-values` + +Sorts YAML array values based on the specified sort order. + +### Options + +| Name | Description | List Items | Default Value | +| ---- | ----------- | ---------- | ------------- | +| `Sort YAML aliases section` | Turns on sorting aliases. | N/A | `true` | +| `Sort YAML tags section` | Turns on sorting tags. | N/A | `true` | +| `Sort YAML array sections` | Turns on sorting values for regular YAML arrays | N/A | `true` | +| `YAML Keys to Ignore` | A list of YAML keys without the ending colon on their own lines that are not meant to have their values sorted. | N/A | | +| `Sort Order` | The way to sort the YAML array values. | `Ascending Alphabetical`: Sorts the array values from a to z

`Descending Alphabetical`: Sorts the array values from z to a | `Ascending Alphabetical` | + + + +### Examples + +
Sorting YAML array values alphabetically + +Before: + +`````` markdown +--- +tags: [computer, research, androids, Computer] +aliases: + - Title 1 + - Title 2 +--- +`````` + +After: + +`````` markdown +--- +tags: [androids, computer, Computer, research] +aliases: + - Title 1 + - Title 2 +--- +`````` +
+
Sorting YAML array values to be alphabetically descending + +Before: + +`````` markdown +--- +tags: [computer, research, androids, Computer] +aliases: + - Title 1 + - Title 2 +--- +`````` + +After: + +`````` markdown +--- +tags: [research, Computer, computer, androids] +aliases: + - Title 2 + - Title 1 +--- +`````` +
+
Sort YAML Arrays respects list of keys to not sort values of for normal arrays (keys to ignore is just `arr2` for this example) + +Before: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title 2 +arr1: [val, val2, val1] +arr2: + - val + - val2 + - val1 +--- +`````` + +After: + +`````` markdown +--- +tags: [computer, research] +aliases: + - Title 1 + - Title 2 +arr1: [val, val1, val2] +arr2: + - val + - val2 + - val1 +--- +`````` +
+ ## YAML Key Sort Alias: `yaml-key-sort` diff --git a/manifest.json b/manifest.json index f3e7fad2..a505f8a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-linter", "name": "Linter", - "version": "1.22.0", + "version": "1.23.0", "minAppVersion": "1.4.16", "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", diff --git a/package.json b/package.json index 864f23b2..b8bdf171 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-linter", - "version": "1.22.0", + "version": "1.23.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": { diff --git a/versions.json b/versions.json index 48fcdb59..332e57f3 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "1.23.0": "1.4.16", "1.22.0": "1.4.16", "1.21.0": "1.4.16", "1.20.1": "1.4.16",