public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Two treatments of same input file
@ 2021-12-09  2:52 Gregory Weber
       [not found] ` <736c254f-44fe-49f8-9556-2f4c83c4e5a0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Gregory Weber @ 2021-12-09  2:52 UTC (permalink / raw)
  To: pandoc-discuss


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

I'm work on creating a set of examples of HTML, JavaScript, and SVG code.
Each comes from a single source file, from which I want to produce a
web page showing
(a) the result of rendering the HTML or SVG or executing the JavaScript;
(b) the code itself, viewed as if in a text editor, and (ideally) with
syntax highlighting.

The best way I can think of doing this involves making two
transformations of the source file, running pandoc on each of them,
and the combining the outputs, probably by running pandoc a third time
with a custom template.

I'm wondering if there's any better way?

Here's a small example:

(1) Original source file:

<form>
<input id="b1" type="button" value="Apply" title="Button"/>
</form>


(2) Intermediate file 1:

```{=html5}
<form>
<input id="b1" type="button" value="Apply" title="Button"/>
</form>
```

(3) Intermediate file 2:

~~~~{.html}
<form>
<input id="b1" type="button" value="Apply" title="Button"/>
</form>
~~~~

(4) Desired final output would be something like this:

...

<h2>A Form with a Button</h2>

<form>
<input id="b1" type="button" value="Apply" title="Button"/>
</form>

<h2>Code to Produce a Form with a Button</h2>

<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code 
class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span 
class="kw">&lt;form&gt;</span></a>
<a class="sourceLine" id="cb1-2" title="2"><span 
class="kw">&lt;input</span><span class="ot"> id=</span><span 
class="st">&quot;b1&quot;</span><span class="ot"> type=</span><span 
class="st">&quot;button&quot;</span><span class="ot"> value=</span><span 
class="st">&quot;Apply&quot;</span><span class="ot"> title=</span><span 
class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span></a>
<a class="sourceLine" id="cb1-3" title="3"><span 
class="kw">&lt;/form&gt;</span></a></code></pre></div>

...

-- 
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/736c254f-44fe-49f8-9556-2f4c83c4e5a0n%40googlegroups.com.

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

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

* Re: Two treatments of same input file
       [not found] ` <736c254f-44fe-49f8-9556-2f4c83c4e5a0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-12-09  9:48   ` Bastien DUMONT
  2021-12-09 20:29     ` Gregory D. Weber
  2021-12-10 15:39   ` Sébastien Boisgérault
  1 sibling, 1 reply; 7+ messages in thread
From: Bastien DUMONT @ 2021-12-09  9:48 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

You can handle all of this using a Lua filter. Assuming that your first heading will always start with "A" and the second with "Code to Produce a", I rewrote slightly your input in test.md:

```
~~~ {.html heading="Form with a Button"}
<form>
<input id="b1" type="button" value="Apply" title="Button"/>
</form>
~~~
```

Then I wrote in test.lua:

```
local HEADING_LEVEL = 2

function CodeBlock(block)
  if block.attr.attributes.heading then
    local raw_heading = block.attr.attributes.heading
    local html_object_heading = pandoc.Header(HEADING_LEVEL, 'A ' .. raw_heading)
    local html_object = pandoc.RawBlock('html5', block.text)
    local code_block_heading = pandoc.Header(HEADING_LEVEL, 'Code to produce a ' .. raw_heading)
    return { html_object_heading, html_object, code_block_heading, block }
  end
