platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.19k stars 80 forks source link

Bug: Remove Hyphenated Line Breaks Rule Gets Activated Due to Placeholders if Beside Text with a Hyphen #241

Closed mutachre closed 2 years ago

mutachre commented 2 years ago

I think it started (disclaimer: not completely sure) after the recent update but... every time I activate it there are some notes that it totally messes up, and I don't just mean the formatting and spaces, I mean it just moves whole sentences and parts (for hundreds of changes). It happens not in every note, but only in some more complex ones (where, however, before a few days ago it did not happen). I post some before-and-after example screenshots.

Schermata 2022-06-27 alle 20 01 46 Schermata 2022-06-27 alle 20 02 06

Thank you.

pjkaufman commented 2 years ago

@mutachre , Thanks for reporting this.

Could you provide the file that is having an issue and your data.json for the plugin located at pathToVault/.obsidian/plugins/obsidian-linter? These two pieces of information will help me greatly in determining what is happening.

pjkaufman commented 2 years ago

If I had to guess the issue is likely around the use of a bare URL and a link on the sams line right next to each other, but without knowing what rules are active and what the source of the file looks like, it will be guesswork as to what is going on.

mutachre commented 2 years ago

@mutachre , Thanks for reporting this.

Could you provide the file that is having an issue and your data.json for the plugin located at pathToVault/.obsidian/plugins/obsidian-linter? These two pieces of information will help me greatly in determining what is happening.

This is the data.json

{
  "ruleConfigs": {
    "Format Tags in YAML": {
      "Remove Hashtags from tags in the YAML frontmatter, as they make the tags there invalid.": false
    },
    "Insert YAML attributes": {
      "Inserts the given YAML attributes into the YAML frontmatter. Put each attribute on a single line.": false,
      "Text to insert": "aliases: \ntags: "
    },
    "YAML Timestamp": {
      "Keep track of the date the file was last edited in the YAML front matter. Gets dates from file metadata.": false,
      "Date Created": false,
      "Date Created Key": "date created",
      "Date Modified": false,
      "Date Modified Key": "date modified",
      "Format": "dddd, MMMM Do YYYY, h:mm:ss a"
    },
    "YAML Title": {
      "Inserts the title of the file into the YAML frontmatter. Gets the title from the first H1 or filename.": false,
      "Title Key": "title"
    },
    "Escape YAML Special Characters": {
      "Escapes colons with a space after them (: ), single quotes ('), and double quotes (\") in YAML.": false,
      "Default Escape Character": "\"",
      "Try to Escape Single Line Arrays": false
    },
    "Header Increment": {
      "Heading levels should only increment by one level at a time": false
    },
    "File Name Heading": {
      "Inserts the file name as a H1 heading if no H1 heading exists.": false
    },
    "Capitalize Headings": {
      "Headings should be formatted with capitalization": false,
      "Style": "First letter",
      "Ignore Cased Words": true,
      "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"
    },
    "Move Footnotes to the bottom": {
      "Move all footnotes to the bottom of the document.": true
    },
    "Re-Index Footnotes": {
      "Re-indexes footnote keys and footnote, based on the order of occurence (NOTE: This rule deliberately does *not* preserve the relation between key and footnote, to be able to re-index duplicate keys.)": true
    },
    "Footnote after Punctuation": {
      "Ensures that footnote references are placed after punctuation, not before.": true
    },
    "Remove Multiple Spaces": {
      "Removes two or more consecutive spaces. Ignores spaces at the beginning and ending of the line. ": true
    },
    "Remove Hyphenated Line Breaks": {
      "Removes hyphenated line breaks. Useful when pasting text from textbooks.": true
    },
    "Remove Consecutive List Markers": {
      "Removes consecutive list markers. Useful when copy-pasting list items.": true
    },
    "Remove Empty List Markers": {
      "Removes empty list markers, i.e. list items without content.": true
    },
    "Convert Bullet List Markers": {
      "Converts common bullet list marker symbols to markdown list markers.": true
    },
    "Proper Ellipsis": {
      "Replaces three consecutive dots with an ellipsis.": true
    },
    "Emphasis Style": {
      "Makes sure the emphasis style is consistent.": true,
      "Style": "asterisk"
    },
    "Strong Style": {
      "Makes sure the strong style is consistent.": true,
      "Style": "asterisk"
    },
    "No Bare URLs": {
      "Encloses bare URLs with angle brackets except when enclosed in back ticks, square braces, or single or double quotes.": true
    },
    "Two Spaces Between Lines with Content": {
      "Makes sure that two spaces are added to the ends of lines with content continued on the next line for paragraphs, blockquotes, and list items": false
    },
    "Trailing spaces": {
      "Removes extra spaces after every line.": true,
      "Two Space Linebreak": false
    },
    "Heading blank lines": {
      "All headings have a blank line both before and after (except where the heading is at the beginning or end of the document).": true,
      "Bottom": true
    },
    "Paragraph blank lines": {
      "All paragraphs should have exactly one blank line both before and after.": false
    },
    "Space after list markers": {
      "There should be a single space after list markers and checkboxes.": true
    },
    "Remove Empty Lines Between List Markers and Checklists": {
      "There should not be any empty lines between list markers and checklists.": true
    },
    "Compact YAML": {
      "Removes leading and trailing blank lines in the YAML front matter.": true,
      "Inner New Lines": true
    },
    "Consecutive blank lines": {
      "There should be at most one consecutive blank line.": true
    },
    "Convert Spaces to Tabs": {
      "Converts leading spaces to tabs.": true,
      "Tabsize": "4"
    },
    "Line Break at Document End": {
      "Ensures that there is exactly one line break at the end of a document.": true
    },
    "Space between Chinese and English or numbers": {
      "Ensures that Chinese and English or numbers are separated by a single space. Follow this [guidelines](https://github.com/sparanoid/chinese-copywriting-guidelines)": false
    },
    "Remove link spacing": {
      "Removes spacing around link text.": true
    }
  },
  "lintOnSave": false,
  "displayChanged": true,
  "foldersToIgnore": [
    ""
  ]
}

