public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Getting a Grip on Lua + Pandoc AST
@ 2019-08-07 14:42 Ken Dow
       [not found] ` <1a04d06d-51d4-4843-aaf9-1a39f7f4ded5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Ken Dow @ 2019-08-07 14:42 UTC (permalink / raw)
  To: pandoc-discuss


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

So I know nothing about Lua <https://www.lua.org/pil/contents.html> or how 
to read the documentation of any AST let alone the Pandoc AST 
<https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with a 
Lua filter. Hopefully someone throw me a few clues :-)

The AST content I'm targetting is this line:

,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str "HTML",
Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str "Do",Space
,Str "Not",Space,Str "Edit-Or-Remove"]

I've stumbled as far as the function below, which detects the heading level 
and changes the level and the id:

function Header(el)
  if el.level == 1 then
    el.level = 6
    el.attr.identifier = "Monkey-See"
    return el
  end
end

When I try to access the Str/inline part of `Header Int 
<https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
Attr 
<https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
[Inline 
<https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
however, I'm stumped. No errors but no changes applied 

function Header(el)
  if el.level == 1 then
    el.level = 6
    el.attr.identifier = "Monkey-See"
    el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with el.string or 
el.text either
    return el
  end
end

All of this is just the appetizer. The main course will be deleting this H1 
value and everything below it up to the next H1.

-- 
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/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com.

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

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

* Re: Getting a Grip on Lua + Pandoc AST
       [not found] ` <1a04d06d-51d4-4843-aaf9-1a39f7f4ded5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-08-07 15:45   ` Ken Dow
  2019-08-07 23:12   ` John MacFarlane
  1 sibling, 0 replies; 6+ messages in thread
From: Ken Dow @ 2019-08-07 15:45 UTC (permalink / raw)
  To: pandoc-discuss


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

Just found the MANUAL.txt example 
<https://pandoc.org/lua-filters.html#modifying-pandocs-manual.txt-for-man-pages> 
with the `pandoc.walk_block` call. Using that, I can loop over and 
manipulate each individual string in the Header:

function Header(el)
    if el.level == 1 then
     el.level = 6
     el.attr.identifier = "Monkey-See"
      return pandoc.walk_block(el, {
        Str = function(el)
            return pandoc.Str('Monkey Do')
        end })
    end
end

Which yields something like "1.0.0.0.0.1 Monkey Do Monkey Do Monkey Do 
Monkey Do Monkey Do Monkey Do Monkey Do". Getting warmer.

On Wednesday, 7 August 2019 10:42:00 UTC-4, Ken Dow wrote:
>
> So I know nothing about Lua <https://www.lua.org/pil/contents.html> or 
> how to read the documentation of any AST let alone the Pandoc AST 
> <https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
> yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with a 
> Lua filter. Hopefully someone throw me a few clues :-)
>
> The AST content I'm targetting is this line:
>
> ,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str "HTML",
> Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str "Do",
> Space,Str "Not",Space,Str "Edit-Or-Remove"]
>
> I've stumbled as far as the function below, which detects the heading 
> level and changes the level and the id:
>
> function Header(el)
>   if el.level == 1 then
>     el.level = 6
>     el.attr.identifier = "Monkey-See"
>     return el
>   end
> end
>
> When I try to access the Str/inline part of `Header Int 
> <https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
> Attr 
> <https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
> [Inline 
> <https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
> however, I'm stumped. No errors but no changes applied 
>
> function Header(el)
>   if el.level == 1 then
>     el.level = 6
>     el.attr.identifier = "Monkey-See"
>     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with el.string 
> or el.text either
>     return el
>   end
> end
>
> All of this is just the appetizer. The main course will be deleting this 
> H1 value and everything below it up to the next H1.
>

-- 
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/70bcc2b2-084f-4ab9-9348-4ea057586805%40googlegroups.com.

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

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

* Re: Getting a Grip on Lua + Pandoc AST
       [not found] ` <1a04d06d-51d4-4843-aaf9-1a39f7f4ded5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-08-07 15:45   ` Ken Dow
@ 2019-08-07 23:12   ` John MacFarlane
       [not found]     ` <yh480ky304tvrx.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  1 sibling, 1 reply; 6+ messages in thread
From: John MacFarlane @ 2019-08-07 23:12 UTC (permalink / raw)
  To: Ken Dow, pandoc-discuss


Try

   el.content = {pandoc.Str("Monkey"), pandoc.Space(), pandoc.Str("Do")}

See https://pandoc.org/lua-filters.html#type-ref-Header

and look at the examples on that page.

Ken Dow <thekenshow-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> So I know nothing about Lua <https://www.lua.org/pil/contents.html> or how 
> to read the documentation of any AST let alone the Pandoc AST 
> <https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
> yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with a 
> Lua filter. Hopefully someone throw me a few clues :-)
>
> The AST content I'm targetting is this line:
>
> ,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str "HTML",
> Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str "Do",Space
> ,Str "Not",Space,Str "Edit-Or-Remove"]
>
> I've stumbled as far as the function below, which detects the heading level 
> and changes the level and the id:
>
> function Header(el)
>   if el.level == 1 then
>     el.level = 6
>     el.attr.identifier = "Monkey-See"
>     return el
>   end
> end
>
> When I try to access the Str/inline part of `Header Int 
> <https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
> Attr 
> <https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
> [Inline 
> <https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
> however, I'm stumped. No errors but no changes applied 
>
> function Header(el)
>   if el.level == 1 then
>     el.level = 6
>     el.attr.identifier = "Monkey-See"
>     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with el.string or 
> el.text either
>     return el
>   end
> end
>
> All of this is just the appetizer. The main course will be deleting this H1 
> value and everything below it up to the next H1.
>
> -- 
> 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/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com.


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

* Re: Getting a Grip on Lua + Pandoc AST
       [not found]     ` <yh480ky304tvrx.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-08-08 13:28       ` Ken Dow
       [not found]         ` <e2fa7d68-9747-4b6b-80fa-b3970adc6d65-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Ken Dow @ 2019-08-08 13:28 UTC (permalink / raw)
  To: pandoc-discuss


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

