From: mb21 <mauro.bieg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Modify writer or extensions inside a filter
Date: Fri, 16 Apr 2021 04:41:58 -0700 (PDT) [thread overview]
Message-ID: <c01112ea-3fd0-42c7-86ae-6e1806671b7bn@googlegroups.com> (raw)
In-Reply-To: <50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 3300 bytes --]
cross-posting
of https://stackoverflow.com/questions/67109880/is-it-posible-to-enable-extensions-on-pandoc-filters
Why do you prefer to set this in the filter instead of on the writer? I
don't think there's a way to do that... because the filter just outputs an
AST again, and what you're trying to change is happening in the writer...
On Thursday, April 15, 2021 at 4:20:32 PM UTC+2 Angel Joaniquet wrote:
> The lua split function is this
>
>
> ```lua
> function split(str,pat)
> local tbl = {}
> str:gsub(pat, function(x) tbl[#tbl+1]=x end)
> return tbl
> end
> ```
>
> El jueves, 15 de abril de 2021 a las 16:08:23 UTC+2, Angel Joaniquet
> escribió:
>
>>
>> I'm trying to make a filter to transform some features of org-mode to
>> GitLab-markdown (not supported by Pandoc out of the box), in particular,
>> the math blocks.
>>
>> The filter should work when transforming to `markdown`, but instead of
>> giving the markdown format for the math blocks (enclosed by `$$...$$`), it
>> should write the blocks as
>>
>> ``` math
>> a + b = c
>> ```
>>
>> The preces I have now is
>>
>> In org-mode, the math blocks are simply the latex code:
>>
>> ```
>> \begin{equation}
>> a + b = c
>> \end{equation}
>> ```
>>
>> this is parsed as a pandoc AST `RawBlock` with format `latex`. I then
>> remove the first (`\begin{equation}`) an last line (`\end{equation}`), and
>> construct a pandoc `CodeBlock` with atrributes `{"math"}`, so the
>> `CodeBlock` object displays in AST as
>>
>> ```
>> CodeBlock ("",["math"],[]) "a + b = c\n"
>> ```
>>
>> and then I let Pandoc create the markdown document, and the written
>> result is
>>
>> ``` {.math}
>> a + b = c
>> ```
>>
>>
>>
>> **The question:**
>> I want the bare `math`, not `{.math}` written, without the use of CLI
>> options.
>>
>>
>> I am aware that this can be done setting the Writer extension
>> `fenced_code_attributes` to false (eg. `$pandoc -w
>> markdown-fenced_code_attributes ...`), but I would much prefer this done
>> inside the filter.
>>
>> Or is it possible to set the extensions inside the filter?
>>
>>
>> Here is my atempted lua-filter:
>>
>> ``` lua
>> function RawBlock(rb)
>> if rb.format == "latex" then
>> local text = rb.text
>> split_text = split(text, "[^\n]*")
>> if split_text[1] == '\\begin{equation}' and
>> split_text[#split_text-1] == '\\end{equation}' then
>> table.remove(split_text, #split_text-1)
>> table.remove(split_text, 1)
>> text = table.concat(split_text, "\n")
>> local cb = pandoc.CodeBlock()
>> cb.attr = {"",{"math"}}
>> cb.text = text
>> return cb
>> end
>> end
>> end
>> ```
>>
>>
>> Kind regards,
>>
>> Angel
>>
>>
>>
>>
--
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/c01112ea-3fd0-42c7-86ae-6e1806671b7bn%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 4109 bytes --]
next prev parent reply other threads:[~2021-04-16 11:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-15 14:08 'Angel Joaniquet' via pandoc-discuss
[not found] ` <509d7700-5cb3-4382-9276-c4b2e2a0c3e5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-04-15 14:20 ` 'Angel Joaniquet' via pandoc-discuss
[not found] ` <50d9ae1b-95a0-445f-9ab2-5b1fe2cc992fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-04-16 11:41 ` mb21 [this message]
[not found] ` <c01112ea-3fd0-42c7-86ae-6e1806671b7bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-04-16 12:00 ` 'Angel Joaniquet' via pandoc-discuss
[not found] ` <03f7ab59-6b1a-451e-8528-4b164d439dc4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-04-16 13:56 ` Albert Krewinkel
[not found] ` <87sg3qqqn9.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-04-19 11:33 ` 'Angel Joaniquet' via pandoc-discuss
2021-04-19 14:49 ` BPJ
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=c01112ea-3fd0-42c7-86ae-6e1806671b7bn@googlegroups.com \
--to=mauro.bieg-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).