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

Underlined headers not recognized in Markdown syntax #209

Closed
Bakudankun opened this issue May 19, 2016 · 6 comments
Closed

Underlined headers not recognized in Markdown syntax #209

Bakudankun opened this issue May 19, 2016 · 6 comments
Labels
enhancement markdown Problems specific to markdown syntax

Comments

@Bakudankun
Copy link

As referred in #101, following syntaxes (Setext-style headers) of Markdown are not recognized.

Header 1     <-- not highlighted
========     <-- not highlighted

Header 2     <-- not highlighted
--------     <-- higlighted

I prefer to use these because they are more conspicuous. Could it be supported?

@Nudin Nudin added enhancement markdown Problems specific to markdown syntax labels Dec 19, 2018
@Nudin
Copy link
Member

Nudin commented Apr 1, 2019

#273 might solve this but would ned to be revamped.

@ranebrown
Copy link
Contributor

Adding the syntax support is easy enough but it is more complicated to handle some of the other commands. At a minimum the commands would need to recognize and link to this style of header.

We would also need to consider another option to indicate how generated sections should be created. Should a mix of Setex style for H1, H2 be used and then ATX style for lower level headers? Or only support ATX style for generated commands?

Commands to consider (others?):

VimwikiTOC
VimwikiGenerateLinks
VimwikiGenerateTags
VimwikiDiaryGenerateLinks

Syntax support can be done with something like this:

syn match VimwikiSetexHeader /^.\+\n[=]\+$/
syn match VimwikiSetexHeader /^.\+\n[-]\+$/
hi def link VimwikiSetexHeader Title

@yaohunzhanyue
Copy link

@ranebrown Sorry to bother you again. I find that vim default syntax highlighting can recognize ==== type, combine to the lastest merge multi_filetype, if I set

let g:vimwiki_filetypes = ['markdown']

.md will be set to vimwiki.markdown, but this would not use vim' default syntax highlighting.

if I change that to

autocmd Filetype vimwiki set filetype=markdown.vimwiki

.md will be set to markdown.vimwiki, and ==== would be highlighted by vim default syntax hl. However, I can't use some of vimwiki's keymappings(etc. <Backspace> for jump back). Is there any chance I can make this right?

@ranebrown
Copy link
Contributor

Vimwiki doesn't know about the regex pattern used to highlight the setex header so there is no way it can jump back to a header defined by another plugin or syntax file.

@tinmarino
Copy link
Member

For highligting

From vim markdown.vim default syntax (Tim Pope) https://github.com/tpope/vim-markdown/blob/9ff8d52c78fb8a587224d7f4d877fc95c8e1bd5b/syntax/markdown.vim#L59-L62

syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink
syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink

syn match markdownHeadingRule "^[=-]\+$" contained

For search: /^\(.*\)$\n^[=-]\+$

tinmarino added a commit to tinmarino/vimwiki that referenced this issue Aug 4, 2020
tinmarino added a commit to tinmarino/vimwiki that referenced this issue Aug 4, 2020
tinmarino added a commit to tinmarino/vimwiki that referenced this issue Aug 4, 2020
@tinmarino
Copy link
Member

Fixed: fc056cf

Screenshot from 2020-08-04 01-16-34-vimwiki


PS (Only for devs): Some redundancy must be factorized but the non regression tests are made and green:

Example of redundancy:
syntax/vimwiki.vim

" SetExt header
" TODO mutualise SetExt Regexp
let setex_header1_re = '^\s\{0,3}[^>].*\n\s\{0,3}==\+$'
let setex_header2_re = '^\s\{0,3}[^>].*\n\s\{0,3}--\+$'
execute 'syntax match VimwikiHeader1'
    \ . ' /'. setex_header1_re . '/ '
    \ 'contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'.
    \ 'VimwikiLink,@Spell'
execute 'syntax match VimwikiHeader2'
    \ . ' /'. setex_header2_re . '/ ' .
    \ 'contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'.
    \ 'VimwikiLink,@Spell'

syntax/vimwiki_markdown.vim

" Header
" TODO mutualise with rxHeader in vars.vim := Define atx_regex only onces
" TODO regex_or function  => (1|2)
let atx_header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
let atx_header_match  = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'

let setex_header_search = '^\s\{0,3}\zs[^>].*\ze\n'
let setex_header_search .= '^\s\{0,3}[=-]\{2,}$'

let setex_header_match = '^\s\{0,3}>\@!__Header__\n'
let setex_header_match .= '^\s\{0,3}[=-][=-]\+$'

deepredsky pushed a commit to deepredsky/vimwiki that referenced this issue Jan 16, 2021
jls83 pushed a commit to jls83/vimwiki that referenced this issue Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement markdown Problems specific to markdown syntax
Projects
None yet
Development

No branches or pull requests

5 participants