Do you know that you can use Pandoc itself as a YAML parser?

https://pandoc.org/lua-filters.html#default-metadata-file

Some things to look out for:

-   Pandoc parses YAML scalar values (but not keys) as Pandoc markdown and returns a tree of objects. To get a "plain" data structure out of that you have to run the `meta` part of the Pandoc object through a function along the lines of

    ````lua
    local function meta2data (x)
      if 'table' == type(x) then
        local t = x.t -- tag == element type
        if not t or 'MetaMap' == t or 'MetaList' == t then
          -- turn into a plain data table
          local d = {}
          for k,v in pairs(x) do
            d[k] = meta2data(v) -- call recursively
          end
          return d
        elseif t then
          -- probably text, so stringify it
          return pandoc.utils.stringify(x)
        end
      else
        -- something else, probably a string or boolean
        return x
      end
    end
    
    local data = meta2data(doc.meta)
    -- or less expensively:
    local some_data = meta2data(doc.meta.some_field)
    ````
    
    NOTE: I'm "quoting" the meta2data function from brain memory so some detail covering some edge case may be missing, but it's the general idea.

-   The restringification of the MetaBlocks and MetaInlines elements (or rather their contents) removes everything which Pandoc considers formatting, so you, or your users, have to wrap any literal strings in the YAML where whitespace and/or punctuation is important in Pandoc code elements, and these need in turn to be wrapped in YAML quoted strings since YAML reserves the backtick for future use as a metacharacter:

    ````````yaml
    foo: '`2**10`'
    bar: |
      ````
      No Markdown parsing here
      ````
    ````````

-   If you read in YAML from a file you have to make sure that it starts and ends with appropriate YAML block delimiters so that Pandoc recognises it as "metadata"

    ````lua
    if not yaml:match('^%-%-%-%f[^%-]') then
      yaml = "---\n" .. yaml
    end
    if not yaml:match('\n([%.%-])%1%1%s*$') then
      yaml = yaml .. "\n...\n"
    end
    ````
    
This looks complicated but the first two points are generally what you have to do/observe anyway if you configure your filter through metadata, and having Pandoc parse the YAML using Haskell is probably still more efficient and robust than using a pure Lua YAML parser. (I've taken a stab at reimplementing [YAML::Tiny](https://metacpan.org/pod/YAML::Tiny) in Lua and it isn't easy!)

Den mån 8 juli 2019 20:41K4zuki <k.yamamoto.08136891-Re5JQEeQqe8@public.gmane.orgm> skrev:
You seem to be totally right: C-based libraries are not supported by static-built pandoc binaries(e.g. deb file)
I agree that setting LUA_PATH/LUA_CPATH is also preferred.

I will use lua-yaml instead of lyaml package. lfs cannot be used in this case but as penlight package requires it, I will leave it installed(and unused).

Thanks for the advice.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm.
To post to this group, send email to pandoc-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/3922e409-02e2-4ba6-b172-20e3d5bf2d56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDYBysaQv%3DONc9roHxumJs5pE%3D4Ex_fe11GOrWPdMOc0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.