Thanks! That worked, and that link is just exactly what I needed. 

BTW - in Firefox latest, the Pandoc Lua Filters page (which does have some 
validation errors 
<https://validator.w3.org/nu/?doc=https%3A%2F%2Fpandoc.org%2Flua-filters.html>) 
displays a large white space after the following text.

Here’s a quick performance comparison, using a version of the pandoc 
> manual, MANUAL.txt, and versions of the same filter written in compiled 
> Haskell (smallcaps) and interpreted Python (smallcaps.py):
>

So the page renders like this, with the rest of the content appears below 
the right-side ToC:


[image: Screen Shot 2019-08-08 at 9.15.22 AM.png]


On Wednesday, 7 August 2019 19:12:48 UTC-4, John MacFarlane wrote:
>
>
> Try 
>
>    el.content = {pandoc.Str("Monkey"), pandoc.Space(), pandoc.Str("Do")} 
>
> See https://pandoc.org/lua-filters.html#type-ref-Header 
>
> and look at the examples on that page. 
>
> Ken Dow <theke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes: 
>
> > So I know nothing about Lua <https://www.lua.org/pil/contents.html> or 
> how 
> > to read the documentation of any AST let alone the Pandoc AST 
> > <
> https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
>
> > yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with 
> a 
> > Lua filter. Hopefully someone throw me a few clues :-) 
> > 
> > The AST content I'm targetting is this line: 
> > 
> > ,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str 
> "HTML", 
> > Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str 
> "Do",Space 
> > ,Str "Not",Space,Str "Edit-Or-Remove"] 
> > 
> > I've stumbled as far as the function below, which detects the heading 
> level 
> > and changes the level and the id: 
> > 
> > function Header(el) 
> >   if el.level == 1 then 
> >     el.level = 6 
> >     el.attr.identifier = "Monkey-See" 
> >     return el 
> >   end 
> > end 
> > 
> > When I try to access the Str/inline part of `Header Int 
> > <
> https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
>
> > Attr 
> > <
> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
>
> > [Inline 
> > <
> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
>
> > however, I'm stumped. No errors but no changes applied 
> > 
> > function Header(el) 
> >   if el.level == 1 then 
> >     el.level = 6 
> >     el.attr.identifier = "Monkey-See" 
> >     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with 
> el.string or 
> > el.text either 
> >     return el 
> >   end 
> > end 
> > 
> > All of this is just the appetizer. The main course will be deleting this 
> H1 
> > value and everything below it up to the next H1. 
> > 
> > -- 
> > 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com. 
>
>

-- 
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/e2fa7d68-9747-4b6b-80fa-b3970adc6d65%40googlegroups.com.

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

[-- Attachment #2: Screen Shot 2019-08-08 at 9.15.22 AM.png --]
[-- Type: image/png, Size: 35265 bytes --]

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

* Re: Getting a Grip on Lua + Pandoc AST
       [not found]         ` <e2fa7d68-9747-4b6b-80fa-b3970adc6d65-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-08-08 17:31           ` Ken Dow
  2019-08-08 18:30           ` John MacFarlane
  1 sibling, 0 replies; 6+ messages in thread
