public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua filter to include sources
@ 2019-06-09  7:57 Pablo Rodríguez
       [not found] ` <395a8b1a-ac45-3f1a-28b1-5c6c079db7f5-S0/GAf8tV78@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-09  7:57 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Dear list,

I think this was discussed (or mentioned, at least) before in this list.

I need a filter (also for “Windows” [where I don’t have admin rights])
to include files such as in:

  [file1.md]{.include-file}

Does anyone created a similar filter for file inclusion?

Many thanks for your help,

Pablo
--
http://www.ousia.tk

-- 
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/395a8b1a-ac45-3f1a-28b1-5c6c079db7f5%40web.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found] ` <395a8b1a-ac45-3f1a-28b1-5c6c079db7f5-S0/GAf8tV78@public.gmane.org>
@ 2019-06-09 13:31   ` Germán Theler
  2019-06-22 20:22   ` BP Jonsson
  2019-06-27 15:25   ` 山本一貴
  2 siblings, 0 replies; 15+ messages in thread
From: Germán Theler @ 2019-06-09 13:31 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

Hi Pablo

I know you asked about Lua filters, vut what I do when I have to include
other files (not necessarily source code files) is to preprocess the
original md file with m4. I use the include() macro and then feed the
result to pandoc.

Regards

--
jeremy theler
www.seamplex.com

On Sun, Jun 9, 2019, 04:57 Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> wrote:

> Dear list,
>
> I think this was discussed (or mentioned, at least) before in this list.
>
> I need a filter (also for “Windows” [where I don’t have admin rights])
> to include files such as in:
>
>   [file1.md]{.include-file}
>
> Does anyone created a similar filter for file inclusion?
>
> Many thanks for your help,
>
> Pablo
> --
> http://www.ousia.tk
>
> --
> 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/395a8b1a-ac45-3f1a-28b1-5c6c079db7f5%40web.de
> .
> 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/CAK0LiynF6-HmGzfW-ojNq1N88tbb3-Uam7oZj9NmJXJ%2BHNNTBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found] ` <395a8b1a-ac45-3f1a-28b1-5c6c079db7f5-S0/GAf8tV78@public.gmane.org>
  2019-06-09 13:31   ` Germán Theler
@ 2019-06-22 20:22   ` BP Jonsson
       [not found]     ` <CAFC_yuQe9p8Ua_EPGhffQT6Q4txyWdNTkvS2UkJ+vBRrgsX1wg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-06-27 15:25   ` 山本一貴
  2 siblings, 1 reply; 15+ messages in thread
From: BP Jonsson @ 2019-06-22 20:22 UTC (permalink / raw)
  To: pandoc-discuss

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

The leanest way to do this is probably with pp before you process the input
with Pandoc at all.

https://github.com/CDSoft/pp

Doing it with a filter you need to process the included file with Pandoc
from inside the filter.  Definitely possible but clunky. Also you would
need to use a div rather than a span and you would need to make sure that
the filter is always run before all other filters to make sure the included
content is affected by the other filters.

If you still prefer to use a filter let me know.

Den sön 9 juni 2019 09:57Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> skrev:

