Closed redactedscribe closed 11 months ago
Hey @redactedscribe . Is this not currently possible by setting the YAML array format under general and then enabling the format YAML Arrays option? I was pretty sure that was how that worked, but I could be wrong.
@pjkaufman If I've understood you correctly, my settings are already set up that way.
I've got General > "YAML (aliases|tags) section style" both set to multi-line, and all toggles under "Format YAML Array" enabled, with "Default YAML array section style" set to multi-line too.
Without "Force key values to be multi-line arrays" populated with "authors" for example, the authors:
key remains as such on lint (no []
appended). Adding "authors" back to the list causes linting to add the brackets. When I check the properties, authors is set to type List.
Sorry @redactedscribe , I forgot where that setting is. The setting in the screenshot for the default normal YAML array needs to be set to multiline:
Do note that an empty multiline array is set to []
because properties would not accept an empty multiline item as anything except null in the display.
"Default YAML array section style" set to multi-line too.
@pjkaufman It is already set to multi-line. Maybe I have some conflicting option or maybe it's a bug?
Aha. What you say is working, but only for the known keys like aliases
and tags
, but I want all List type properties to be formatted as arrays using these same settings (minus anything set for "Force key values to be multi-line arrays" -- maybe there was some confusion, the original comment's FR may make more sense now).
Is the option to format regular arrays enabled? If you don't think so, could you provide your data.json
?
{
"ruleConfigs": {
"Remove Space around Fullwidth Characters": {
"Ensures that fullwidth characters are not followed by whitespace (either single spaces or a tab). Note that this may causes issues with markdown format in some cases.": false
},
"Space between Chinese and English or numbers": {
"Ensures that Chinese and English or numbers are separated by a single space. Follows these [guidelines](https://github.com/sparanoid/chinese-copywriting-guidelines)": false,
"Ensures that Chinese and English or numbers are separated by a single space. Follow this [guidelines](https://github.com/sparanoid/chinese-copywriting-guidelines)": false
},
"escape-yaml-special-characters": {
"enabled": false,
"try-to-escape-single-line-arrays": false
},
"format-tags-in-yaml": {
"enabled": true
},
"format-yaml-array": {
"enabled": true,
"alias-key": true,
"tag-key": true,
"default-array-style": "multi-line",
"default-array-keys": true,
"force-single-line-array-style": "",
"force-multi-line-array-style": "authors\ncssclasses"
},
"insert-yaml-attributes": {
"enabled": false,
"text-to-insert": "aliases: \ntags: "
},
"move-tags-to-yaml": {
"enabled": false,
"how-to-handle-existing-tags": "Nothing",
"tags-to-ignore": ""
},
"remove-yaml-keys": {
"enabled": false,
"yaml-keys-to-remove": ""
},
"yaml-key-sort": {
"enabled": true,
"yaml-key-priority-sort-order": "",
"priority-keys-at-start-of-yaml": true,
"yaml-sort-order-for-other-keys": "Ascending Alphabetical"
},
"yaml-timestamp": {
"enabled": false,
"date-created": true,
"date-created-key": "date created",
"force-retention-of-create-value": true,
"date-modified": true,
"date-modified-key": "date modified",
"format": "dddd, MMMM Do YYYY, h:mm:ss a"
},
"yaml-title": {
"enabled": false,
"title-key": "title",
"mode": "first-h1"
},
"yaml-title-alias": {
"enabled": false,
"preserve-existing-alias-section-style": true,
"keep-alias-that-matches-the-filename": false,
"use-yaml-key-to-keep-track-of-old-filename-or-heading": true
},
"capitalize-headings": {
"enabled": false,
"style": "Title Case",
"ignore-case-words": false,
"ignore-words": "macOS, iOS, iPhone, iPad, JavaScript, TypeScript, AppleScript",
"lowercase-words": "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"
},
"file-name-heading": {
"enabled": false
},
"header-increment": {
"enabled": true,
"start-at-h2": true
},
"footnote-after-punctuation": {
"enabled": true
},
"move-footnotes-to-the-bottom": {
"enabled": false
},
"re-index-footnotes": {
"enabled": true
},
"convert-bullet-list-markers": {
"enabled": false
},
"emphasis-style": {
"enabled": true,
"style": "asterisk"
},
"no-bare-urls": {
"enabled": false,
"no-bare-uris": false
},
"ordered-list-style": {
"enabled": true,
"number-style": "ascending",
"list-end-style": "."
},
"proper-ellipsis": {
"enabled": false
},
"remove-consecutive-list-markers": {
"enabled": false
},
"remove-empty-list-markers": {
"enabled": false
},
"remove-hyphenated-line-breaks": {
"enabled": false
},
"remove-multiple-spaces": {
"enabled": true
},
"strong-style": {
"enabled": true,
"style": "asterisk"
},
"two-spaces-between-lines-with-content": {
"enabled": false
},
"compact-yaml": {
"enabled": false,
"inner-new-lines": false
},
"consecutive-blank-lines": {
"enabled": true
},
"convert-spaces-to-tabs": {
"enabled": false,
"tabsize": 4
},
"empty-line-around-code-fences": {
"enabled": true
},
"empty-line-around-tables": {
"enabled": true
},
"heading-blank-lines": {
"enabled": true,
"bottom": true,
"empty-line-after-yaml": true
},
"line-break-at-document-end": {
"enabled": true
},
"paragraph-blank-lines": {
"enabled": true
},
"remove-empty-lines-between-list-markers-and-checklists": {
"enabled": true
},
"remove-link-spacing": {
"enabled": true
},
"space-after-list-markers": {
"enabled": true
},
"trailing-spaces": {
"enabled": true,
"twp-space-line-break": true
},
"force-yaml-escape": {
"enabled": false,
"force-yaml-escape-keys": ""
},
"headings-start-line": {
"enabled": true
},
"remove-trailing-punctuation-in-heading": {
"enabled": true,
"punctuation-to-remove": ".,;:!。,;:!"
},
"auto-correct-common-misspellings": {
"enabled": false,
"ignore-words": ""
},
"unordered-list-style": {
"enabled": true,
"list-style": "-"
},
"empty-line-around-blockquotes": {
"enabled": false
},
"empty-line-around-math-blocks": {
"enabled": false
},
"move-math-block-indicators-to-their-own-line": {
"enabled": false
},
"remove-space-around-characters": {
"enabled": false,
"include-fullwidth-forms": true,
"include-cjk-symbols-and-punctuation": true,
"include-dashes": true,
"other-symbols": ""
},
"space-between-chinese-japanese-or-korean-and-english-or-numbers": {
"enabled": false
},
"add-blockquote-indentation-on-paste": {
"enabled": false
},
"prevent-double-checklist-indicator-on-paste": {
"enabled": false
},
"prevent-double-list-item-indicator-on-paste": {
"enabled": false
},
"proper-ellipsis-on-paste": {
"enabled": false
},
"remove-hyphens-on-paste": {
"enabled": false
},
"remove-leading-or-trailing-whitespace-on-paste": {
"enabled": false
},
"remove-leftover-footnotes-from-quote-on-paste": {
"enabled": false
},
"remove-multiple-blank-lines-on-paste": {
"enabled": false
},
"blockquote-style": {
"enabled": true,
"style": "space"
},
"quote-style": {
"enabled": false,
"single-quote-enabled": true,
"single-quote-style": "''",
"double-quote-enabled": true,
"double-quote-style": "\"\""
},
"remove-space-before-or-after-characters": {
"enabled": false,
"characters-to-remove-space-before": ",!?;:).’”]",
"characters-to-remove-space-after": "¿¡‘“(["
}
},
"lintOnSave": true,
"recordLintOnSaveLogs": false,
"displayChanged": true,
"lintOnFileChange": true,
"displayLintOnFileChangeNotice": true,
"settingsConvertedToConfigKeyValues": true,
"foldersToIgnore": [],
"linterLocale": "system-default",
"logLevel": "ERROR",
"lintCommands": [],
"customRegexes": [],
"commonStyles": {
"aliasArrayStyle": "multi-line",
"tagArrayStyle": "multi-line",
"minimumNumberOfDollarSignsToBeAMathBlock": 2,
"escapeCharacter": "\"",
"removeUnnecessaryEscapeCharsForMultiLineArrays": true
}
}
I thought this was maybe related to:
Aha. What you say is working, but only for the known keys like aliases and tags, ...
but I see now that it's not enabled.
"insert-yaml-attributes": {
"enabled": false,
"text-to-insert": "aliases: \ntags: "
},
Either there's some bug that doesn't always manifest, or it's too late, or I'm going crazy.
At this point, all I know is that the config options don't do what you say they should be doing.
Using my config, add an authors:
key, make sure it's a List type in Properties, lint, notice authors:
doesn't include a []
. Only aliases:
, tags:
, and other keys listed under "Force key values to be multi-line arrays" format as x: []
. I'd rather have the list blank and have Linter figure out which keys are arrays via Properties to and format them all as x: []
.
@pjkaufman Does the JSON file help to reveal our misunderstanding or what the problem may be?
Hey @redactedscribe , I have not taken a look yet. However I would like to clarify that you are not trying to do convert a non-list key to a list in the YAML. That is to say, you are not doing the following, right? Before Lint
---
authors:
---
After Lint expecting:
---
authors: []
---
If that is the case, then yes, the Linter will not do that unless you add the keys to the list of keys to force multi-line format on it since the Linter first looks for YAML arrays and then formats them.
Edit: if the YAML is not formatted right prior to lint then there is nothing that the Linter can do about it.
I must be doing something wrong since I am not seeing the issue you are referring to.
The only way I could reproduce was having a list in YAML then manually removing all list indicators. Properties still considered the value to be a list, but the actual YAML was not formatted as an array. This is expected since Properties is not setting the content of the YAML properly for that value to be considered a YAML array.
If you look at the file in question, can you confirm that the property that properties is referring to is properly formatted as a list and the Linter is still not handling things properly?
The Linter expects one of the 2 following formats for an empty YAML array (tags and aliases are a little different):
key1: []
key2:
-
If neither of those is present in the YAML then the Linter cannot do anything about it.
I would like to clarify that you are not trying to do convert a non-list key to a list in the YAML. That is to say, you are not doing the following, right? ... If that is the case, then yes, the Linter will not do that unless you add the keys to the list of keys to force multi-line format on it since the Linter first looks for YAML arrays and then formats them.
Yes, that is what I am doing and it is the point of the feature request: For Linter to query Properties whether e.g. authors
is a List (array) or not. With this information, Linter would not need a []
or -
present to determine if the key is an array, nor for the user to have to manually add "authors" to the "Force key values to be multi-line arrays" option.
I don't know if Obsidian's API would let Linter access the necessary information, but hopefully we are on the same page now.
I see. Thanks for bearing with me as I worked through understanding this!
This is something I can see being useful, but I am not sure this would ever get implemented since I don't think properties has an exposed API and logic to test with locally.
Maybe the coming improvements to properties will make this possible if it isn't already. Thank you too.
As it stands, this is not possible since there is no API for working with this data. As such I am going to close this until we have an API that is made accessible. This can be revisited at that time.
Someone posted that there may be a way to see which types exist for which fields:
app.metadataTypeManager.types["essai"] = {name: 'essai', type: 'number'}
app.metadataTypeManager.save()
Is Your Feature Request Related to a Problem? Please Describe.
In my case, "Force key values to be multi-line arrays" has to be manually maintained to be kept in sync with the List property types given to keys. I don't have any special case where I'd not want a List property to not be formatted as a multi-line array.
Describe the Solution You'd Like
If the Obsidian API allows for it, provide an option under "Format YAML Array" which can be toggled on e.g. "Automatically format List properties as multi-line arrays". When off, don't do anything. The current "Force key values to be multi-line arrays" would be in addition to automatically formatting List properties, so both can be used at once.
Describe Alternatives You've Considered
Keep manually maintaining "Force key values to be multi-line arrays".
Thanks.