From: Ken Dow @ 2019-08-08 17:31 UTC (permalink / raw)
  To: pandoc-discuss


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

Great progress! I'm able to remove front and back matter from the DOCX 
output using hidden Heading 1 elements inserted in the Word source. Here's 
the filter:

-- 
-- Strip out the front and back matter based on specific hidden Heading 1 
elements
--
function Pandoc(doc)
    local outblocks = {}
    local startoutput = false
    local endoutput = false
    for i,el in pairs(doc.blocks) do
      if (el.t == "Header" and el.attr.identifier == 
"html-front-wrapper-do-not-edit-or-remove") then
       startoutput = true
      end
      if (el.t == "Header" and el.attr.identifier == 
"html-back-wrapper-do-not-edit-or-remove") then
       endoutput = true
      end
      repeat
        if (startoutput == false or endoutput == true) then
          do break end
        end
        if (el.t == "Header" and el.attr.identifier == 
"html-front-wrapper-do-not-edit-or-remove") then
          do break end
        else
          table.insert(outblocks, el)
        end
       until true
     end
   return pandoc.Pandoc(outblocks, doc.meta)
end

Next, I'd like to rewrite the image attributes with a separate filter. I 
tried each of the following - no errors, but neither had any effect:

--
-- Rewrite image element data to remove height/width and add "image" class
--
function Image(el)
    el.attr.style = ""
    el.attr.class = "image"
    return el
end

