ndy2 / mkdocs-obsidian-support-plugin

A MkDocs plugin that supports obsidian to mkdocs convert
https://ndy2.github.io/mkdocs-obsidian-support-plugin/
MIT License
15 stars 5 forks source link

feature: support obsidian #tags #6

Closed daxcore closed 9 months ago

daxcore commented 9 months ago

the #tags will be converted into tags{: .hash} this .hash class can be used for javascript and css

prerequisites:

mkdocs.yml:

extra_css:
  - assets/css/obsidian_tags.css

extra_javascript:
  - https://code.jquery.com/jquery-3.7.1.min.js
  - assets/javascript/obsidian_tags.js

obsidian_tags.css:

.hash {
  background-color: #f3eefd;
  border-radius: 20px;
  padding: 5px;
  font-weight: normal;
}

obsidian_tags.js:

$('.hash').each(function() {
  var link = $(this).html();
  $(this).contents().wrap('<a href="?q='+link+'">#</a>');
});
ndy2 commented 9 months ago

Thank you for for nice suggestion and even PR!

I understand all your code and intension of the suggestion. It looks awesome.

Somehow, I fixed the broken unit test and added some unittest on it. As you might noticed that this project is just my side project and there are many bugs.

So there is no branch strategy or delicated ci-cd process. I would merge all your PR on main but would not release until handle below issues.

  1. add unit test on TagConversion.

  2. (this is suggestion) update OBSIDIAN_TAGS_REGEX to esacpe on \ prefix (e.g. #sometag) After I see this issue. I worried that it would convert not only tags but naive hashtags or # started strings. this forum - /is-it-possible-to-ignore-certain-tags is about same issue and it says add backslash (\) can be a solution and i think it is very good.

  3. (this is suggestion too) add # (%23) on tag href. so the query can be search the actual tag.

If you want to finish this feature by your own. Please consider work on abover three issues. Or you may agree, I would develop them and ask review to you, or I just do everything.

Please tell me your comment on above plan. I would merge all opened PR till this weekend.

daxcore commented 9 months ago

thanks for ur interest into this feature. i would be happy if u could add the unit-tests.

i updated the regex string to prevent tags prefixed by backslash and inside of codeblocks.

like this:

#tag
# notag
(#notag)
[#notag]
[[#notag]]
\#notag

#notag

 #notag

i don't understand the third point. currently, the # symbol is just added by javascript while runtime. the hashtag of obsidian files will be ignored by the regex string. the match group just contains the tagname. so the link, searchs for all locations, where this word/tagname was used, also that ones, not prefixed as a tag.

please feel free to finish this pull-request. i could do a review in the end, or i would open a new issue, if there are suggestions by my side ;)