Skip to content

Fixes \n and removes backslash before double quotes in property value#687

Open
d-kaue wants to merge 4 commits intoobsidianmd:mainfrom
d-kaue:fix-property
Open

Fixes \n and removes backslash before double quotes in property value#687
d-kaue wants to merge 4 commits intoobsidianmd:mainfrom
d-kaue:fix-property

Conversation

@d-kaue
Copy link
Contributor

@d-kaue d-kaue commented Feb 7, 2026

Fixes #598

This PR fixes two issues from the same source:

export function escapeValue(value: string): string {
return value.replace(/"/g, '\\"').replace(/\n/g, '\\n');
}
export function unescapeValue(value: string): string {
return value.replace(/\\"/g, '"').replace(/\\n/g, '\n');
}

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, and unescapeValue was making it into a newline, for this reason we don't see it. however it's possible to see the newline in value attribute.

I have done a test in https://help.obsidian.md/web-clipper/filters to replace \n with @ 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 escapeValue and unescapeValue functions are not necessary, and it was adding backslash before double quotes in template properties. So I have created a patch to fix this and uses patchAndUpdateTemplateVersion inside loadTemplates to 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 schemaVersion to any templates (seems that some templates doesn't have it in sync storage) to be sure we run patchAndUpdateTemplateVersion once 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.1

A 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Newline characters being erroneously removed

1 participant

Comments