--
-- Rewrite image element data to remove height/width and add "image" class
--
function Para(el)
    if (#el.c == 1 and el.c[1].t == "Image") then
      el.c[1].attr.style = ""
      el.c[1].attr.class = "image"
    end
    return el
end



On Thursday, 8 August 2019 09:28:19 UTC-4, Ken Dow wrote:
Thanks! That worked, and that link is just exactly what I needed. 

BTW - in Firefox latest, the Pandoc Lua Filters page (which does have some 
validation errors 
<https://validator.w3.org/nu/?doc=https%3A%2F%2Fpandoc.org%2Flua-filters.html>) 
displays a large white space after the following text.

Here’s a quick performance comparison, using a version of the pandoc 
> manual, MANUAL.txt, and versions of the same filter written in compiled 
> Haskell (smallcaps) and interpreted Python (smallcaps.py):


So the page renders like this, with the rest of the content appears below 
the right-side ToC:


[image: Screen Shot 2019-08-08 at 9.15.22 AM.png]


On Wednesday, 7 August 2019 19:12:48 UTC-4, John MacFarlane wrote: 
Try 

   el.content = {pandoc.Str("Monkey"), pandoc.Space(), pandoc.Str("Do")} 

See https://pandoc.org/lua-filters.html#type-ref-Header 

and look at the examples on that page. 

Ken Dow <theke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: 

> So I know nothing about Lua <https://www.lua.org/pil/contents.html> or 
how 
> to read the documentation of any AST let alone the Pandoc AST 
> <
https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 

> yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with a 
> Lua filter. Hopefully someone throw me a few clues :-) 
> 
> The AST content I'm targetting is this line: 
> 
> ,Header 1 ("html-front-wrapper-do-not-
>
> edit-or-remove",[],[]) [Str "HTML", 
> > Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str 
> "Do",Space 
> > ,Str "Not",Space,Str "Edit-Or-Remove"] 
> > 
> > I've stumbled as far as the function below, which detects the heading 
> level 
> > and changes the level and the id: 
> > 
> > function Header(el) 
> >   if el.level == 1 then 
> >     el.level = 6 
> >     el.attr.identifier = "Monkey-See" 
> >     return el 
> >   end 
> > end 
> > 
> > When I try to access the Str/inline part of `Header Int 
> > <
> https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
>
> > Attr 
> > <
> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
>
> > [Inline 
> > <
> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
>
> > however, I'm stumped. No errors but no changes applied 
> > 
> > function Header(el) 
> >   if el.level == 1 then 
> >     el.level = 6 
> >     el.attr.identifier = "Monkey-See" 
> >     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with 
> el.string or 
> > el.text either 
> >     return el 
> >   end 
> > end 
> > 
> > All of this is just the appetizer. The main course will be deleting this 
> H1 
> > value and everything below it up to the next H1. 
> > 
> > -- 
> > 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-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com. 
>



On Thursday, 8 August 2019 09:28:19 UTC-4, Ken Dow wrote:
>
> Thanks! That worked, and that link is just exactly what I needed. 
>
> BTW - in Firefox latest, the Pandoc Lua Filters page (which does have 
> some validation errors 
> <https://validator.w3.org/nu/?doc=https%3A%2F%2Fpandoc.org%2Flua-filters.html>) 
> displays a large white space after the following text.
>
> Here’s a quick performance comparison, using a version of the pandoc 
>> manual, MANUAL.txt, and versions of the same filter written in compiled 
>> Haskell (smallcaps) and interpreted Python (smallcaps.py):
>
>
> So the page renders like this, with the rest of the content appears below 
> the right-side ToC:
>
>
> [image: Screen Shot 2019-08-08 at 9.15.22 AM.png]
>
>
> On Wednesday, 7 August 2019 19:12:48 UTC-4, John MacFarlane wrote:
>>
>>
>> Try 
>>
>>    el.content = {pandoc.Str("Monkey"), pandoc.Space(), pandoc.Str("Do")} 
>>
>> See https://pandoc.org/lua-filters.html#type-ref-Header 
>>
>> and look at the examples on that page. 
>>
>> Ken Dow <theke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: 
>>
>> > So I know nothing about Lua <https://www.lua.org/pil/contents.html> or 
>> how 
>> > to read the documentation of any AST let alone the Pandoc AST 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
>>
>> > yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with 
>> a 
>> > Lua filter. Hopefully someone throw me a few clues :-) 
>> > 
>> > The AST content I'm targetting is this line: 
>> > 
>> > ,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str 
>> "HTML", 
>> > Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str 
>> "Do",Space 
>> > ,Str "Not",Space,Str "Edit-Or-Remove"] 
>> > 
>> > I've stumbled as far as the function below, which detects the heading 
>> level 
>> > and changes the level and the id: 
>> > 
>> > function Header(el) 
>> >   if el.level == 1 then 
>> >     el.level = 6 
>> >     el.attr.identifier = "Monkey-See" 
>> >     return el 
>> >   end 
>> > end 
>> > 
>> > When I try to access the Str/inline part of `Header Int 
>> > <
>> https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
>>
>> > Attr 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
>>
>> > [Inline 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
>>
>> > however, I'm stumped. No errors but no changes applied 
>> > 
>> > function Header(el) 
>> >   if el.level == 1 then 
>> >     el.level = 6 
>> >     el.attr.identifier = "Monkey-See" 
>> >     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with 
>> el.string or 
>> > el.text either 
>> >     return el 
>> >   end 
>> > end 
>> > 
>> > All of this is just the appetizer. The main course will be deleting 
>> this H1 
>> > value and everything below it up to the next H1. 
>> > 
>> > -- 
>> > 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-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com
>> . 
>
>

-- 
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/067c8e50-ff56-4bc5-b488-267adbd41b79%40googlegroups.com.

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

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

* Re: Getting a Grip on Lua + Pandoc AST
       [not found]         ` <e2fa7d68-9747-4b6b-80fa-b3970adc6d65-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-08-08 17:31           ` Ken Dow
@ 2019-08-08 18:30           ` John MacFarlane
  1 sibling, 0 replies; 6+ messages in thread
From: John MacFarlane @ 2019-08-08 18:30 UTC (permalink / raw)
  To: Ken Dow, pandoc-discuss


Thanks for alerting me to those issues -- I think I've now
fixed them.

Ken Dow <thekenshow-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Thanks! That worked, and that link is just exactly what I needed. 
>
> BTW - in Firefox latest, the Pandoc Lua Filters page (which does have some 
> validation errors 
> <https://validator.w3.org/nu/?doc=https%3A%2F%2Fpandoc.org%2Flua-filters.html>) 
> displays a large white space after the following text.
>
> Here’s a quick performance comparison, using a version of the pandoc 
>> manual, MANUAL.txt, and versions of the same filter written in compiled 
>> Haskell (smallcaps) and interpreted Python (smallcaps.py):
>>
>
> So the page renders like this, with the rest of the content appears below 
> the right-side ToC:
>
>
> [image: Screen Shot 2019-08-08 at 9.15.22 AM.png]
>
>
> On Wednesday, 7 August 2019 19:12:48 UTC-4, John MacFarlane wrote:
>>
>>
>> Try 
>>
>>    el.content = {pandoc.Str("Monkey"), pandoc.Space(), pandoc.Str("Do")} 
>>
>> See https://pandoc.org/lua-filters.html#type-ref-Header 
>>
>> and look at the examples on that page. 
>>
>> Ken Dow <theke...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes: 
>>
>> > So I know nothing about Lua <https://www.lua.org/pil/contents.html> or 
>> how 
>> > to read the documentation of any AST let alone the Pandoc AST 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.19/docs/Text-Pandoc-Definition.html>, 
>>
>> > yet here I am trying to manipulate my Pandoc DOCX->HTML conversion with 
>> a 
>> > Lua filter. Hopefully someone throw me a few clues :-) 
>> > 
>> > The AST content I'm targetting is this line: 
>> > 
>> > ,Header 1 ("html-front-wrapper-do-not-edit-or-remove",[],[]) [Str 
>> "HTML", 
>> > Space,Str "Front",Space,Str "Wrapper",Space,Str "\8211",Space,Str 
>> "Do",Space 
>> > ,Str "Not",Space,Str "Edit-Or-Remove"] 
>> > 
>> > I've stumbled as far as the function below, which detects the heading 
>> level 
>> > and changes the level and the id: 
>> > 
>> > function Header(el) 
>> >   if el.level == 1 then 
>> >     el.level = 6 
>> >     el.attr.identifier = "Monkey-See" 
>> >     return el 
>> >   end 
>> > end 
>> > 
>> > When I try to access the Str/inline part of `Header Int 
>> > <
>> https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Int.html#t:Int> 
>>
>> > Attr 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Attr> 
>>
>> > [Inline 
>> > <
>> https://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Inline>]`, 
>>
>> > however, I'm stumped. No errors but no changes applied 
>> > 
>> > function Header(el) 
>> >   if el.level == 1 then 
>> >     el.level = 6 
>> >     el.attr.identifier = "Monkey-See" 
>> >     el.inline = '[Str "Monkey",Space,Str "Do"]' -- no luck with 
>> el.string or 
>> > el.text either 
>> >     return el 
>> >   end 
>> > end 
>> > 
>> > All of this is just the appetizer. The main course will be deleting this 
>> H1 
>> > value and everything below it up to the next H1. 
>> > 
>> > -- 
>> > 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/1a04d06d-51d4-4843-aaf9-1a39f7f4ded5%40googlegroups.com. 
>>
>>
>
> -- 
> 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/e2fa7d68-9747-4b6b-80fa-b3970adc6d65%40googlegroups.com.

-- 
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/yh480kblwztspp.fsf%40johnmacfarlane.net.


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07 14:42 Getting a Grip on Lua + Pandoc AST Ken Dow
     [not found] ` <1a04d06d-51d4-4843-aaf9-1a39f7f4ded5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-07 15:45   ` Ken Dow
2019-08-07 23:12   ` John MacFarlane
     [not found]     ` <yh480ky304tvrx.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-08-08 13:28       ` Ken Dow
     [not found]         ` <e2fa7d68-9747-4b6b-80fa-b3970adc6d65-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-08 17:31           ` Ken Dow
2019-08-08 18:30           ` John MacFarlane

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