> Dear list,
>
> I think this was discussed (or mentioned, at least) before in this list.
>
> I need a filter (also for “Windows” [where I don’t have admin rights])
> to include files such as in:
>
>   [file1.md]{.include-file}
>
> Does anyone created a similar filter for file inclusion?
>
> Many thanks for your help,
>
> Pablo
> --
> http://www.ousia.tk
>
> --
> 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/395a8b1a-ac45-3f1a-28b1-5c6c079db7f5%40web.de
> .
> 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/CAFC_yuQe9p8Ua_EPGhffQT6Q4txyWdNTkvS2UkJ%2BvBRrgsX1wg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found]     ` <CAFC_yuQe9p8Ua_EPGhffQT6Q4txyWdNTkvS2UkJ+vBRrgsX1wg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-06-23 11:46       ` Pablo Rodríguez
       [not found]         ` <f02fcea3-f721-ba64-ef73-c09937948afa-S0/GAf8tV78@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-23 11:46 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On 6/22/19 10:22 PM, BP Jonsson wrote:
> The leanest way to do this is probably with pp before you process the
> input with Pandoc at all.
>
> https://github.com/CDSoft/pp

Many thanks for your reply, BPJ.

A preprocessor is something that I have to avoid.

We are a small group working on a +1000-page document. To use Markdown,
git and PDF output (with ConTeXt from XML sources), I have to provide
the simplest method to the rest of the group.

> Doing it with a filter you need to process the included file with Pandoc
> from inside the filter.  Definitely possible but clunky. Also you would
> need to use a div rather than a span and you would need to make sure
> that the filter is always run before all other filters to make sure the
> included content is affected by the other filters.

Actually, file transclusion was already proposed for MultiMarkdown
(https://fletcher.github.io/MultiMarkdown-5/transclusion.html):

 {{filetoinclude.md}}

> If you still prefer to use a filter let me know.

Would it be possible to have a filter that understands the syntax above?

Many thanks for your help,

Pablo
--
http://www.ousia.tk

-- 
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/f02fcea3-f721-ba64-ef73-c09937948afa%40web.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]         ` <f02fcea3-f721-ba64-ef73-c09937948afa-S0/GAf8tV78@public.gmane.org>
@ 2019-06-23 13:16           ` jeremy theler
       [not found]             ` <CAK0LiykC58NkKuL4CDGGn5K7QabFOXcyca8J9oDZr1SBpuhNHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-06-23 19:33           ` Albert Krewinkel
  1 sibling, 1 reply; 15+ messages in thread
From: jeremy theler @ 2019-06-23 13:16 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

is

m4 input.md | pandoc

"that" more complex than

pandoc input.md

?

--
jeremy theler
www.seamplex.com

On Sun, Jun 23, 2019, 08:46 Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> wrote:

> On 6/22/19 10:22 PM, BP Jonsson wrote:
> > The leanest way to do this is probably with pp before you process the
> > input with Pandoc at all.
> >
> > https://github.com/CDSoft/pp
>
> Many thanks for your reply, BPJ.
>
> A preprocessor is something that I have to avoid.
>
> We are a small group working on a +1000-page document. To use Markdown,
> git and PDF output (with ConTeXt from XML sources), I have to provide
> the simplest method to the rest of the group.
>
> > Doing it with a filter you need to process the included file with Pandoc
> > from inside the filter.  Definitely possible but clunky. Also you would
> > need to use a div rather than a span and you would need to make sure
> > that the filter is always run before all other filters to make sure the
> > included content is affected by the other filters.
>
> Actually, file transclusion was already proposed for MultiMarkdown
> (https://fletcher.github.io/MultiMarkdown-5/transclusion.html):
>
>  {{filetoinclude.md}}
>
> > If you still prefer to use a filter let me know.
>
> Would it be possible to have a filter that understands the syntax above?
>
> Many thanks for your help,
>
> Pablo
> --
> http://www.ousia.tk
>
> --
> 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/f02fcea3-f721-ba64-ef73-c09937948afa%40web.de
> .
> 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/CAK0LiykC58NkKuL4CDGGn5K7QabFOXcyca8J9oDZr1SBpuhNHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found]             ` <CAK0LiykC58NkKuL4CDGGn5K7QabFOXcyca8J9oDZr1SBpuhNHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-06-23 17:35               ` Pablo Rodríguez
       [not found]                 ` <653f8584-8908-f7e2-7e37-d653acb2a8ac-S0/GAf8tV78@public.gmane.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-23 17:35 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On 6/23/19 3:16 PM, jeremy theler wrote:
> is "m4 input.md | pandoc" *that* more complex than "pandoc
> input.md"?
Hi Jeremy,

many thanks for your reply.

The issue is that I have already installed all required software
(pandoc, git, ConTeXt [plus proper text editor and required scripts]) in
the foreign computers (with Win7/10 on them).

Adding a new tool is a real problem for me. There are no recently
compiled binaries for Windows (at least,
http://gnuwin32.sourceforge.net/packages/m4.htm are almost a decade
old). And the installation should be postponed to my next visit to the
locations where those foreign computers are placed (it may take up to
the end of 2019).

I realize (by guessing) that source inclusion capability may not be
available in core pandoc.

But not being able to have this feature in a filter is extremely
problematic fo the rest of us (the ones that don’t code).

Best wishes,

Pablo
--
http://www.ousia.tk

-- 
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/653f8584-8908-f7e2-7e37-d653acb2a8ac%40web.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]         ` <f02fcea3-f721-ba64-ef73-c09937948afa-S0/GAf8tV78@public.gmane.org>
  2019-06-23 13:16           ` jeremy theler
@ 2019-06-23 19:33           ` Albert Krewinkel
       [not found]             ` <8736k0yu4z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Albert Krewinkel @ 2019-06-23 19:33 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Pablo Rodríguez writes:

> On 6/22/19 10:22 PM, BP Jonsson wrote:
>> The leanest way to do this is probably with pp before you process the
>> input with Pandoc at all.
>>
>> https://github.com/CDSoft/pp
>
> Many thanks for your reply, BPJ.
>
> A preprocessor is something that I have to avoid.
>
> We are a small group working on a +1000-page document. To use Markdown,
> git and PDF output (with ConTeXt from XML sources), I have to provide
> the simplest method to the rest of the group.
>
>> Doing it with a filter you need to process the included file with Pandoc
>> from inside the filter. Definitely possible but clunky. Also you would
>> need to use a div rather than a span and you would need to make sure
>> that the filter is always run before all other filters to make sure the
>> included content is affected by the other filters.
>
> Actually, file transclusion was already proposed for MultiMarkdown
> (https://fletcher.github.io/MultiMarkdown-5/transclusion.html):
>
>  {{filetoinclude.md}}
>
>> If you still prefer to use a filter let me know.
>
> Would it be possible to have a filter that understands the syntax above?

Not good code, but implements MultiMarkdown syntax:

    function Para (p)
      if #p.content ~= 1 or p.content[1].t ~= 'Str' then return end
      local filename = p.content[1].text:match '^{{(.*)}}$'
      return filename
        and pandoc.read(io.open(filename, 'r'):read '*a').blocks
        or nil
    end

    function CodeBlock (cb)
      local filename = cb.text:match '^{{(.*)}}'
      return filename
        and pandoc.CodeBlock(io.open(filename, 'r'):read '*a').blocks
        or nil
    end

-- 
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/8736k0yu4z.fsf%40zeitkraut.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]                 ` <653f8584-8908-f7e2-7e37-d653acb2a8ac-S0/GAf8tV78@public.gmane.org>
@ 2019-06-23 20:18                   ` Germán Theler
  0 siblings, 0 replies; 15+ messages in thread
From: Germán Theler @ 2019-06-23 20:18 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

ok, but you'll have to admit that all the issues you have are not common
enough to have pandoc developers to make bad decision choices as needing to
code again some functionality that can be solved with another already
existing tool

it is not explicitly stated but it seems to me that Pandoc follows most if
not all of Eric Raymond's rules of UNIX programming

https://en.m.wikipedia.org/wiki/Unix_philosophy

--
jeremy theler
www.seamplex.com

On Sun, Jun 23, 2019, 14:35 Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> wrote:

> On 6/23/19 3:16 PM, jeremy theler wrote:
> > is "m4 input.md | pandoc" *that* more complex than "pandoc
> > input.md"?
> Hi Jeremy,
>
> many thanks for your reply.
>
> The issue is that I have already installed all required software
> (pandoc, git, ConTeXt [plus proper text editor and required scripts]) in
> the foreign computers (with Win7/10 on them).
>
> Adding a new tool is a real problem for me. There are no recently
> compiled binaries for Windows (at least,
> http://gnuwin32.sourceforge.net/packages/m4.htm are almost a decade
> old). And the installation should be postponed to my next visit to the
> locations where those foreign computers are placed (it may take up to
> the end of 2019).
>
> I realize (by guessing) that source inclusion capability may not be
> available in core pandoc.
>
> But not being able to have this feature in a filter is extremely
> problematic fo the rest of us (the ones that don’t code).
>
> Best wishes,
>
> Pablo
> --
> http://www.ousia.tk
>
> --
> 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/653f8584-8908-f7e2-7e37-d653acb2a8ac%40web.de
> .
> 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/CAK0LiynVYa9kq1EaEq7RGvsHWp9x2BLt0etFw0BaDzcgN4RZng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found]             ` <8736k0yu4z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2019-06-23 21:29               ` BP Jonsson
       [not found]                 ` <CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-06-25 18:59               ` Pablo Rodríguez
  1 sibling, 1 reply; 15+ messages in thread
