Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

fenced code block not syntax highlighted in marked down #37

Open
laoshaw opened this issue Jun 2, 2021 · 21 comments
Open

fenced code block not syntax highlighted in marked down #37

laoshaw opened this issue Jun 2, 2021 · 21 comments

Comments

@laoshaw
Copy link

laoshaw commented Jun 2, 2021

I have ```cpp ``` for c++, and c for c, and python for python etc, i.e. the 'standard' markdown code block, however they're either displayed as a single color, or the code just disappears, the code block in markdown does not work for me on ubuntu 20.04 vim8.

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

@laoshaw thanks for reporting!

I was looking into other issues and can confirm that code block are not syntax highlighted.

Please provide a md snippet which contains an example in which the code is not displayed at all.

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

Note so self:
maybe related to this: 6d87e54

@laoshaw
Copy link
Author

laoshaw commented Jun 2, 2021

A markdown snippet:

## hello world for c++

```cpp 
#include <iostream>
int main(){ std::cout << "hello world" << std::endl;
```

## hello world for c

```c
#include <stdio.h>
int main(void) { printf("hello world\n");} 
```

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

Haha, the #include is interpreted as a heading and creates a new slide :)
The snippet you posted creates 4 slides, not 2 as one would expect.
Fixing the separator is easy, but I have to investigate the syntax hl issue

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

@laoshaw just to have a semi working version this would be the regex for the slid separator:

# ftplugin/markdown.vim
let b:presenting_slide_separator_default = '\v(^|\n)\ze#{1,2} '

You should be able to overwrite the separator like this:
https://github.com/sotte/presenting.vim#configuration

@laoshaw
Copy link
Author

laoshaw commented Jun 2, 2021

Thanks. That fixed the header issue. Hope syntax can be highlighted somehow.

A screenshot of one slide is attached, there are two bars not sure if it's be design. plus the two lines for code block, e.g.

```c
```

ideally should not be visible.

x

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

The bars are there on purpose, fencing off the code

ideally should not be visible.

That is/should be the case if it works.

@laoshaw
Copy link
Author

laoshaw commented Jun 2, 2021

If code can be highlighted they will stand out visibly enough without the two bars I feel. It would be nice to make the two bars optional as they're a bit heavy visually when I have say two or three small snippets of code on one slide(that will be 6 bars then)

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

Yeah, design is subjective :) Initially presenting did not do any formatting, it just used the existing hl.

If you want a super lightweight version of presenting you can use an old version which does not use figlet, but does proper syntax hl:

git checkout 9fb8ccc

Then "fix" the slide sep:

au FileType markdown let s:presenting_slide_separator = '\v(^|\n)\ze#+ '

image

This version would respect your md conceal for your code blocks. I assume you use plasticboy/vim-markdown
https://github.com/plasticboy/vim-markdown#fenced-code-block-languages

@laoshaw
Copy link
Author

laoshaw commented Jun 2, 2021

git checkout 9fb8ccc will give me blank slides with only title shown, the code blocks are totally gone if I use au FileType markdown let s:presenting_slide_separator_default = '\v(^|\n)\ze#+ ', use au FileType markdown let s:presenting_slide_separator = '\v(^|\n)\ze#+ ' it works fine now. Thanks!

@sotte
Copy link
Owner

sotte commented Jun 2, 2021

Glad it kinda works ™️ should be a smoother experience though! I'll try to fix this soon.

Out of curiosity: do you use the figlet feature? @laoshaw

@laoshaw
Copy link
Author

laoshaw commented Jun 3, 2021

I could not use figlet as I got "error: could not load font small" for all headings on each slide.

fixed it: I did not install figlet, now it works but long headline does not look good with the figlet headers, would love just to use a bold font instead, but I like the list using figlet dots

@laoshaw
Copy link
Author

laoshaw commented Jun 3, 2021

also when using 'figlet' I found for lists only the first level are figlet-ed, the second level of the list are still using whatever is from markdown, be it * or -

@sotte
Copy link
Owner

sotte commented Jun 4, 2021

Related to #34

@gorrioncillo
Copy link

gorrioncillo commented Jun 12, 2021

this same occurred on python

#Comment
def hola():
  print('Hola mundo')

hola()

This make the slide divided into 2. The fixes here do not work.
I use vimwiki plugin too, so the markdown files seems to appear as vimwiki type. do you think this the cause?

@jbargu
Copy link

jbargu commented Jul 23, 2021

I had the same issue and fixed it with:

  1. rm -rf vim-plug.
  2. Remove tpope/vim-markdown from the list of plugins.
  3. Set let g:vimwiki_global_ext = 0 for vimwiki to avoid ft=vimwiki on *.md files.

The crucial step seems to be removing the vim-plug dir.

@kavinvalli
Copy link

kavinvalli commented Nov 29, 2021

I am still facing this issue @sotte
Screenshot 2021-11-29 at 6 03 19 PM

@normen
Copy link

normen commented Dec 27, 2021

For me it works. I have no markdown plugin installed - tpopes plugin is integrated in VIM. I do have to add the highlight types to my vimrc though, like below. Those then also work in vimwiki though, which is a double-win.

let g:markdown_fenced_languages = ['go','perl','sh', 'python', 'cpp', 'c', 'javascript', 'vim']

@sotte
Copy link
Owner

sotte commented Jan 3, 2022

My workaround is also not using any markdown plugin :) I should mention that in the README.

@rattletat
Copy link

rattletat commented Nov 9, 2022

For me, the vim-polyglot plugin caused my code cells to be not highlighted.

@VictorTaelin
Copy link

VictorTaelin commented Nov 22, 2023

I managed to solve the issue here by commenting the lines that ident the code block to the right. Seems like doing so will cause my markdown highlighter to fail to detect the block as a code block. Can't work in a polished PR now, sorry, but here is a complete file:

https://gist.github.com/VictorTaelin/df15d860e1aca738794e6f4f67e17c48

Replace autoload/markdown.vim by it to solve the issue.

Using: https://github.com/tpope/vim-markdown

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants