vim-asciidoctor
vim-asciidoctor copied to clipboard
multiline bold, italic, code
*this should be highlighted
as bold in vim-asciidoctor*
No empty lines should be between *
*bold text _now bold+italic goes all
the way till here_ now bold again and it ends here*
Probably would be impossible to do it right:
__ italic text
is not italic because of newline__
shouldn't be italic but it would with my test implementation.
Even if you introduce a paragraph and make italic contained -- first line will still be italic.
syn region asciidoctorBold matchgroup=Conceal start=/\m\*\*\ze./ end=/\*\*/ contains=@Spell concealends
" override bold if it was multilined with empty rows between
syn match asciidoctorNonBold /\*\*.*[^*]\{2}\s*\ze\n\n\+/ contains=@Spell
syn region asciidoctorItalic matchgroup=Conceal start=/\m__\ze./ end=/__/ contains=@Spell concealends
" override italic if it was multilined with empty rows between
syn match asciidoctorNonItalic /__.*[^_]\{2}\s*\ze\n\n\+/ contains=@Spell
syn region asciidoctorBold matchgroup=Conceal start=/\m\*\*\ze./ end=/\*\*/ contains=@Spell concealends
" override bold if it was multilined with empty rows between
syn match asciidoctorNonBold /\*\*.*[^*]\{2}\s*\ze\n\n\+/ contains=@Spell
Best thing I could come up with.
It works for some cases (when there is empty line between begin and end it works), but very fragile -- you can easily end up having the rest of your buffer italic if __
placed without paired __
.
This is italic starting from dolor
which is clearly wrong but I have no Idea how to tell vim region syntax to stop this at proper places :(
. Lorem ipsum __dolor sit amet, consectetur adipiscing elit. Maecenas feugiat
fermentum pretium. Cras eu dolor imperdiet justo mattis pulvinar.
. Cras nec lectus ligula. Proin elementum luctus elit, a tincidunt quam
facilisis non.
. Nunc quis mauris non turpis finibus luctus. Maecenas ante sapien, sagittis
quis accumsan in, feugiat quis sem. Praesent et auctor libero.
I will park it for now, suggesting to not using multiline inline markup.
Maybe this can work? They should replace the existing ones, I removed oneline
and added \n\n
as pattern that can close the region (in end
)
syn region asciidoctorBold matchgroup=Conceal start=/\m\*\*/ end=/\*\*\|\n\n/ contains=@Spell concealends
syn region asciidoctorBold matchgroup=Conceal start=/\m\%(^\|[[:punct:][:space:]]\@<=\)\*\ze[^* ].\{-}\S/ end=/\*\%([[:punct:][:space:]]\@=\|$\)\|\n\n/ contains=@Spell concealends
syn region asciidoctorItalic matchgroup=Conceal start=/\m__/ end=/__\|\n\n/ contains=@Spell concealends
syn region asciidoctorItalic matchgroup=Conceal start=/\m\%(^\|[[:punct:][:space:]]\@<=\)_\ze[^_ ].\{-}\S/ end=/_\%([[:punct:][:space:]]\@=\|$\)\|\n\n/ contains=@Spell concealends
syn region asciidoctorBoldItalic matchgroup=Conceal start=/\m\*\*_/ end=/_\*\*\|\n\n/ contains=@Spell concealends
syn region asciidoctorBoldItalic matchgroup=Conceal start=/\m\%(^\|[[:punct:][:space:]]\@<=\)\*_\ze[^*_ ].\{-}\S/ end=/_\*\%([[:punct:][:space:]]\@=\|$\)\|\n\n/ contains=@Spell concealends
Thx, I will check today
Not sure if it is possible to be exactly complient
== Tes№t *of* dif__fe__r##ent## `text` #properties# here
:sectnums:
**Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas feugiat fermentum pretium. Cras eu dolor imperdiet justo mattis
pulvinar. **
regular text
**Cras nec lectus ligula. Proin elementum luctus elit, a tincidunt quam
facilisis non. Nunc quis mauris non turpis finibus luctus. Maecenas ante
sapien, sagittis quis accumsan in, feugiat quis sem. Praesent et auctor libero.
list:
* Lorem __ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas feugiat fermentum pretium. Cras eu dolor imperdiet justo mattis
Maecenas feugiat fermentum pretium. Cras eu dolor imperdiet justo mattis
* pulvinar. Cras nec lectus ligula. Proin elementum luctus elit, a tincidunt quam
facilisis non. Nunc quis mauris non turpis finibus luctus. Maecenas ante
* sapien, sagittis quis accumsan in, feugiat quis sem. Praesent et auctor libero.
There could be a contained
variant that is used in regular paragraphs, but not in lists, to avoid the list problem. I'll see if I can do it.
If a variant is used, it could be limited to patterns with double __
and **
, so that it's more explicit and it would still work.
This cannot be avoided I think, but it's a minor issue:
**Cras nec lectus ligula. Proin elementum luctus elit, a tincidunt quam
facilisis non. Nunc quis mauris non turpis finibus luctus. Maecenas ante
This cannot be avoided I think, but it's a minor issue:
**Cras nec lectus ligula. Proin elementum luctus elit, a tincidunt quam facilisis non. Nunc quis mauris non turpis finibus luctus. Maecenas ante
Actually this, kind of, could be mitigated with additional match:
syn region asciidoctorBold matchgroup=Conceal start=/\m\*\*/ end=/\*\*\|\n\n/ contains=@Spell concealends
" override bold if it was multilined with empty rows between
syn match asciidoctorNonBold /\*\*.*[^*]\{2}\s*\ze\n\n\+/ contains=@Spell
This is not yet 100% proof as it only works for 1 line (probably could be tuned)
I made an attempt here
https://github.com/mg979/vim-asciidoctor/blob/multiline_bolditalic/syntax/asciidoctor.vim
It allows multiline bold/italics only in regular paragraphs. At least this is the intention.
Edit: it seems to b very slow unfortunately.
I made an attempt here
Thank you, will check it
Edit: it seems to b very slow unfortunately.
Ok. Do you think we should keep them oneline
ed? (I think we should do, and just document this in a readme)
I made it a bit faster I think. I don't know if there's a better (and acceptably fast) solution than the one I tried. To have multiline working would be good because otherwise bold/italics can break every time a paragraph is reformatted, but right now oneline
is ok.
To have multiline working would be good because otherwise bold/italics can break every time a paragraph is reformatted
That is why actually I have decided to try to implement multilined bold/italic :)
You can see the current differences here
https://github.com/habamax/vim-asciidoctor/compare/master...mg979:multiline_bolditalic
I'll try to improve it when I'll have the time
Thank again!, tried it, not sure about speed (I didn't feel it slow, but no real measurements were done :) )
Basically, introducing paragraph and other "blocks" is the way to go to more or less properly implement this. For now the issues are in gif:
- options are not highlighted
- when bold starts, list becomes paragraph and list bullets are not highlighted
- "hanging" bold -- non-closed bold region
- must be fixed, paragraph should include most other clusters
- this maybe because it's the last char of the line, in that case? Or maybe you have
\r\n
line endings, and\n\n
isn't matched? - I don't think it can be fixed, markdown syntax also allows conceal/multiline and when italics/boldd start, the whole buffer after it becomes bold/italic. Maybe with some negative lookahead pattern, but they tend to be very slow.
Personally I would only allow them in regular paragraphs, not in lists/tables etc, it simplifies things.
Personally I would only allow them in regular paragraphs, not in lists/tables etc, it simplifies things.
Ok
2\. this maybe because it's the last char of the line, in that case? Or maybe you have `\r\n` line endings, and `\n\n` isn't matched?
I have unix lineendings for all my docs (just doublechecked set ff
echoes fileformat=unix
)
3\. I don't think it can be fixed, markdown syntax also allows conceal/multiline and when italics/boldd start, the whole buffer after it becomes bold/italic. Maybe with some negative lookahead pattern, but they tend to be very slow.
Ok.
Checking multiline from @mg979
Paragraphs probably should be aware of this
Paragraph definition is too greedy?