lervag / wiki-ft.vim

Simple Vim filetype plugin for wiki-files
MIT License
14 stars 5 forks source link

change bold conceal to markdown "standard" #15

Closed felixschurk closed 1 year ago

felixschurk commented 1 year ago

Hei Lervag, this is more a question than an issue. What would I need to change that the Bold conceal does also work with **bold text** instead only *bold*, to use two stars as the bold markup.

I tried with changing

https://github.com/lervag/wiki-ft.vim/blob/d547e58dc7e6cf144e1d490a243b0788dd37104f/syntax/wiki.vim#L245

to use /**/ however that only conceals the last ** and the first one is still only concealed once.

I also know that there are more markdown specific ft plugins, however most of them do not properly deal with wiki links, therefore I wanted to use this one.

Thank you already for the reply! Best Felix

lervag commented 1 year ago

Hei Lervag,

Hei @felisschurk

this is more a question than an issue.

I don't mind questions :)

What would I need to change that the Bold conceal does also work with **bold text** instead only *bold*, to use two stars as the bold markup. I tried with changing …

The * is special in regexes as it is used to "any number of the preceding atom". However, if the regex is just the single letter *, then it will match the literal *. To match two *s you need to escape the symbols, i.e. /\*\*/.

However, to match the Markdown variant **bold**, you need to change more. If you add this to your own personal after/syntax/wiki.vim, it should work:

syntax match wikiBold
      \ /\v%(^|\s|[[:punct:]])\zs\*\*[^*`[:space:]]%([^*`]*[^*`[:space:]])?\*\*\ze%([[:punct:]]|\s|$)/
      \ contains=wikiBoldItalic,wikiConcealBold,@Spell
syntax match wikiConcealBold /\*\*/ contained conceal

I know the regex is very hard to read! But the idea is to handle some edge cases to avoid unexpected matches.

You could also use something like this, which is much simpler:

syntax match wikiBold \ /\*\*[^*]*\*\*/
      \ contains=wikiBoldItalic,wikiConcealBold,@Spell
syntax match wikiConcealBold /\*\*/ contained conceal

Here we first match two *s, then [^*]* will match any number of characters that are not *s, before we again match two *s. It would probably work fine in almost all cases.

I also know that there are more markdown specific ft plugins, however most of them do not properly deal with wiki links, therefore I wanted to use this one.

Cool :)

felixschurk commented 1 year ago

Thank you a lot, this works like a charm.

For a further understanding, if I in generally want to modify or adapt a vim plugin you would usually put the changes in the after/.../ folder? Or does this hardly depend on what you would like to change?

lervag commented 1 year ago

Thank you a lot, this works like a charm.

Good to hear!

For a further understanding, if I in generally want to modify or adapt a vim plugin you would usually put the changes in the after/.../ folder?

Generally, no. But often, yes.

Or does this hardly depend on what you would like to change?

I would say it depends, but that you can often use after/... to adjust your plugins. The crucial thing to understand here is that Vim (and neovim) loads user scripts in a very definite order. The point of after/ftplugin/... is that you are writing code that will be automatically loaded by the filetype mechanism, but that is guaranteed to be loaded after anything that is not in a after/ directory.

It is really quite well explained in :help startup; see step 4 (Vim) or 10 (neovim); but the entire section is really a useful thing to at least have a broad understanding of.