From: BP Jonsson @ 2019-06-23 21:29 UTC (permalink / raw)
  To: pandoc-discuss

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

Even though it is generally unwise to have whitespace in file names it
should be pointed out that this "MultiMarkdown syntax" hack will not work
if there is whitespace in the file name.

IMHO the whole idea of trying to duplicate some syntax of another tool
rather than implementing as robust a mechanism as possible exploiting the
syntax, or rather the AST structure and filter mechanism, of *Pandoc* is
misguided and invites trouble. The most robust solution is certainly to use
a Pandoc fenced code block[^1] with a class `include` where the text of the
code block is the file name and only the file name, like this:

``````
```include
included-file.md
```
``````

Here is an implementation:

````lua
function CodeBlock (cb)
  if #cb.classes == 1 and cb.classes[1] == 'include' then
    -- remove leadimg/trailing whitespace
    local filename = cb.text:gsub('^%s+', ""):gsub('%s+$', "")
    if filename:len() == 0 then
      -- bail out if there is no file name
      return nil
    end
    return pandoc.read(
      io.open(filename, 'r'):read('*a') ).blocks
  else
    return nil
  end
end
````

[^1]: When I wrote "div" earlier it was a typo/thinko for "code block"
because I had been working with divs just before.

Den sön 23 juni 2019 21:33Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
skrev:

>
> Pablo Rodríguez writes:
>
> > On 6/22/19 10:22 PM, BP Jonsson wrote:
> >> The leanest way to do this is probably with pp before you process the
> >> input with Pandoc at all.
> >>
> >> https://github.com/CDSoft/pp
> >
> > Many thanks for your reply, BPJ.
> >
> > A preprocessor is something that I have to avoid.
> >
> > We are a small group working on a +1000-page document. To use Markdown,
> > git and PDF output (with ConTeXt from XML sources), I have to provide
> > the simplest method to the rest of the group.
> >
> >> Doing it with a filter you need to process the included file with Pandoc
> >> from inside the filter. Definitely possible but clunky. Also you would
> >> need to use a div rather than a span and you would need to make sure
> >> that the filter is always run before all other filters to make sure the
> >> included content is affected by the other filters.
> >
> > Actually, file transclusion was already proposed for MultiMarkdown
> > (https://fletcher.github.io/MultiMarkdown-5/transclusion.html):
> >
> >  {{filetoinclude.md}}
> >
> >> If you still prefer to use a filter let me know.
> >
> > Would it be possible to have a filter that understands the syntax above?
>
> Not good code, but implements MultiMarkdown syntax:
>
>     function Para (p)
>       if #p.content ~= 1 or p.content[1].t ~= 'Str' then return end
>       local filename = p.content[1].text:match '^{{(.*)}}$'
>       return filename
>         and pandoc.read(io.open(filename, 'r'):read '*a').blocks
>         or nil
>     end
>
>     function CodeBlock (cb)
>       local filename = cb.text:match '^{{(.*)}}'
>       return filename
>         and pandoc.CodeBlock(io.open(filename, 'r'):read '*a').blocks
>         or nil
>     end
>
> --
> 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/8736k0yu4z.fsf%40zeitkraut.de
> .
> 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/CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found]                 ` <CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-06-23 23:03                   ` John MacFarlane
       [not found]                     ` <m236jzrjkh.fsf-gd5emFPDCk19a1wB/4mvwEEMvNT87kid@public.gmane.org>
  2019-06-25 19:14                   ` Pablo Rodríguez
  1 sibling, 1 reply; 15+ messages in thread
From: John MacFarlane @ 2019-06-23 23:03 UTC (permalink / raw)
  To: BP Jonsson, pandoc-discuss


This is a common request.

The filter approach has limitations; since this only
gets done after parsing, it will cause problems if
you have e.g. reference links defined in one file
and used in another.

We have the infrastructure to do includes in the
parser, and we do it already in LaTeX and RST.
So it wouldn't actually be hard to add support
for includes to pandoc markdown.  Whether it's
a good idea, and if so what syntax to use, I'm
less sure.



BP Jonsson <bpjonsson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> Even though it is generally unwise to have whitespace in file names it
> should be pointed out that this "MultiMarkdown syntax" hack will not work
> if there is whitespace in the file name.
>
> IMHO the whole idea of trying to duplicate some syntax of another tool
> rather than implementing as robust a mechanism as possible exploiting the
> syntax, or rather the AST structure and filter mechanism, of *Pandoc* is
> misguided and invites trouble. The most robust solution is certainly to use
> a Pandoc fenced code block[^1] with a class `include` where the text of the
> code block is the file name and only the file name, like this:
>
> ``````
> ```include
> included-file.md
> ```
> ``````
>
> Here is an implementation:
>
> ````lua
> function CodeBlock (cb)
>   if #cb.classes == 1 and cb.classes[1] == 'include' then
>     -- remove leadimg/trailing whitespace
>     local filename = cb.text:gsub('^%s+', ""):gsub('%s+$', "")
>     if filename:len() == 0 then
>       -- bail out if there is no file name
>       return nil
>     end
>     return pandoc.read(
>       io.open(filename, 'r'):read('*a') ).blocks
>   else
>     return nil
>   end
> end
> ````
>
> [^1]: When I wrote "div" earlier it was a typo/thinko for "code block"
> because I had been working with divs just before.
>
> Den sön 23 juni 2019 21:33Albert Krewinkel <albert+pandoc@zeitkraut.de>
> skrev:
>
>>
>> Pablo Rodríguez writes:
>>
>> > On 6/22/19 10:22 PM, BP Jonsson wrote:
>> >> The leanest way to do this is probably with pp before you process the
>> >> input with Pandoc at all.
>> >>
>> >> https://github.com/CDSoft/pp
>> >
>> > Many thanks for your reply, BPJ.
>> >
>> > A preprocessor is something that I have to avoid.
>> >
>> > We are a small group working on a +1000-page document. To use Markdown,
>> > git and PDF output (with ConTeXt from XML sources), I have to provide
>> > the simplest method to the rest of the group.
>> >
>> >> Doing it with a filter you need to process the included file with Pandoc
>> >> from inside the filter. Definitely possible but clunky. Also you would
>> >> need to use a div rather than a span and you would need to make sure
>> >> that the filter is always run before all other filters to make sure the
>> >> included content is affected by the other filters.
>> >
>> > Actually, file transclusion was already proposed for MultiMarkdown
>> > (https://fletcher.github.io/MultiMarkdown-5/transclusion.html):
>> >
>> >  {{filetoinclude.md}}
>> >
>> >> If you still prefer to use a filter let me know.
>> >
>> > Would it be possible to have a filter that understands the syntax above?
>>
>> Not good code, but implements MultiMarkdown syntax:
>>
>>     function Para (p)
>>       if #p.content ~= 1 or p.content[1].t ~= 'Str' then return end
>>       local filename = p.content[1].text:match '^{{(.*)}}$'
>>       return filename
>>         and pandoc.read(io.open(filename, 'r'):read '*a').blocks
>>         or nil
>>     end
>>
>>     function CodeBlock (cb)
>>       local filename = cb.text:match '^{{(.*)}}'
>>       return filename
>>         and pandoc.CodeBlock(io.open(filename, 'r'):read '*a').blocks
>>         or nil
>>     end
>>
>> --
>> 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/8736k0yu4z.fsf%40zeitkraut.de
>> .
>> 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/CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g%40mail.gmail.com.
> 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/m236jzrjkh.fsf%40macbook-air-3.home.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]             ` <8736k0yu4z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  2019-06-23 21:29               ` BP Jonsson
@ 2019-06-25 18:59               ` Pablo Rodríguez
  1 sibling, 0 replies; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-25 18:59 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On 6/23/19 9:33 PM, Albert Krewinkel wrote:
> Pablo Rodríguez writes:
>> [...]
>>> If you still prefer to use a filter let me know.
>>
>> Would it be possible to have a filter that understands the syntax above?
>
> Not good code, but implements MultiMarkdown syntax:
>
>     function Para (p)
>       if #p.content ~= 1 or p.content[1].t ~= 'Str' then return end
>       local filename = p.content[1].text:match '^{{(.*)}}$'
>       return filename
>         and pandoc.read(io.open(filename, 'r'):read '*a').blocks
>         or nil
>     end
>
>     function CodeBlock (cb)
>       local filename = cb.text:match '^{{(.*)}}'
>       return filename
>         and pandoc.CodeBlock(io.open(filename, 'r'):read '*a').blocks
>         or nil
>     end

Many thanks for the filter, Albert.

Pablo
--
http://www.ousia.tk

-- 
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/e8b31b75-b94e-af2e-ef13-e1f19a80985d%40web.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]                 ` <CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-06-23 23:03                   ` John MacFarlane
@ 2019-06-25 19:14                   ` Pablo Rodríguez
       [not found]                     ` <7528223b-fe59-55f5-9350-8b0e6cc83e1f-S0/GAf8tV78@public.gmane.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-25 19:14 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On 6/23/19 11:29 PM, BP Jonsson wrote:
> Even though it is generally unwise to have whitespace in file names it
> should be pointed out that this "MultiMarkdown syntax" hack will not
> work if there is whitespace in the file name.

Many thanks for your filter, BPJ.

I avoid spaces in filenames.

> IMHO the whole idea of trying to duplicate some syntax of another tool
> rather than implementing as robust a mechanism as possible exploiting
> the syntax, or rather the AST structure and filter mechanism, of
> *Pandoc* is misguided and invites trouble. The most robust solution is
> certainly to use a Pandoc fenced code block[^1] with a class `include`
> where the text of the code block is the file name and only the file
> name, like this:
>
> ``````
> ```include
> included-file.md
> ```
> ``````

As a side-comment, if code blocks are used to get code in the final
documents, don’t you think this syntax makes it much harder for the user
(at least, the non-coder) to write documents and to get the big picture
of consistent Markdown usage?

Many thanks for your help,

Pablo
--
http://www.ousia.tk

-- 
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/7528223b-fe59-55f5-9350-8b0e6cc83e1f%40web.de.
For more options, visit https://groups.google.com/d/optout.


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

* Re: Lua filter to include sources
       [not found]                     ` <m236jzrjkh.fsf-gd5emFPDCk19a1wB/4mvwEEMvNT87kid@public.gmane.org>
