2

Occasionally I embed base64 in markdown like:

<figure>
<img src="data:image/png;base64,/9j/4AAQ … [snip] " width="100%"> 
</figure>

I have this defined in syntax markdown.vim:

syn region markdownBase64Image start=/<img src="data:image/ end=/"/ conceal cchar=X

It works but I have many blank lines under cchar and then if cursor and concealed line is moved to top of window, the remaining base64 code appears. It kind of defeats the purpose.

I would like to conceal the base64 string to see the context in which it appears. Like

<figure>
X
</figure>

I've read the help docs and searched online but cannot find anything to help me.

Edit: Added more info

With conceallevel=2 and concealcursor= it looks like this:

enter image description here

Base64 string does not include 'end' pattern '"'. It marks the end of the base64 representation.

Edit: Added more additional info

  • the syntax rule is defined in .../vimfiles/after/syntax/markdown.vim. there is only the one line (shown above).
  • the file has also :set cole=1 and set concealcursor=.
  • i have also tested syntax rule with text file with no filetype. i'm guessing this means no other syntax rules apply.my issue is the same when syntax rule is input through command line.
  • while the example image shows <img> tag surrounded by <figure> tag, i have tested syntax rules in other contexts and the issue is the same.
  • example base64 image data (i have encoded and tested a tiny 819b image and give the string here. while the effect is not so extreme, same issue persists. Also note string is one line.):
<img src="data:image/png;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/2wBDARUXFx4aHjshITt8U0ZTfHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHz/wAARCAA4AGQDASIAAhEBAxEB/8QAGQAAAwEBAQAAAAAAAAAAAAAAAAMEAgEF/8QAKhAAAQQBAwMEAAcAAAAAAAAAAQACAxEhBDFBEhNRBSJhgRUkMjNxocH/xAAXAQEBAQEAAAAAAAAAAAAAAAACAAED/8QAGxEBAQADAQEBAAAAAAAAAAAAAAECETEhQkP/2gAMAwEAAhEDEQA/APFgsvA4BV9KdvbJFAXarRjpWKXaW6RWFCleMrJwnOGVgtUx5ZmeNS5oFi1XFKBROAiLS9/VFpw0b1yvU/D4TFXTXyjacxSNAIwtFqnBMGqETjzSsIWimc1NngijDqcSQuuHtS3kuJJNk7qRQCFqghSOEzOQmCVpypS2gtA4WpWJIzyFokVuFH8BFnhwVth5C5SV3jy1a748FSLhid3ZXBxbm/6Xo9pznNIkrGQvPa49RwQCr4v2xn6C512x4m12nic7vE0QKGdzwtlSztdJ6n0kWAAVW5bOBesOHsSXDCokcBEASku2CYku3Quu3QpOg9wLrY8brMYoUmtPCkSXDqwsA08dJP8AC26hKMLM5a0iiLKNZXHTFrwALv4ToonaiaNhuMO3cP8AFMZTG9vcGDg4V+lNSxmsWClJ4zZjtCYyWhxLR5K3E0RHKvkHP0kSAVshl13l8eK6Qy6+Uhxb4TXyStb1FuTx4WA388SP0nhMnlLQaFkmgnJ45ZVNMZZOklpTmOtteE2GMBlEknklKcOlytDK445Qsu3QtI7pxgg0tNF5QhYk+pOaCn1EJa1riRuhC1lcjBlbTs8Kv0+Q4jcctdSEJBOPfDgbS3Rg7OH2hCOUh42vI1DY4vUAA6zWSkPdeso1TcoQqMy6rhNlwStRW4Qhcv0pfKZ0rb3QhC6i/9k=">

Edit: More info

Vim version:

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan  3 2024 00:15:11)
MS-Windows 32-bit GUI version with OLE support
Compiled by appveyor@APPVEYOR-VM

I have tested on 'clean' vim ...\vim91\gvim.exe --clean -i ~/.viminfo2 and recorded output to 'gif':

(Strangely, I tried uploading a 1M gif 700x800px and got error "Image uploads are limited to 50 megapixels; please use a smaller image" Tried with other gifs and same problem. However, it's happy with an '.apng' file.)

Click on image if it stops looping :)

enter image description here

Edit (240626):

:set nowrap changes effect of conceal but makes the effort rather pointless. With nowrap the embeddded image is no longer a problem (it occupies only one line) and I would not bother trying to conceal it. But then, most of my text is in lines longer than screen width so setting :set nowrap has the effect of concealing most of my text!

There appears to be a bug however if I assume there's not a problem with my vim. See how the conceal rule doesn't properly conceal the image tag according to the rule:

enter image description here

12
  • 1
    For the cursor problem, have you checked the conceallevel and concealcursor options? It would help to have a full example to understand the problem.
    – D. Ben Knoble
    Commented Jun 22 at 14:06
  • I have added additional info, pls say if you need more info.
    – Tom
    Commented Jun 22 at 16:43
  • To be able to test the proposed solution it would be good to have the input text and the desired display text (preferably not in an image but in real text to not have to retype it:-) ) Commented Jun 22 at 17:53
  • More info added. I found this post from 2010 which says: > Unfortunately, currently there is no way to eliminate this void created by the conceal feature; apparently the development of the conceal feature was very complicated and involved some compromises to get it "out the door" in time for the 7.3 release. > This may be fixed in a future release if someone submits a working patch to Bram Moolenaar and/or the Vim developers mailing list.
    – Tom
    Commented Jun 23 at 3:09
  • Could you share the version of Vim you are using? I have test on Vim 9.1 and it seems to work fine. Commented Jun 23 at 15:41

1 Answer 1

1

There are some weakness in the Vim solution about conceal.

For your solution to work here are the two settings you need to change:

" Vim 9.1 doesn't conceal multiple wrapped lines
set nowrap

" Vim highlighting (including conceal) consider only
" the first part of the line (the first `&synmaxcol` characters)
set synmaxcol=3000
1
  • 1
    OK, so I'm learning something, viz. synmaxcol. If I set nowrap and synmaxcol=10000 I can hide the entire line of the <img … tag (if the line is less than 10000 chars). However, every line of my file is now effectively 'concealed' (though not with syntax rule) inasmuch I cannot scan more of a line that extends beyond the width of the window. This is not an improvement when much of my file is paragraphs of text. I'm thinking at this stage I'm going to have to live without syntax conceal feature for this particular application.
    – Tom
    Commented Jun 26 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.