obsidian-linter icon indicating copy to clipboard operation
obsidian-linter copied to clipboard

Bug: "Remove Multiple Spaces" rule ignores >1 spaces inside of tables

Open redactedscribe opened this issue 2 years ago • 5 comments

  • [x] I have verified that I am on the latest version of the Linter (using main.js from #910)

Describe the Bug

The "Remove Multiple Spaces" rule does not work inside of tables.

How to Reproduce

Steps to reproduce the behavior:

| Foo | Bar |
| --- | --- |
| Hello | World! Some  double  spaces  and a link [ here is link text1 ](link_here). |    

(Last | above has 4 spaces after it)

Double  spaces  outside of a table and a link [ here is link text1 ](link_here).

The example contains links only for the purposes of showing that Linter can and does process content inside of tables, but for some reason just ignores processing double spaces.

  1. Enable "Remove Multiple Spaces".
  2. Enable "Remove link spacing".
  3. Paste example above into Obsidian.
  4. Lint. Spaces for links are removed from both inside and outside of the table, but only double spaces outside of the table are removed.

Expected Behavior

Double spaces should be removed from everywhere in the note body (unless "Trailing Spaces" > "Two Space Linebreak" is enabled -- or any other space rule which should override).

Expected output if applicable:

| Foo | Bar |
| --- | --- |
| Hello | World! Some double spaces and a link [here is link text1](link_here). |

(Last | above has 4 spaces after it)

Double spaces outside of a table and a link [here is link text1](link_here).

Device

  • [x] Desktop
  • [ ] Mobile

Additional Context

Assumed "Remove Multiple Spaces" rule would be under the Spacing tab in the settings, but in fact it is under Content. Perhaps it should be under Spacing?

Thanks.

redactedscribe avatar Nov 27 '23 21:11 redactedscribe

Hey @redactedscribe . I am not sure that this is a bug. If I recall, the reason tables are not affected is because removing multiple spaces in a table removes styling added to those tables like making sure all rows have the same length.

I am not sure I would want to change that behavior since it could mess up table styling which I have no intention of supporting in the Linter.

pjkaufman avatar Nov 28 '23 10:11 pjkaufman

I understand your concerns @pjkaufman, however I do not style my tables so fixing >1 spaces would not be a problem in my case.

(Edit: By style I mean align the table using spaces. I do "style" it by having a space before and after vertical bars, which might require some support and is something I did not consider at first.)

Is "Remove Multiple Spaces" the only rule which doesn't run on tables? If so, Linter already supports tables you could say, it just doesn't touch spacing.

If that holds true, then instead of hardcoding skipping over the "Remove Multiple Spaces" rule, we could have an "Ignore rules from table linting" option with a list filter where we can add rule aliases (with "remove-multiple-spaces" listed by default).

This would then at least give us the option to remove "remove-multiple-spaces" if we don't want space-aligned tables in source.

redactedscribe avatar Nov 28 '23 14:11 redactedscribe

The issue with removing multiple spaces is that it will remove spaces before and after text in a table as well. It can be handled, but that would take treating tables as special and then handling them as a one off. That is possible, but it would likely be some time before I could take a look at it assuming there is not a lot of desire for this from the community.

However, I would be fine with accepting a PR for this.

pjkaufman avatar Nov 28 '23 16:11 pjkaufman

It would mess with the following table styling:

| Foo        | Bar                                                                                                        |
| --------- | -------------------------------------------------------------------------- |
|     Hello | World! Some double spaces and a link [here is link text1](link_here). |

would become

| Foo | Bar |
| --------- | -------------------------------------------------------------------------- |
| Hello | World! Some double spaces and a link [here is link text1](link_here). |

pjkaufman avatar Nov 28 '23 16:11 pjkaufman

The issue with removing multiple spaces is that it will remove spaces before and after text in a table as well.

I understood this, which is why I suggested keeping the behaviour the same but letting users who don't want/need nicely spaced tables in their Markdown to opt out.

That is possible, but it would likely be some time before I could take a look at it assuming there is not a lot of desire for this from the community.

My assumption would be that some users do format their tables nicely, and others don't bother (which my guess would be the majority, but I don't know). For those that don't bother, I assume they'd also want them to be spaced like the rest of their file.

However, I would be fine with accepting a PR for this.

Thanks for being open to a PR.

redactedscribe avatar Nov 28 '23 16:11 redactedscribe