sotte / presenting.vim

A simple tool for presenting slides in vim based on text files.
MIT License
300 stars 50 forks source link

fenced code block not syntax highlighted in marked down #37

Open laoshaw opened 3 years ago

laoshaw commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

Note so self: maybe related to this: https://github.com/sotte/presenting.vim/commit/6d87e549fb0bd00db908f501c7b4bff7436daa05

laoshaw commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

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

laoshaw commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Related to #34

gorrioncillo commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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

normen commented 2 years ago

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 commented 2 years ago

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

rattletat commented 1 year ago

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

VictorTaelin commented 9 months ago

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