public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Understanding new style writer
@ 2022-02-15 19:06 Günter Dannoritzer
       [not found] ` <12d035a5-f3c1-475a-9ae5-db014361514an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Günter Dannoritzer @ 2022-02-15 19:06 UTC (permalink / raw)
  To: pandoc-discuss


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

Hello,

in the pandoc manual it shows under custom-writers how to create a writer.

If I understand it right, this is the part that creates the output specific 
code. So there should be a writer for each desired output format?

How do I specify in a new style writer, that the writer should only process 
docx for example?

How is a writer separated from a filter? If I understand it correct, the 
filter works on the abstract syntax notation, however, there are examples 
in the pandoc manual under lua filter, where raw output like latex is 
inserted into the ast with a filter.

How would I change this writer from the manual, to only process docx images?

function Writer (doc, opts) 
   local filter = { 
      CodeBlock = function (cb) 
         -- only modify if code block has no attributes
         if cb.attr == pandoc.Attr() then
            local delimited = '```\n' .. cb.text .. '\n```' 
            return pandoc.RawBlock('markdown', delimited) 
         end
      end
   }
   return pandoc.write(doc:walk(filter), 'gfm', opts)
end 

Thanks for your help.

Regards,
Günter

-- 
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/12d035a5-f3c1-475a-9ae5-db014361514an%40googlegroups.com.

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

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

* Re: Understanding new style writer
       [not found] ` <12d035a5-f3c1-475a-9ae5-db014361514an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-15 19:44   ` Albert Krewinkel
       [not found]     ` <87wnhvg9zo.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Albert Krewinkel @ 2022-02-15 19:44 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi Günter,

Günter Dannoritzer <dannoritzer-S0/GAf8tV78@public.gmane.org> writes:

> in the pandoc manual it shows under custom-writers how to create a
> writer.

This feature has not been released yet, and should probably not be
mentioned on the website. You can already test it by using one of the
nightly builds.

> If I understand it right, this is the part that creates the output
> specific code. So there should be a writer for each desired output
> format?

The key to filters and custom writers is to understand how pandoc works:
When converting a document, the input is first read and parsed into
pandoc's internal document representation, the abstract syntax tree
(AST). The AST is completely format independent and can be modified via
filters. A "writer" takes the AST and converts it into the desired
output format.

Custom writers should be used whenever the desired output format is not
supported by pandoc, or when the desired format differs too much from
what pandoc produces by default.

> How is a writer separated from a filter? If I understand it correct,
> the filter works on the abstract syntax notation, however, there are
> examples in the pandoc manual under lua filter, where raw output like
> latex is inserted into the ast with a filter.

I sympathize, the distinction is not always clear. They *can* be used
for similar things, and filters can even be specified and used within a
writer. As a rule of thumb:

 -  A filter should be used when the document is to be modified
    in ways that are independent of the targeted output format.

 -  A custom writers is the right choice when defining a new output
    format, or when changes are to be made to just on specific format
    supported by pandoc.

There's a lot of room in between, and for the moment, I'd say:
**When in doubt, use a filter.**
But this may change in the future.

> How would I change this writer from the manual, to only process docx
> images?

Not quite sure what you mean here. Are you referring to images that were
read *from* a docx document, those written *to* a docx file, or
something else entirely?

Hope this helps,

Albert

-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124

-- 
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/87wnhvg9zo.fsf%40zeitkraut.de.


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

* Re: Understanding new style writer
       [not found]     ` <87wnhvg9zo.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-02-15 22:09       ` Günter Dannoritzer
       [not found]         ` <868a108d-f233-4f5c-bfe7-f26dc8bafffan-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2022-02-15 23:23       ` John MacFarlane
  1 sibling, 1 reply; 6+ messages in thread
From: Günter Dannoritzer @ 2022-02-15 22:09 UTC (permalink / raw)
  To: pandoc-discuss


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

Hi Albert,

Thanks for the explanantions.

Albert Krewinkel schrieb am Dienstag, 15. Februar 2022 um 21:17:59 UTC+1:
...
 

> > How would I change this writer from the manual, to only process docx 
> > images? 
>
> Not quite sure what you mean here. Are you referring to images that were 
> read *from* a docx document, those written *to* a docx file, or 
> something else entirely? 
>
>
Sorry for being so unspecific. 

I have this Markdown:

![Title: 4.3.4 USB](4_3_4-usb.png){.right width=5cm}

and I would like to have a --to=docx with the image being right aligned 
floating. However, it results in an inline image and the class is not 
considered.

