Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiline bold, italic, code #58

Open
habamax opened this issue Feb 26, 2020 · 19 comments
Open

multiline bold, italic, code #58

habamax opened this issue Feb 26, 2020 · 19 comments
Assignees
Labels
enhancement New feature or request

Comments

@habamax
Copy link
Owner

habamax commented Feb 26, 2020

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

No empty lines should be between *

@habamax habamax self-assigned this Feb 26, 2020
@habamax habamax added the enhancement New feature or request label Feb 26, 2020
@habamax
Copy link
Owner Author

habamax commented Feb 26, 2020

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

@habamax
Copy link
Owner Author

habamax commented Mar 6, 2020

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
Copy link
Owner Author

habamax commented Mar 25, 2020

    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
Copy link
Owner Author

habamax commented Mar 25, 2020

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

@habamax habamax closed this as completed Mar 25, 2020
@mg979
Copy link
Contributor

mg979 commented Mar 30, 2020

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

@habamax
Copy link
Owner Author

habamax commented Mar 30, 2020

Thx, I will check today

@habamax habamax reopened this Mar 30, 2020
@habamax
Copy link
Owner Author

habamax commented Mar 30, 2020

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.

@mg979
Copy link
Contributor

mg979 commented Mar 30, 2020

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

@habamax
Copy link
Owner Author

habamax commented Mar 30, 2020

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

@mg979
Copy link
Contributor

mg979 commented Mar 31, 2020

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.

@habamax
Copy link
Owner Author

habamax commented Mar 31, 2020

I made an attempt here

Thank you, will check it

@habamax
Copy link
Owner Author

habamax commented Apr 1, 2020

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)

@mg979
Copy link
Contributor

mg979 commented Apr 1, 2020

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.

@habamax
Copy link
Owner Author

habamax commented Apr 1, 2020

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

@mg979
Copy link
Contributor

mg979 commented Apr 1, 2020

You can see the current differences here

master...mg979:multiline_bolditalic

I'll try to improve it when I'll have the time

@habamax
Copy link
Owner Author

habamax commented Apr 7, 2020

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

@mg979
Copy link
Contributor

mg979 commented Apr 7, 2020

  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.

@habamax
Copy link
Owner Author

habamax commented Apr 7, 2020

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
Copy link
Owner Author

habamax commented May 20, 2020

Checking multiline from @mg979

Paragraphs probably should be aware of this

image

Paragraph definition is too greedy?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants