public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: [ Q ] Lua-filter: "Dynamic linking not supported" error when loading certain lua module(s)
Date: Fri, 12 Jul 2019 12:36:21 +0200	[thread overview]
Message-ID: <CADAJKhDYBysaQv=ONc9roHxumJs5pE=4Ex_fe11GOrWPdMOc0A@mail.gmail.com> (raw)
In-Reply-To: <3922e409-02e2-4ba6-b172-20e3d5bf2d56-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4435 bytes --]

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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/3922e409-02e2-4ba6-b172-20e3d5bf2d56%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/3922e409-02e2-4ba6-b172-20e3d5bf2d56%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.

[-- Attachment #2: Type: text/html, Size: 7092 bytes --]

      parent reply	other threads:[~2019-07-12 10:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08 12:44 K4zuki
     [not found] ` <4337b7eb-3ed7-4a70-a9f5-ecccc625c7d8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-08 13:14   ` BP Jonsson
     [not found]     ` <CAFC_yuSiX5iPeh69vpy4bB9ZSYPB+BHtZEMJCykHMqgLyRMWJw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-07-08 18:41       ` K4zuki
     [not found]         ` <3922e409-02e2-4ba6-b172-20e3d5bf2d56-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-12 10:36           ` BPJ [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADAJKhDYBysaQv=ONc9roHxumJs5pE=4Ex_fe11GOrWPdMOc0A@mail.gmail.com' \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).