vim-asciidoctor icon indicating copy to clipboard operation
vim-asciidoctor copied to clipboard

multiline bold, italic, code

Open habamax opened this issue 4 years ago • 19 comments

*this should be highlighted
as bold in vim-asciidoctor*

No empty lines should be between *

habamax avatar Feb 26 '20 08:02 habamax

*bold text _now bold+italic goes all 
the way till here_ now bold again and it ends here*

habamax avatar Feb 26 '20 09:02 habamax

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.

image

habamax avatar Mar 06 '20 10:03 habamax

    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.

image

habamax avatar Mar 25 '20 16:03 habamax

I will park it for now, suggesting to not using multiline inline markup.

habamax avatar Mar 25 '20 16:03 habamax

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

mg979 avatar Mar 30 '20 03:03 mg979

Thx, I will check today

habamax avatar Mar 30 '20 03:03 habamax

Not sure if it is possible to be exactly complient

image image

== 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.

habamax avatar Mar 30 '20 06:03 habamax

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

mg979 avatar Mar 30 '20 07:03 mg979

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) image

habamax avatar Mar 30 '20 07:03 habamax

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.

mg979 avatar Mar 31 '20 05:03 mg979

I made an attempt here

Thank you, will check it

habamax avatar Mar 31 '20 12:03 habamax

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)

habamax avatar Apr 01 '20 06:04 habamax

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.

mg979 avatar Apr 01 '20 07:04 mg979

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 :)

habamax avatar Apr 01 '20 07:04 habamax

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

mg979 avatar Apr 01 '20 08:04 mg979

Thank again!, tried it, not sure about speed (I didn't feel it slow, but no real measurements were done :) )

vim-asciidoctor-multiline1

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:

  1. options are not highlighted
  2. when bold starts, list becomes paragraph and list bullets are not highlighted
  3. "hanging" bold -- non-closed bold region

habamax avatar Apr 07 '20 07:04 habamax

  1. must be fixed, paragraph should include most other clusters
  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?
  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.

Personally I would only allow them in regular paragraphs, not in lists/tables etc, it simplifies things.

mg979 avatar Apr 07 '20 08:04 mg979

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.

habamax avatar Apr 07 '20 08:04 habamax

Checking multiline from @mg979

Paragraphs probably should be aware of this

image

Paragraph definition is too greedy?

image

habamax avatar May 20 '20 17:05 habamax