So my idea is, to create the respective XML myself. The alignment is inside 
the <w:grapic>, so I cannot inject it with a filter, like shown in the 
lua-filter example on the pandoc page.

Regards,
Günter

-- 
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/868a108d-f233-4f5c-bfe7-f26dc8bafffan%40googlegroups.com.

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

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

* Re: Understanding new style writer
       [not found]     ` <87wnhvg9zo.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  2022-02-15 22:09       ` Günter Dannoritzer
@ 2022-02-15 23:23       ` John MacFarlane
  1 sibling, 0 replies; 6+ messages in thread
From: John MacFarlane @ 2022-02-15 23:23 UTC (permalink / raw)
  To: Albert Krewinkel, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:

> Hi Günter,
>
> Günter Dannoritzer <dannoritzer-S0/GAf8tV78@public.gmane.org> writes:
>
>> in the pandoc manual it shows under custom-writers how to create a
>> writer.
>
> This feature has not been released yet, and should probably not be
> mentioned on the website. You can already test it by using one of the

My mistake; I will revert it to the documentation for the released version!

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


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

* Re: Understanding new style writer
       [not found]         ` <868a108d-f233-4f5c-bfe7-f26dc8bafffan-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-17  7:44           ` Albert Krewinkel
       [not found]             ` <87bkz6exuy.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Albert Krewinkel @ 2022-02-17  7:44 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Günter Dannoritzer <dannoritzer-S0/GAf8tV78@public.gmane.org> writes:

> Albert Krewinkel schrieb am Dienstag, 15. Februar 2022 um 21:17:59
> UTC+1:
> ...
>
>   > How would I change this writer from the manual, to only process
>   docx
>   > images?
>   Not quite sure what you mean here. Are you referring to images that
>   were
>   read *from* a docx document, those written *to* a docx file, or
>   something else entirely?
>
> Sorry for being so unspecific.
> I have this Markdown:
> ![Title: 4.3.4 USB](4_3_4-usb.png){.right width=5cm}
> and I would like to have a --to=docx with the image being right aligned
> floating. However, it results in an inline image and the class is not
> considered.
> So my idea is, to create the respective XML myself. The alignment is
> inside the <w:grapic>, so I cannot inject it with a filter, like shown

OK, I see. Adding raw OOXML into docx is notoriously difficult, but
should be possible. Figures are currently represented as Para elements
that contain just one image. You could try to process that and then
return a `RawBlock` containing the necessary OOXML. Filtering these
specific Para will give you more freedom than replacing just the Image.

Hope that helps, please let us know how it goes.

-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124

-- 
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/87bkz6exuy.fsf%40zeitkraut.de.


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

* Re: Understanding new style writer
       [not found]             ` <87bkz6exuy.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-02-18 20:58               ` Günter Dannoritzer
  0 siblings, 0 replies; 6+ messages in thread
From: Günter Dannoritzer @ 2022-02-18 20:58 UTC (permalink / raw)
  To: pandoc-discuss


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

Thanks for that explanation. This is what I did now:

--- text.md
![Image right](image.png){.right width=5cm}


![Image center](image.png){.center width=5cm}
---

and here is the lua filter:

--- img.lua

function Image (img)

  align = 'left'
  for k, v in pairs(img.classes) do
    if v == 'center' then
      align = 'center'
    elseif v == 'right' then
      align = 'right'
    end
  end

  ret_img = {
     pandoc.RawInline('openxml', string.format('<w:pPr><w:jc 
w:val="%s"/></w:pPr>', align)),
     img
  }

  return ret_img
end
---

Concerning the alignment the filter works as expected and as using the 
class parameter, the text can be used for docx and html export without 
having to change the markdown.

Thanks again for the help.

Regards,
Günter


-- 
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/a2ff754b-d09a-4db5-a091-14c57e82b2c2n%40googlegroups.com.

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

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

end of thread, other threads:[~2022-02-18 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 19:06 Understanding new style writer Günter Dannoritzer
     [not found] ` <12d035a5-f3c1-475a-9ae5-db014361514an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-15 19:44   ` Albert Krewinkel
     [not found]     ` <87wnhvg9zo.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-02-15 22:09       ` Günter Dannoritzer
     [not found]         ` <868a108d-f233-4f5c-bfe7-f26dc8bafffan-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-17  7:44           ` Albert Krewinkel
     [not found]             ` <87bkz6exuy.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-02-18 20:58               ` Günter Dannoritzer
2022-02-15 23:23       ` 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).