tpope / vim-liquid

Vim Liquid runtime files with Jekyll enhancements
126 stars 25 forks source link

Incorrectly detects pandoc markdown files as liquid #18

Open dylan-chong opened 5 years ago

dylan-chong commented 5 years ago

Markdown files for use with pandoc can start with a YAML header, which starts with ---. This causes this plugin to think that the filetype is liquid.

Example document:

---
title: ENGR401 Assignment 1
author:
    - Dylan
date: \today{}
toc: false
---

# Introduction

Content

See line https://github.com/tpope/vim-liquid/blob/master/ftdetect/liquid.vim#L7

nickjj commented 5 years ago

This is also an issue if you use Jekyll since files start with the same type of front matter (triple dashes with some properties inside of them) but the file names themselves end with .md.

This is primarily an issue for me because:

  1. None of the markdown snippets work since the filetype is liquid.

  2. I want to add a few custom vim-snippets that are specific to markdown but in order to get them to work I have to put them in a liquid snippets file. Technically this works but it's a little confusing since now a liquid snippet file has markdown snippets.

tpope commented 5 years ago

Jekyll does use Liquid; it's the reason I added this behavior to begin with. Setting the filetype to liquid.markdown might address your use case. As for pandoc, I don't know, maybe we limit this special case to _posts/?

nickjj commented 5 years ago

Could this be done at the plugin level for Jekyll / Liquid? I wouldn't want to have to manually set the file type every time I open a Jekyll based blog post but at the same time I wouldn't want regular md files to be liquid.markdown either.

tpope commented 5 years ago

If you're saying it should live in a separate Jekyll plugin, then yes, ideally, but that in and of itself doesn't answer the question of how to distinguish between Jekyll, Pandoc, and other Markdown files with Yaml frontmatter.

nickjj commented 5 years ago

Setting the file type to liquid.markdown breaks syntax highlighting for the whole file.

What would the process look like to get this to work? I thought it could be done in this plugin because you already have most of the logic in place.

For example, you have:

au BufNewFile,BufRead *.markdown,*.mkd,*.mkdn,*.md
      \ if getline(1) == '---' |
      \   let b:liquid_subtype = 'markdown' |
      \   set ft=liquid |
      \ endif

But the subtype doesn't fully set the ft to markdown because snippets still think it's a liquid file, even though it's markdown.

tpope commented 5 years ago

:set filetype=liquid.markdown looks fine to me. Do you have a Markdown plugin installed or are you using the built-in default?

nickjj commented 5 years ago

I am using this plugin: https://github.com/plasticboy/vim-markdown