end
```

With the command pandoc test.md -L test.lua, I got the desired result.

You may want to modify it in order to adapt it to your real needs (like setting a "header-level" attribute on your raw block, etc.)

Le Wednesday 08 December 2021 à 06:52:34PM, Gregory Weber a écrit :
> I'm work on creating a set of examples of HTML, JavaScript, and SVG code.
> Each comes from a single source file, from which I want to produce a
> web page showing
> (a) the result of rendering the HTML or SVG or executing the JavaScript;
> (b) the code itself, viewed as if in a text editor, and (ideally) with
> syntax highlighting.
> 
> The best way I can think of doing this involves making two
> transformations of the source file, running pandoc on each of them,
> and the combining the outputs, probably by running pandoc a third time
> with a custom template.
> 
> I'm wondering if there's any better way?
> 
> Here's a small example:
> 
> (1) Original source file:
> 
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> 
> 
> (2) Intermediate file 1:
> 
> ```{=html5}
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> ```
> 
> (3) Intermediate file 2:
> 
> ~~~~{.html}
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> ~~~~
> 
> (4) Desired final output would be something like this:
> 
> ...
> 
> <h2>A Form with a Button</h2>
> 
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> 
> <h2>Code to Produce a Form with a Button</h2>
> 
> <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class=
> "sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">&
> lt;form&gt;</span></a>
> <a class="sourceLine" id="cb1-2" title="2"><span class="kw">&lt;input</span>
> <span class="ot"> id=</span><span class="st">&quot;b1&quot;</span><span class=
> "ot"> type=</span><span class="st">&quot;button&quot;</span><span class="ot">
> value=</span><span class="st">&quot;Apply&quot;</span><span class="ot"> title=
> </span><span class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span>
> </a>
> <a class="sourceLine" id="cb1-3" title="3"><span class="kw">&lt;/form&gt;</
> span></a></code></pre></div>
> 
> ...
> 
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/736c254f-44fe-49f8-9556-2f4c83c4e5a0n%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/736c254f-44fe-49f8-9556-2f4c83c4e5a0n%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
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/YbHQ4fLbj/vJ65mY%40localhost.


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

* Re: Two treatments of same input file
  2021-12-09  9:48   ` Bastien DUMONT