and the file:

Zettelkasten (Test).md

Hope it helps!

pjkaufman commented 2 years ago

Thanks @mutachre ! I am now able to reproduce this issue. I will see about fixing this for next release which will hopefully be this week.

pjkaufman commented 2 years ago

@mutachre, it looks like the issue was a bad link syntax in the file:

- [Zettelkasten Note-Taking Method: Simply Explained (Video)](https://youtu.be/rOSZOCoqOo8- [Metodo dettagliato e considerazioni](https://youtu.be/rOSZOCoqOo8)

It is missing an end parentheses after https://youtu.be/rOSZOCoqOo8- which makes it not get considered to be a markdown link. I need to look into what happened to cause the placeholder for the link to not get recognized, but likely it accidentally caught the whitespace as a part of the link that got ignored using the placeholder.

The above should be the following to be a valid link:

- [Zettelkasten Note-Taking Method: Simply Explained (Video)](https://youtu.be/rOSZOCoqOo8-) [Metodo dettagliato e considerazioni](https://youtu.be/rOSZOCoqOo8)
pjkaufman commented 2 years ago

So the long explanation of what happened is that the rules technically worked as expected. https://youtu.be/rOSZOCoqOo8- gets affected by the rule to remove the hyphenated line break since it ends in a dash. As it was, it would not get affected. However when we put in a placeholder for the link the text became:

- [Zettelkasten Note-Taking Method: Simply Explained (Video)](https://youtu.be/rOSZOCoqOo8- PLACEHOLDER_LINK 57849

This does meet the conditions to be considered a hyphenated line break that needs addressing. It changes the text to the following:

- [Zettelkasten Note-Taking Method: Simply Explained (Video)](https://youtu.be/rOSZOCoqOo8PLACEHOLDER_LINK 57849

To fix this, I can add a character like | or { and } around the placeholder text to make sure it does not get recognized as a valid portion of text to remove the hyphen for.

pjkaufman commented 2 years ago

I should have a fix for this scenario shortly. I am just retesting with your setup to make sure that just fixing it for the one rule will not cause other issues.

pjkaufman commented 2 years ago

Looks to work for both scenarios. So I will push it up and it will go out with the next release. Feel free to go ahead and use master or wait until the next release to get the fix. However adding the missing parenthese will fix the issue in that one case for you. Thanks again for reporting the issue!

pjkaufman commented 2 years ago

Please let me know if for some reason this issue persists for you once you use either master or the next release.

mutachre commented 2 years ago

it looks like the issue was a bad link syntax in the file.

That's exactly it! I thank you for investigating and for the prompt reply; now the file is linting correctly. Even if it was my own mistake, I hope I raised some useful points for the development of this (fantastic) plugin.

pjkaufman commented 2 years ago

It did. It also showed an issue that could happen in more than 1 place that I was able to fix.