public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Need help writing a LUA filter: merge all Para from a Div to a single Para.Str
@ 2019-08-10 14:31 Dmitriy Krasilnikov
       [not found] ` <15c2e38f-139c-41a6-932a-3ca06263781d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Krasilnikov @ 2019-08-10 14:31 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1953 bytes --]

Greetings!

I'm trying to convert RST admonitions to one-liner strings.

Here's the JSON output for a «Note» admonition:
{
  "t": "Div",
  "c": [
    [
      "",
      [
        "note"
      ],
      []
    ],
    [
      {
        "t": "Div",
        "c": [
          [
            "",
            [
              "admonition-title"
            ],
            []
          ],
          [
            {
              "t": "Para",
              "c": [
                {
                  "t": "Strong",
                  "c": [
                    {
                      "t": "Str",
                      "c": "Note"
                    }
                  ]
                }
              ]
            }
          ]
        ]
      },
      {
        "t": "Para",
        "c": [
          {
            "t": "Str",
            "c": "Причина"
          },
          {
            "t": "Space"
          },
          {
            "t": "Str",
            "c": "необходимости"
          },
          {
            "t": "Space"
          },
          {
            "t": "Str",
            "c": "закрепления"
          },
          {
            "t": "Space"
          },
          {
            "t": "Str",
            "c": "понятия?"
          }
        ]
      }
    ]
  ]
}

How can I convert this top-level Div to a string like: Note: <text from the 
next Para>? I'm new to LUA, been googling all day but no hints.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/15c2e38f-139c-41a6-932a-3ca06263781d%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 17209 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Need help writing a LUA filter: merge all Para from a Div to a single Para.Str
       [not found] ` <15c2e38f-139c-41a6-932a-3ca06263781d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-08-10 16:46   ` Albert Krewinkel
       [not found]     ` <871rxtq87v.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Albert Krewinkel @ 2019-08-10 16:46 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Dmitriy Krasilnikov writes:

> Greetings!
>
> I'm trying to convert RST admonitions to one-liner strings.
>
> Here's the JSON output for a «Note» admonition:
>
> [...]
>
> How can I convert this top-level Div to a string like: Note: <text
> from the next Para>?

Here's a filter which should serve as a solid starting point. See the
docs at https://pandoc.org/lua-filters.html for explanations of what the
functions do.

    function Div (div)
      if div.classes[1] == 'note' then
        local sep = {pandoc.Str':', pandoc.Space()}
        local inlines = pandoc.utils.blocks_to_inlines(div.content, sep)
        return pandoc.Para(inlines)
      end
    end

Does that help?

Cheers,
Albert

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/871rxtq87v.fsf%40zeitkraut.de.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Need help writing a LUA filter: merge all Para from a Div to a single Para.Str
       [not found]     ` <871rxtq87v.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2019-08-11 10:30       ` Dmitriy Krasilnikov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitriy Krasilnikov @ 2019-08-11 10:30 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2189 bytes --]

Yes, very helpful. Now I see there's a special function to convert block to 
inlines, missed it somehow.

For future reference of newbies like myself, here's what I've done to 
replace "Note" to something else before squashing Div's to one Para:

function Div (div)
    if div.classes[1] == 'note' then





*        div = pandoc.walk_block(div, {                Para = 
function(element)                    if element.content[1].text == "Note" 
then                        return pandoc.Para { pandoc.Emph(pandoc.Str 
'Примечание') }                    end                end })*
        local sep = {pandoc.Str':', pandoc.Space() }
        local inlines = pandoc.utils.blocks_to_inlines(div.content, sep)
        return pandoc.Para(inlines) -- pandoc.Str('') to drop the notes 
completely
    end
end



суббота, 10 августа 2019 г., 19:46:51 UTC+3 пользователь Albert Krewinkel 
написал:
>
>
> Dmitriy Krasilnikov writes: 
>
> > Greetings! 
> > 
> > I'm trying to convert RST admonitions to one-liner strings. 
> > 
> > Here's the JSON output for a «Note» admonition: 
> > 
> > [...] 
> > 
> > How can I convert this top-level Div to a string like: Note: <text 
> > from the next Para>? 
>
> Here's a filter which should serve as a solid starting point. See the 
> docs at https://pandoc.org/lua-filters.html for explanations of what the 
> functions do. 
>
>     function Div (div) 
>       if div.classes[1] == 'note' then 
>         local sep = {pandoc.Str':', pandoc.Space()} 
>         local inlines = pandoc.utils.blocks_to_inlines(div.content, sep) 
>         return pandoc.Para(inlines) 
>       end 
>     end 
>
> Does that help? 
>
> Cheers, 
> Albert 
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e5cdeaaf-66e0-484f-95eb-657da316f6f3%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 11793 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-11 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-10 14:31 Need help writing a LUA filter: merge all Para from a Div to a single Para.Str Dmitriy Krasilnikov
     [not found] ` <15c2e38f-139c-41a6-932a-3ca06263781d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-10 16:46   ` Albert Krewinkel
     [not found]     ` <871rxtq87v.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-08-11 10:30       ` Dmitriy Krasilnikov

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).