@ 2021-12-09 20:29     ` Gregory D. Weber
  0 siblings, 0 replies; 7+ messages in thread
From: Gregory D. Weber @ 2021-12-09 20:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On Thu, 2021-12-09 at 09:48 +0000, Bastien DUMONT wrote:
> You can handle all of this using a Lua filter. 

I suspected the answer might lie in that direction.  So now it's time for me to
learn some Lua.  Okay, thanks for your advice!

> Assuming that your first heading will always start with "A" and the second
> with "Code to Produce a", I rewrote slightly your input in test.md:
> 
> ```
> ~~~ {.html heading="Form with a Button"}
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> ~~~
> ```
> 
> Then I wrote in test.lua:
> 
> ```
> local HEADING_LEVEL = 2
> 
> function CodeBlock(block)
>   if block.attr.attributes.heading then
>     local raw_heading = block.attr.attributes.heading
>     local html_object_heading = pandoc.Header(HEADING_LEVEL, 'A ' ..
> raw_heading)
>     local html_object = pandoc.RawBlock('html5', block.text)
>     local code_block_heading = pandoc.Header(HEADING_LEVEL, 'Code to produce a
> ' .. raw_heading)
>     return { html_object_heading, html_object, code_block_heading, block }
>   end
> end
> ```
> 
> With the command pandoc test.md -L test.lua, I got the desired result.
> 
> You may want to modify it in order to adapt it to your real needs (like
> setting a "header-level" attribute on your raw block, etc.)
> 
> Le Wednesday 08 December 2021 à 06:52:34PM, Gregory Weber a écrit :
> > I'm work on creating a set of examples of HTML, JavaScript, and SVG code.
> > Each comes from a single source file, from which I want to produce a
> > web page showing
> > (a) the result of rendering the HTML or SVG or executing the JavaScript;
> > (b) the code itself, viewed as if in a text editor, and (ideally) with
> > syntax highlighting.
> > 
> > The best way I can think of doing this involves making two
> > transformations of the source file, running pandoc on each of them,
> > and the combining the outputs, probably by running pandoc a third time
> > with a custom template.
> > 
> > I'm wondering if there's any better way?
> > 
> > Here's a small example:
> > 
> > (1) Original source file:
> > 
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > 
> > 
> > (2) Intermediate file 1:
> > 
> > ```{=html5}
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > ```
> > 
> > (3) Intermediate file 2:
> > 
> > ~~~~{.html}
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > ~~~~
> > 
> > (4) Desired final output would be something like this:
> > 
> > ...
> > 
> > <h2>A Form with a Button</h2>
> > 
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > 
> > <h2>Code to Produce a Form with a Button</h2>
> > 
> > <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class=
> > "sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span
> > class="kw">&
> > lt;form&gt;</span></a>
> > <a class="sourceLine" id="cb1-2" title="2"><span class="kw">&lt;input</span>
> > <span class="ot"> id=</span><span class="st">&quot;b1&quot;</span><span
> > class=
> > "ot"> type=</span><span class="st">&quot;button&quot;</span><span
> > class="ot">
> > value=</span><span class="st">&quot;Apply&quot;</span><span class="ot">
> > title=
> > </span><span class="st">&quot;Button&quot;</span><span
> > class="kw">/&gt;</span>
> > </a>
> > <a class="sourceLine" id="cb1-3" title="3"><span class="kw">&lt;/form&gt;</
> > span></a></code></pre></div>
> > 
> > ...
> > 
> > 
> > --
> > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [2]
> > https://groups.google.com/d/msgid/
> > pandoc-discuss/736c254f-44fe-49f8-9556-2f4c83c4e5a0n%40googlegroups.com.
> > 
> > References:
> > 
> > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2] 
> > https://groups.google.com/d/msgid/pandoc-discuss/736c254f-44fe-49f8-9556-2f4c83c4e5a0n%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
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/40aa7ce4ce0d3663e7060018f7366f2a940462c8.camel%40gmail.com.


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

* Re: Two treatments of same input file
       [not found] ` <736c254f-44fe-49f8-9556-2f4c83c4e5a0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2021-12-09  9:48   ` Bastien DUMONT
@ 2021-12-10 15:39   ` Sébastien Boisgérault
       [not found]     ` <84047109-8502-490c-82fe-0104c3dfcfbdn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Sébastien Boisgérault @ 2021-12-10 15:39 UTC (permalink / raw)
  To: pandoc-discuss


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



Le jeudi 9 décembre 2021 à 03:52:34 UTC+1, spotte...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :

> I'm work on creating a set of examples of HTML, JavaScript, and SVG code.
> Each comes from a single source file, from which I want to produce a
> web page showing
> (a) the result of rendering the HTML or SVG or executing the JavaScript;
> (b) the code itself, viewed as if in a text editor, and (ideally) with
> syntax highlighting.
>
> The best way I can think of doing this involves making two
> transformations of the source file, running pandoc on each of them,
> and the combining the outputs, probably by running pandoc a third time
> with a custom template.
>
> I'm wondering if there's any better way?
>

IMHO, you only need one call to pandoc: if you're ok with Python and with 
the pandoc python library (https://pypi.org/project/pandoc/), you could use 
the following showcase.py script :

# file: showcase.py
import sys
import pandoc
from pandoc.types import Pandoc, Meta, CodeBlock, RawBlock

if __name__ == "__main__":
filename = sys.argv[1]
with open(filename) as html_file:
html = html_file.read()
html_block = RawBlock("html", html)
attr = ("", ["html"], [])
code_block = CodeBlock(attr, html)
doc = Pandoc(Meta({}), [html_block, code_block])
with open("out.html", "bw") as output:
pandoc.write(doc, file=output, format="html", options=["--standalone"])

Then, if you call

    $ python -m showcase.py form.html

where form.html is the HTML file

<form>
  <input id="b1" type="button" value="Apply" title="Button"/>
</form>

you will end up with the desired output in the file "out.html".

Cheers,

SB
 

>
> Here's a small example:
>
> (1) Original source file:
>
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
>
>
> (2) Intermediate file 1:
>
> ```{=html5}
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> ```
>
> (3) Intermediate file 2:
>
> ~~~~{.html}
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> ~~~~
>
> (4) Desired final output would be something like this:
>
> ...
>
> <h2>A Form with a Button</h2>
>
> <form>
> <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
>
> <h2>Code to Produce a Form with a Button</h2>
>
> <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code 
> class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span 
> class="kw">&lt;form&gt;</span></a>
> <a class="sourceLine" id="cb1-2" title="2"><span 
> class="kw">&lt;input</span><span class="ot"> id=</span><span 
> class="st">&quot;b1&quot;</span><span class="ot"> type=</span><span 
> class="st">&quot;button&quot;</span><span class="ot"> value=</span><span 
> class="st">&quot;Apply&quot;</span><span class="ot"> title=</span><span 
> class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span></a>
> <a class="sourceLine" id="cb1-3" title="3"><span 
> class="kw">&lt;/form&gt;</span></a></code></pre></div>
>
> ...
>
>

-- 
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/84047109-8502-490c-82fe-0104c3dfcfbdn%40googlegroups.com.

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

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

* Re: Two treatments of same input file
       [not found]     ` <84047109-8502-490c-82fe-0104c3dfcfbdn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-12-11  0:08       ` Gregory D. Weber
       [not found]         ` <fe5098cf12d71f2224fe6416f351e39c23a3fd26.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Gregory D. Weber @ 2021-12-11  0:08 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

This might work better for me since I am much more familiar with Python than
Lua.  I didn't know there was a Pandoc library for Python!  Thanks very much.

On Fri, 2021-12-10 at 07:39 -0800, Sébastien Boisgérault wrote:
> 
> 
> Le jeudi 9 décembre 2021 à 03:52:34 UTC+1, spotte...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :
> > I'm work on creating a set of examples of HTML, JavaScript, and SVG code.
> > Each comes from a single source file, from which I want to produce a
> > web page showing
> > (a) the result of rendering the HTML or SVG or executing the JavaScript;
> > (b) the code itself, viewed as if in a text editor, and (ideally) with
> > syntax highlighting.
> > 
> > The best way I can think of doing this involves making two
> > transformations of the source file, running pandoc on each of them,
> > and the combining the outputs, probably by running pandoc a third time
> > with a custom template.
> > 
> > I'm wondering if there's any better way?
> 
> IMHO, you only need one call to pandoc: if you're ok with Python and with the
> pandoc python library (https://pypi.org/project/pandoc/), you could use the
> following showcase.py script :
> 
> # file: showcase.py
> import sys
> import pandoc
> from pandoc.types import Pandoc, Meta, CodeBlock, RawBlock
> 
> if __name__ == "__main__":
>     filename = sys.argv[1]
>     with open(filename) as html_file:
>         html = html_file.read()
>         html_block = RawBlock("html", html)
>         attr = ("", ["html"], [])
>         code_block = CodeBlock(attr, html)
>         doc = Pandoc(Meta({}), [html_block, code_block])
>         with open("out.html", "bw") as output:
>             pandoc.write(doc, file=output, format="html", options=["
> --standalone"])
> 
> Then, if you call
> 
>     $ python -m showcase.py form.html
> 
> where form.html is the HTML file
> 
> <form>
>   <input id="b1" type="button" value="Apply" title="Button"/>
> </form>
> 
> you will end up with the desired output in the file "out.html".
> 
> Cheers,
> 
> SB
>  
> > Here's a small example:
> > 
> > (1) Original source file:
> > 
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > 
> > 
> > (2) Intermediate file 1:
> > 
> > ```{=html5}
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > ```
> > 
> > (3) Intermediate file 2:
> > 
> > ~~~~{.html}
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > ~~~~
> > 
> > (4) Desired final output would be something like this:
> > 
> > ...
> > 
> > <h2>A Form with a Button</h2>
> > 
> > <form>
> > <input id="b1" type="button" value="Apply" title="Button"/>
> > </form>
> > 
> > <h2>Code to Produce a Form with a Button</h2>
> > 
> > <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code
> > class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span
> > class="kw">&lt;form&gt;</span></a>
> > <a class="sourceLine" id="cb1-2" title="2"><span
> > class="kw">&lt;input</span><span class="ot"> id=</span><span
> > class="st">&quot;b1&quot;</span><span class="ot"> type=</span><span
> > class="st">&quot;button&quot;</span><span class="ot"> value=</span><span
> > class="st">&quot;Apply&quot;</span><span class="ot"> title=</span><span
> > class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span></a>
> > <a class="sourceLine" id="cb1-3" title="3"><span
> > class="kw">&lt;/form&gt;</span></a></code></pre></div>
> > 
> > ...
> > 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google
> Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/pandoc-discuss/mfaEmeNEx7o/unsubscribe.
> To unsubscribe from this group and all its topics, 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/84047109-8502-490c-82fe-0104c3dfcfbdn%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/fe5098cf12d71f2224fe6416f351e39c23a3fd26.camel%40gmail.com.


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

* Re: Two treatments of same input file
       [not found]         ` <fe5098cf12d71f2224fe6416f351e39c23a3fd26.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-12-11 22:23           ` Sébastien Boisgérault
       [not found]             ` <b7669818-66ed-4336-af6e-f41eec4cd6f5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Sébastien Boisgérault @ 2021-12-11 22:23 UTC (permalink / raw)
  To: pandoc-discuss


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



Le samedi 11 décembre 2021 à 01:08:47 UTC+1, spotte...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :

> This might work better for me since I am much more familiar with Python 
> than 
> Lua. I didn't know there was a Pandoc library for Python! 


There are actually 3 Pandoc librairies for Python (that I know of):

  - pandocfilters: 
https://pandoc.org/filters.html#but-i-dont-want-to-learn-haskell

  - panflute: http://scorreia.com/software/panflute/

  - pandoc (Python): https://boisgera.github.io/pandoc/

Cheers,

SB

 

> Thanks very much. 
>
> On Fri, 2021-12-10 at 07:39 -0800, Sébastien Boisgérault wrote: 
> > 
> > 
> > Le jeudi 9 décembre 2021 à 03:52:34 UTC+1, spotte...-Re5JQEeQqe8@public.gmane.orgm a écrit 
> : 
> > > I'm work on creating a set of examples of HTML, JavaScript, and SVG 
> code. 
> > > Each comes from a single source file, from which I want to produce a 
> > > web page showing 
> > > (a) the result of rendering the HTML or SVG or executing the 
> JavaScript; 
> > > (b) the code itself, viewed as if in a text editor, and (ideally) with 
> > > syntax highlighting. 
> > > 
> > > The best way I can think of doing this involves making two 
> > > transformations of the source file, running pandoc on each of them, 
> > > and the combining the outputs, probably by running pandoc a third time 
> > > with a custom template. 
> > > 
> > > I'm wondering if there's any better way? 
> > 
> > IMHO, you only need one call to pandoc: if you're ok with Python and 
> with the 
> > pandoc python library (https://pypi.org/project/pandoc/), you could use 
> the 
> > following showcase.py script : 
> > 
> > # file: showcase.py 
> > import sys 
> > import pandoc 
> > from pandoc.types import Pandoc, Meta, CodeBlock, RawBlock 
> > 
> > if __name__ == "__main__": 
> > filename = sys.argv[1] 
> > with open(filename) as html_file: 
> > html = html_file.read() 
> > html_block = RawBlock("html", html) 
> > attr = ("", ["html"], []) 
> > code_block = CodeBlock(attr, html) 
> > doc = Pandoc(Meta({}), [html_block, code_block]) 
> > with open("out.html", "bw") as output: 
> > pandoc.write(doc, file=output, format="html", options=[" 
> > --standalone"]) 
> > 
> > Then, if you call 
> > 
> > $ python -m showcase.py form.html 
> > 
> > where form.html is the HTML file 
> > 
> > <form> 
> > <input id="b1" type="button" value="Apply" title="Button"/> 
> > </form> 
> > 
> > you will end up with the desired output in the file "out.html". 
> > 
> > Cheers, 
> > 
> > SB 
> > 
> > > Here's a small example: 
> > > 
> > > (1) Original source file: 
> > > 
> > > <form> 
> > > <input id="b1" type="button" value="Apply" title="Button"/> 
> > > </form> 
> > > 
> > > 
> > > (2) Intermediate file 1: 
> > > 
> > > ```{=html5} 
> > > <form> 
> > > <input id="b1" type="button" value="Apply" title="Button"/> 
> > > </form> 
> > > ``` 
> > > 
> > > (3) Intermediate file 2: 
> > > 
> > > ~~~~{.html} 
> > > <form> 
> > > <input id="b1" type="button" value="Apply" title="Button"/> 
> > > </form> 
> > > ~~~~ 
> > > 
> > > (4) Desired final output would be something like this: 
> > > 
> > > ... 
> > > 
> > > <h2>A Form with a Button</h2> 
> > > 
> > > <form> 
> > > <input id="b1" type="button" value="Apply" title="Button"/> 
> > > </form> 
> > > 
> > > <h2>Code to Produce a Form with a Button</h2> 
> > > 
> > > <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code 
> > > class="sourceCode html"><a class="sourceLine" id="cb1-1" 
> title="1"><span 
> > > class="kw">&lt;form&gt;</span></a> 
> > > <a class="sourceLine" id="cb1-2" title="2"><span 
> > > class="kw">&lt;input</span><span class="ot"> id=</span><span 
> > > class="st">&quot;b1&quot;</span><span class="ot"> type=</span><span 
> > > class="st">&quot;button&quot;</span><span class="ot"> 
> value=</span><span 
> > > class="st">&quot;Apply&quot;</span><span class="ot"> 
> title=</span><span 
> > > class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span></a> 
> > > <a class="sourceLine" id="cb1-3" title="3"><span 
> > > class="kw">&lt;/form&gt;</span></a></code></pre></div> 
> > > 
> > > ... 
> > > 
> > 
> > -- 
> > You received this message because you are subscribed to a topic in the 
> Google 
> > Groups "pandoc-discuss" group. 
> > To unsubscribe from this topic, visit 
> > https://groups.google.com/d/topic/pandoc-discuss/mfaEmeNEx7o/unsubscribe. 
>
> > To unsubscribe from this group and all its topics, send an email to 
> > pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/pandoc-discuss/84047109-8502-490c-82fe-0104c3dfcfbdn%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/b7669818-66ed-4336-af6e-f41eec4cd6f5n%40googlegroups.com.

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

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

* Re: Two treatments of same input file
       [not found]             ` <b7669818-66ed-4336-af6e-f41eec4cd6f5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-12-16  1:16               ` Gregory Weber
  0 siblings, 0 replies; 7+ messages in thread
From: Gregory Weber @ 2021-12-16  1:16 UTC (permalink / raw)
  To: pandoc-discuss


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

Too many good options!
I've decided to work with the Lua filters, since they are more efficient 
and Lua is built into Pandoc, for now.  And it is working pretty well for 
me so far.

On Saturday, December 11, 2021 at 5:23:35 PM UTC-5 sebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 
wrote:

> Le samedi 11 décembre 2021 à 01:08:47 UTC+1, spotte...-Re5JQEeQqe8@public.gmane.orgm a écrit :
>
>> This might work better for me since I am much more familiar with Python 
>> than 
>> Lua. I didn't know there was a Pandoc library for Python! 
>
>
> There are actually 3 Pandoc librairies for Python (that I know of):
>
>   - pandocfilters: 
> https://pandoc.org/filters.html#but-i-dont-want-to-learn-haskell
>
>   - panflute: http://scorreia.com/software/panflute/
>
>   - pandoc (Python): https://boisgera.github.io/pandoc/
>
> Cheers,
>
> SB
>
>  
>
>> Thanks very much. 
>>
>> On Fri, 2021-12-10 at 07:39 -0800, Sébastien Boisgérault wrote: 
>> > 
>> > 
>> > Le jeudi 9 décembre 2021 à 03:52:34 UTC+1, spotte...@gmail.com a écrit 
>> : 
>> > > I'm work on creating a set of examples of HTML, JavaScript, and SVG 
>> code. 
>> > > Each comes from a single source file, from which I want to produce a 
>> > > web page showing 
>> > > (a) the result of rendering the HTML or SVG or executing the 
>> JavaScript; 
>> > > (b) the code itself, viewed as if in a text editor, and (ideally) 
>> with 
>> > > syntax highlighting. 
>> > > 
>> > > The best way I can think of doing this involves making two 
>> > > transformations of the source file, running pandoc on each of them, 
>> > > and the combining the outputs, probably by running pandoc a third 
>> time 
>> > > with a custom template. 
>> > > 
>> > > I'm wondering if there's any better way? 
>> > 
>> > IMHO, you only need one call to pandoc: if you're ok with Python and 
>> with the 
>> > pandoc python library (https://pypi.org/project/pandoc/), you could 
>> use the 
>> > following showcase.py script : 
>> > 
>> > # file: showcase.py 
>> > import sys 
>> > import pandoc 
>> > from pandoc.types import Pandoc, Meta, CodeBlock, RawBlock 
>> > 
>> > if __name__ == "__main__": 
>> > filename = sys.argv[1] 
>> > with open(filename) as html_file: 
>> > html = html_file.read() 
>> > html_block = RawBlock("html", html) 
>> > attr = ("", ["html"], []) 
>> > code_block = CodeBlock(attr, html) 
>> > doc = Pandoc(Meta({}), [html_block, code_block]) 
>> > with open("out.html", "bw") as output: 
>> > pandoc.write(doc, file=output, format="html", options=[" 
>> > --standalone"]) 
>> > 
>> > Then, if you call 
>> > 
>> > $ python -m showcase.py form.html 
>> > 
>> > where form.html is the HTML file 
>> > 
>> > <form> 
>> > <input id="b1" type="button" value="Apply" title="Button"/> 
>> > </form> 
>> > 
>> > you will end up with the desired output in the file "out.html". 
>> > 
>> > Cheers, 
>> > 
>> > SB 
>> > 
>> > > Here's a small example: 
>> > > 
>> > > (1) Original source file: 
>> > > 
>> > > <form> 
>> > > <input id="b1" type="button" value="Apply" title="Button"/> 
>> > > </form> 
>> > > 
>> > > 
>> > > (2) Intermediate file 1: 
>> > > 
>> > > ```{=html5} 
>> > > <form> 
>> > > <input id="b1" type="button" value="Apply" title="Button"/> 
>> > > </form> 
>> > > ``` 
>> > > 
>> > > (3) Intermediate file 2: 
>> > > 
>> > > ~~~~{.html} 
>> > > <form> 
>> > > <input id="b1" type="button" value="Apply" title="Button"/> 
>> > > </form> 
>> > > ~~~~ 
>> > > 
>> > > (4) Desired final output would be something like this: 
>> > > 
>> > > ... 
>> > > 
>> > > <h2>A Form with a Button</h2> 
>> > > 
>> > > <form> 
>> > > <input id="b1" type="button" value="Apply" title="Button"/> 
>> > > </form> 
>> > > 
>> > > <h2>Code to Produce a Form with a Button</h2> 
>> > > 
>> > > <div class="sourceCode" id="cb1"><pre class="sourceCode html"><code 
>> > > class="sourceCode html"><a class="sourceLine" id="cb1-1" 
>> title="1"><span 
>> > > class="kw">&lt;form&gt;</span></a> 
>> > > <a class="sourceLine" id="cb1-2" title="2"><span 
>> > > class="kw">&lt;input</span><span class="ot"> id=</span><span 
>> > > class="st">&quot;b1&quot;</span><span class="ot"> type=</span><span 
>> > > class="st">&quot;button&quot;</span><span class="ot"> 
>> value=</span><span 
>> > > class="st">&quot;Apply&quot;</span><span class="ot"> 
>> title=</span><span 
>> > > class="st">&quot;Button&quot;</span><span class="kw">/&gt;</span></a> 
>> > > <a class="sourceLine" id="cb1-3" title="3"><span 
>> > > class="kw">&lt;/form&gt;</span></a></code></pre></div> 
>> > > 
>> > > ... 
>> > > 
>> > 
>> > -- 
>> > You received this message because you are subscribed to a topic in the 
>> Google 
>> > Groups "pandoc-discuss" group. 
>> > To unsubscribe from this topic, visit 
>> > 
>> https://groups.google.com/d/topic/pandoc-discuss/mfaEmeNEx7o/unsubscribe. 
>>
>> > To unsubscribe from this group and all its topics, send an email to 
>> > pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
>> > To view this discussion on the web visit 
>> > 
>> https://groups.google.com/d/msgid/pandoc-discuss/84047109-8502-490c-82fe-0104c3dfcfbdn%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/7a7009c9-67b2-4cc4-81ac-6c5431d6259bn%40googlegroups.com.

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

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

end of thread, other threads:[~2021-12-16  1:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09  2:52 Two treatments of same input file Gregory Weber
     [not found] ` <736c254f-44fe-49f8-9556-2f4c83c4e5a0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-09  9:48   ` Bastien DUMONT
2021-12-09 20:29     ` Gregory D. Weber
2021-12-10 15:39   ` Sébastien Boisgérault
     [not found]     ` <84047109-8502-490c-82fe-0104c3dfcfbdn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-11  0:08       ` Gregory D. Weber
     [not found]         ` <fe5098cf12d71f2224fe6416f351e39c23a3fd26.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-12-11 22:23           ` Sébastien Boisgérault
     [not found]             ` <b7669818-66ed-4336-af6e-f41eec4cd6f5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-16  1:16               ` Gregory Weber

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