@ 2019-06-25 19:25                       ` Pablo Rodríguez
  0 siblings, 0 replies; 15+ messages in thread
From: Pablo Rodríguez @ 2019-06-25 19:25 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On 6/24/19 1:03 AM, John MacFarlane wrote:
>
> This is a common request.
>
> The filter approach has limitations; since this only
> gets done after parsing, it will cause problems if
> you have e.g. reference links defined in one file
> and used in another.

If the whole problem with an inclusion filter is this (I mean, having
content that is splitted in two files), I think this may be easily avoided.

Many thanks for your reply,

Pablo
--
http://www.ousia.tk


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

* Re: Lua filter to include sources
       [not found]                     ` <7528223b-fe59-55f5-9350-8b0e6cc83e1f-S0/GAf8tV78@public.gmane.org>
@ 2019-06-26  8:03                       ` BP Jonsson
  0 siblings, 0 replies; 15+ messages in thread
From: BP Jonsson @ 2019-06-26  8:03 UTC (permalink / raw)
  To: pandoc-discuss

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

I don't see why the one syntax should be more confusing than the other. Any
syntax has to be learnt by a user before they can use it. The word
`include`, which is highly unlikely to be the name of a highlighting
language, is prominently visible on the code block and it should be fairly
obvious that the file name is a file name. The main advantage of the code
block based version is that it is much less likely to cause a "parsing
error", and I think that it might be much more confusing, especially for a
non-programmer, if inclusion doesn't happen because of such an error.
Besides there already is the raw block syntax which arguably also might be
confusing to someone used to GFM code blocks, and must be learnt like any
other extension.

````````pandoc
```{=latex}
\begin{foo}
```
````````

If one wants to one can change my filter so that the "class" `INCLUDE` is
all upper case.  Since all highlight languages are lower case that might
make this stand out better as a "directive".

Den tis 25 juni 2019 21:14Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> skrev:

> On 6/23/19 11:29 PM, BP Jonsson wrote:
> > Even though it is generally unwise to have whitespace in file names it
> > should be pointed out that this "MultiMarkdown syntax" hack will not
> > work if there is whitespace in the file name.
>
> Many thanks for your filter, BPJ.
>
> I avoid spaces in filenames.
>
> > IMHO the whole idea of trying to duplicate some syntax of another tool
> > rather than implementing as robust a mechanism as possible exploiting
> > the syntax, or rather the AST structure and filter mechanism, of
> > *Pandoc* is misguided and invites trouble. The most robust solution is
> > certainly to use a Pandoc fenced code block[^1] with a class `include`
> > where the text of the code block is the file name and only the file
> > name, like this:
> >
> > ``````
> > ```include
> > included-file.md
> > ```
> > ``````
>
> As a side-comment, if code blocks are used to get code in the final
> documents, don’t you think this syntax makes it much harder for the user
> (at least, the non-coder) to write documents and to get the big picture
> of consistent Markdown usage?
>
> Many thanks for your help,
>
> Pablo
> --
> http://www.ousia.tk
>
> --
> 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/7528223b-fe59-55f5-9350-8b0e6cc83e1f%40web.de
> .
> 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/CAFC_yuSVzMZa4ZPP2M0DY6TiNSBnjMsujm_rpNBuokHJneoQ8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: Lua filter to include sources
       [not found] ` <395a8b1a-ac45-3f1a-28b1-5c6c079db7f5-S0/GAf8tV78@public.gmane.org>
  2019-06-09 13:31   ` Germán Theler
  2019-06-22 20:22   ` BP Jonsson
