markdown-oxide icon indicating copy to clipboard operation
markdown-oxide copied to clipboard

Tag definition

Open dawsers opened this issue 1 year ago • 5 comments

I am sorry I am bringing this up again. I have noticed a small bug when parsing tags.

According to the Obsidian manual, a tag is defined this way:

Tag format

You can use any of the following characters in your tags:

  • Alphabetical letters
  • Numbers
  • Underscore (_)
  • Hyphen (-)
  • Forward slash (/) for Nested tags

Tags must contain at least one non-numerical character. For example, #1984 isn't a valid tag, but #y1984 is.

When I use tag auto-completion, I get this:

screenshot-1713774068

It seems parsing only tests for at least one non-numerical character between # and a space. That is why #2024 is parsed correctly as a non-tag, but not the links. Those tags include the full URL. #7 wouldn't be a tag, but if we include ] and the rest as valid characters for a tag name, we end up with the tag shown in the dialogue. The same goes for #seven.

The tree-sitter markdown parser considers this a tag:

_tag_name: $ => seq($._word_no_digit, repeat(choice($._word_no_digit, $._digits, '-'))),

that means after the # there cannot be a digit as first character, but then they are allowed, so #y1984 is valid, but #1984y isn't.

So I think the regular expression needs some tweaking, something like:

/(^| )+#[a-zA-Z_\-\/][0-9a-zA-Z_\-\/]*/

screenshot-1713777330

I don't know about #-/_/tag, but it doesn't seem the spec rejects it. Maybe you prefer to tweak the first part so the first character doesn't include _-/ either.

Thank you!

dawsers avatar Apr 22 '24 09:04 dawsers

Thank you for this!

Your comments are exceptionally helpful!

Solving this should involve a trivial adjustment of the tag regex + some testing. Nothing too hard!

Feel-ix-343 avatar Apr 22 '24 19:04 Feel-ix-343

I would like to be of more help by coding instead of filing reports, but as I explained, Rust is foreign to me. I spent one full day trying to change six lines of code in the Vault part of your application before I gave up. :-)

dawsers avatar Apr 22 '24 19:04 dawsers

Ah well the reports are extremely helpful.

Also I am in the process of a huge refactor, and the current code is not very good to be honest. Hopefully after the refactor things will become more clear!

Feel-ix-343 avatar Apr 22 '24 19:04 Feel-ix-343

Also, tag completion only happens at the start of line. Is it the default behaviour?

anandkumar89 avatar Apr 29 '24 12:04 anandkumar89

Also, tag completion only happens at the start of line. Is it the default behaviour?

This is because of #17 ; It's an nvim-cmp issue

Feel-ix-343 avatar Apr 29 '24 12:04 Feel-ix-343