Fixes \n and removes backslash before double quotes in property value#687
Open
d-kaue wants to merge 4 commits intoobsidianmd:mainfrom
Open
Fixes \n and removes backslash before double quotes in property value#687d-kaue wants to merge 4 commits intoobsidianmd:mainfrom
\n and removes backslash before double quotes in property value#687d-kaue wants to merge 4 commits intoobsidianmd:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #598
This PR fixes two issues from the same source:
obsidian-clipper/src/utils/string-utils.ts
Lines 9 to 15 in 1ea04c9
These helper functions are used exclusively for property value.
Newline issue
The issue with newline (
\n) not appearing is because HTML input does not render newline, andunescapeValuewas making it into a newline, for this reason we don't see it. however it's possible to see the newline invalueattribute.I have done a test in https://help.obsidian.md/web-clipper/filters to replace
\nwith@to see it, and it's working now.{{content|slice:0,500|replace:"\n":"#NEWLINE#"}}Backslash issue
Another thing I noticed by debugging the newline is that
escapeValueandunescapeValuefunctions are not necessary, and it was adding backslash before double quotes in template properties. So I have created a patch to fix this and usespatchAndUpdateTemplateVersioninsideloadTemplatesto make sure that when updating the extension, the correct value will be there when the popup or embbed is opened. This handles when opening the settings, "Import all settings" and individual imports (JSON and file) too.Also I have set
schemaVersionto any templates (seems that some templates doesn't have it in sync storage) to be sure we runpatchAndUpdateTemplateVersiononce to prevent any removal to the user's backslash + double quote. (prevents filter args like this"\""to be become this""")Updated the SCHEMA_VERSION to
0.1.1A template like this
{ "schemaVersion": "0.1.0", "name": "TEST", "behavior": "create", "noteContentFormat": "", "properties": [ { "name": "test", "value": "{{title|replace:\\\"shouldn't remove this \\\\\" backslash\\\":\\\"and keeps \\n visible\\\"}}", "type": "text" } ], "triggers": [], "noteNameFormat": "{{title}}", "path": "" }Will be updated to
{ "schemaVersion": "0.1.1", "name": "TEST", "behavior": "create", "noteContentFormat": "", "properties": [ { "name": "test", "value": "{{title|replace:\"shouldn't remove this \\\" backslash\":\"and keeps \\n visible\"}}", "type": "text" } ], "triggers": [], "noteNameFormat": "{{title}}", "path": "" }Note:
\\\"= backslash + escaped double quote\\"= backslash + double quote\"= escaped double quote