jgm / lcmark

Flexible CommonMark converter
BSD 2-Clause "Simplified" License
55 stars 6 forks source link

convert() returns yaml as HTML and not metadata #1

Closed fuggla closed 8 years ago

fuggla commented 8 years ago

Hi,

I installed lcmark via luarocks and have been trying to convert markdown to html using lcmark.convert(). The function returns yaml data as html and not a table and I can't figure out why. I'm probably doing something wrong here... Any help would be appreciated!

Script (Lua 5.2.4)

local lcmark = require 'lcmark'
local inspect = require 'inspect'

file = io.open("test.md", "r")
markdown = file:read("*all")
file:close()

html, meta = lcmark.convert(markdown, "html")
print(html)
print(inspect(meta))

Output:

<hr />
<h2>author: yaml author</h2>
<h2>header</h2>
<p>text</p>

{}

test.md content:


---
author: yaml author

---

## header
text

It works as expected outside of lua:

lcmark -t html test.md
<h2>header</h2>
<p>text</p>
jgm commented 8 years ago

You've got to set the option yaml_metadata to true.

html, meta = lcmarkconvert(markdown, "html", {yaml_metadata = true})

I forgot to document this -- and have just added something to README.

Maybe it shouldn't even be an option, but it seems nice to have a mode where lcmark works just like cmark.

fuggla commented 8 years ago

I see. Thanks for your help.