@ 2019-06-27 15:25   ` 山本一貴
  2 siblings, 0 replies; 15+ messages in thread
From: 山本一貴 @ 2019-06-27 15:25 UTC (permalink / raw)
  To: pandoc-discuss


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

Hello Pablo,

This is not cleaned up, with many debugging comments, but 
https://github.com/pandocker/pandocker-lua-filters/blob/master/lua/preprocess.lua
may work for you.

The syntax is a header of any level like `# #include "filename.md"`. The 
filter is hooking 
a-Header-containing-Str("#include")-Space()-Quoted("filename.md") 
combination.
This filter works recursively, but not with stuff inside a Div.

Hope this helps; you can reuse or whatever under MIT license.

Regards,
K4zuki / Kazuki

-- 
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/4865859a-58c8-4eed-8862-97aa0722f098%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

end of thread, other threads:[~2019-06-27 15:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-09  7:57 Lua filter to include sources Pablo Rodríguez
     [not found] ` <395a8b1a-ac45-3f1a-28b1-5c6c079db7f5-S0/GAf8tV78@public.gmane.org>
2019-06-09 13:31   ` Germán Theler
2019-06-22 20:22   ` BP Jonsson
     [not found]     ` <CAFC_yuQe9p8Ua_EPGhffQT6Q4txyWdNTkvS2UkJ+vBRrgsX1wg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-06-23 11:46       ` Pablo Rodríguez
     [not found]         ` <f02fcea3-f721-ba64-ef73-c09937948afa-S0/GAf8tV78@public.gmane.org>
2019-06-23 13:16           ` jeremy theler
     [not found]             ` <CAK0LiykC58NkKuL4CDGGn5K7QabFOXcyca8J9oDZr1SBpuhNHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-06-23 17:35               ` Pablo Rodríguez
     [not found]                 ` <653f8584-8908-f7e2-7e37-d653acb2a8ac-S0/GAf8tV78@public.gmane.org>
2019-06-23 20:18                   ` Germán Theler
2019-06-23 19:33           ` Albert Krewinkel
     [not found]             ` <8736k0yu4z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-06-23 21:29               ` BP Jonsson
     [not found]                 ` <CAFC_yuT2G3TMd3PXTjnAzkVrTMdo8ZbJNGRiuz4-Vpurws9W4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-06-23 23:03                   ` John MacFarlane
     [not found]                     ` <m236jzrjkh.fsf-gd5emFPDCk19a1wB/4mvwEEMvNT87kid@public.gmane.org>
2019-06-25 19:25                       ` Pablo Rodríguez
2019-06-25 19:14                   ` Pablo Rodríguez
     [not found]                     ` <7528223b-fe59-55f5-9350-8b0e6cc83e1f-S0/GAf8tV78@public.gmane.org>
2019-06-26  8:03                       ` BP Jonsson
2019-06-25 18:59               ` Pablo Rodríguez
2019-06-27 15:25   ` 山本一貴

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