yoshuawuyts / vmd

:pray: preview markdown files
MIT License
1.18k stars 111 forks source link

Ignore front-matter #109

Closed pavloo closed 6 years ago

pavloo commented 6 years ago

Currently vmd tries to parse front-matter as it's a valid markdown. This PR adds a feature of ignoring front-matter. By default it's configured to ignore yaml front-matter, but there is an option to set the list of ignored formats.

maxkueng commented 6 years ago

I just did some checking. GitHub actually doesn't strip front-matter but renders it as a nested table. But only if YAML syntax is used. If the front-matter is TOML or JSON style it just renders it like regular text.

vmd should behave the same, if possible. We can strip it (i.e. not render it) and also add support for TOML and JSON but those behaviors should be turned off by default and can be enabled through config parameters / command-line arguments.

I tried some front-matter that I copied from the hugo docs.

YAML:

---
title: "spf13-vim 3.0 release and new website"
description: "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
tags: [ ".vimrc", "plugins", "spf13-vim", "vim" ]
lastmod: 2015-12-23
date: "2012-04-06"
categories:
  - "Development"
  - "VIM"
slug: "spf13-vim-3-0-release-and-new-website"
---

sdasdasd

Is rendered like this:

image

TOML-syntax front-matter is just rendered as text:

+++
title = "spf13-vim 3.0 release and new website"
description = "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
tags = [ ".vimrc", "plugins", "spf13-vim", "vim" ]
date = "2012-04-06"
categories = [
  "Development",
  "VIM"
]
slug = "spf13-vim-3-0-release-and-new-website"
+++

sdasdasd

Looks like this:

image

Same with JSON-syntax front-matter:

{
    "title": "spf13-vim 3.0 release and new website",
    "description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim.",
    "tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ],
    "date": "2012-04-06",
    "categories": [
        "Development",
        "VIM"
    ],
    "slug": "spf13-vim-3-0-release-and-new-website"
}

sdasdasd

Looks like this:

image

Invalid YAML front-matter is rendered like this:

image

maxkueng commented 6 years ago

I've created a new issue based on my comment.

maxkueng commented 6 years ago

@pavloo : I'm not sure if you got the notification emails as it happened in a different issue. But I made a couple changes to the Front Matter behavior in PR #112:

pavloo commented 6 years ago

@maxkueng Sorry was on vacation. Looks nice. Thanks!