From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29753 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?S=C3=A9bastien_Boisg=C3=A9rault?= Newsgroups: gmane.text.pandoc Subject: Re: Two treatments of same input file Date: Fri, 10 Dec 2021 07:39:41 -0800 (PST) Message-ID: <84047109-8502-490c-82fe-0104c3dfcfbdn@googlegroups.com> References: <736c254f-44fe-49f8-9556-2f4c83c4e5a0n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2420_1683806078.1639150781758" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14818"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCIOBSUCXMMRBPXJZWGQMGQESUI5NUI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Dec 10 16:39:46 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f57.google.com ([209.85.161.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mvhzt-0003dv-VA for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 10 Dec 2021 16:39:45 +0100 Original-Received: by mail-oo1-f57.google.com with SMTP id g1-20020a4ab801000000b002c63cddd8f6sf5598937oop.5 for ; Fri, 10 Dec 2021 07:39:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=EF4nO3qa7tBNtqY63W65vFPLrW2y5gcuWXyrcMTYaCw=; b=OJkDg4o+xX4RH6Xz8f1ptYyw0wO3dZNVNGpLtaSPlI8XGrzRXQyyeK3V/APm4VjwgV 6U/Jg9YaNqIroK1XLTRvWfuPCaBuCmZLAWYlKY9cyT4t8TyclA3TVJQo61X8xYsRdaE5 ewG6yhZXPdPicy02FA6SXpW4RRrrR+2tO+G3LG+FXbW1WmPqmPhJkn3dkffVVEYmNym8 /COju4ZoMOwFHQcz0Nv+YsYUBHwtIUONyBXw2G2+0Uzd55hyISlz+6EbkAXWvjC9vavK LLgX5XYU3PmMAwAl6ISyIypCKv3ZBafwzlXLEit1bkonYppkFpIBrmTt/wQ7vIsxlPEk ojBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=EF4nO3qa7tBNtqY63W65vFPLrW2y5gcuWXyrcMTYaCw=; b=NRJPL/LJ6w6Q07SE8nimOgCW8GlDPz5j1xujG4MNc1vzE+d/YSegfzBtIY8T/kgBIk eAEVczsFeoH9pNWZ5XYM/9Jh7JcxUokch4kc60uWvNqTdtEm+NEWUsYisXJBMp0Q/Do2 BCeUJ5ql29DOCrdKe3lF4x8uW4/vz2IwxFxeamDDDqo9TynFVina6SXlVSHLc3WXHF3X LkfewpTypEIsjoGg3mfu+egfOCo4uBbZjCOddOXQIZAp/mzrZbyBks6lfq7zqj/7WEWu /J3OP2kR/RUuvLVu9UPK0lw5Xm+VFh/MajSRmsdHguVA7EAQMijwpQD8cTl/2ayfmeLI Nrlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=EF4nO3qa7tBNtqY63W65vFPLrW2y5gcuWXyrcMTYaCw=; b=gOf6zrwvtajLusZ23pCj67K34FewaIs17hTC0Uejc2HQcV/3d6phXNFOXc3vuC3E0G RqUf6Qs5m/4KAwouz/aBrDkadK58nrdHIrijITKn81cq5RPNZx5QJXE6jDa4xAzScqM8 CmkooPCGLCJrqN5iFVoeG+db0kO3O0HHAwI6LyYKI3Japj1huGXkVBdC4pHHCxOQMgbt 39HkIql+O6WkaLQgcqhhMDirgGxb9kJmdn6g1P5vTbd11ug/+ldJGSeveVuFsCuozrMc hDDrIXbHZdbict+2NDVOG7ecXHifT1HBI4RmiTnHa3tFdOJSuxfVBWYjKKALMXDYgSTx Gfwg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533tu5oDmiEjpw70kQ1BcKUumof9Nj6dTPRs6bpURrp3htCojAPO GLWvbRk8l+iMrhD7UbBt9rM= X-Google-Smtp-Source: ABdhPJxC4IOS/E00mBKjUefvRbA8dR9/BIbFX2rhaeRoTsgUoH1nHDkJQoZYjvMtHQcZanTyc7d/qw== X-Received: by 2002:a05:6808:1686:: with SMTP id bb6mr13298882oib.40.1639150784413; Fri, 10 Dec 2021 07:39:44 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a4a:58c9:: with SMTP id f192ls474201oob.6.gmail; Fri, 10 Dec 2021 07:39:42 -0800 (PST) X-Received: by 2002:a05:6820:388:: with SMTP id r8mr8825637ooj.0.1639150782427; Fri, 10 Dec 2021 07:39:42 -0800 (PST) In-Reply-To: <736c254f-44fe-49f8-9556-2f4c83c4e5a0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: Sebastien.Boisgerault-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:29753 Archived-At: ------=_Part_2420_1683806078.1639150781758 Content-Type: multipart/alternative; boundary="----=_Part_2421_89994857.1639150781758" ------=_Part_2421_89994857.1639150781758 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le jeudi 9 d=C3=A9cembre 2021 =C3=A0 03:52:34 UTC+1, spotte...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a = =C3=A9crit : > 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= =20 the pandoc python library (https://pypi.org/project/pandoc/), you could use= =20 the following showcase.py script : # file: showcase.py import sys import pandoc from pandoc.types import Pandoc, Meta, CodeBlock, RawBlock if __name__ =3D=3D "__main__": filename =3D sys.argv[1] with open(filename) as html_file: html =3D html_file.read() html_block =3D RawBlock("html", html) attr =3D ("", ["html"], []) code_block =3D CodeBlock(attr, html) doc =3D Pandoc(Meta({}), [html_block, code_block]) with open("out.html", "bw") as output: pandoc.write(doc, file=3Doutput, format=3D"html", options=3D["--standalone"= ]) Then, if you call $ python -m showcase.py form.html where form.html is the HTML file
you will end up with the desired output in the file "out.html". Cheers, SB =20 > > Here's a small example: > > (1) Original source file: > >
> >
> > > (2) Intermediate file 1: > > ```{=3Dhtml5} >
> >
> ``` > > (3) Intermediate file 2: > > ~~~~{.html} >
> >
> ~~~~ > > (4) Desired final output would be something like this: > > ... > >

A Form with a Button

> >
> >
> >

Code to Produce a Form with a Button

> > > > ... > > --=20 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 e= mail 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. ------=_Part_2421_89994857.1639150781758 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

L= e jeudi 9 d=C3=A9cembre 2021 =C3=A0 03:52:34 UTC+1, spotte...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a = =C3=A9crit :
I'm work on creating a set of examples of HTML, JavaScript, and SVG cod= e.
Each comes from a single source file, from which I want to produce a<= br>web page showing
(a) the result of rendering the HTML or SVG or execu= ting 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, r= unning pandoc on each of them,
and the combining the outputs, probably b= y running pandoc a third time
with a custom template.

I'm wonderi= ng if there's any better way?

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

# file: showcas= e.py
import sys
import= pandoc
from pandoc.types = import Pandoc, Meta, CodeBlock, RawBlock

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

Then, if you call

    $ python -m showcase.py form.htm= l

where form.html is the HTML file
<= br>
<form>
  <input id=3D"b1" type=3D"button" va= lue=3D"Apply" title=3D"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=3D"b1" ty= pe=3D"button" value=3D"Apply" title=3D"Button"/>
</form>

(2) Intermediate file 1:

```{=3Dhtml5}
<form>
<i= nput id=3D"b1" type=3D"button" value=3D"Apply" title=3D"Button"/>
<= ;/form>
```

(3) Intermediate file 2:

~~~~{.html}
<= ;form>
<input id=3D"b1" type=3D"button" value=3D"Apply" title=3D"B= utton"/>
</form>
~~~~

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

...

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

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

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

<div class=3D"sourceCode"= id=3D"cb1"><pre class=3D"sourceCode html"><code class=3D"sourc= eCode html"><a class=3D"sourceLine" id=3D"cb1-1" title=3D"1"><s= pan class=3D"kw">&lt;form&gt;</span></a>
<a cl= ass=3D"sourceLine" id=3D"cb1-2" title=3D"2"><span class=3D"kw">&am= p;lt;input</span><span class=3D"ot"> id=3D</span><span= class=3D"st">&quot;b1&quot;</span><span class=3D"ot"&g= t; type=3D</span><span class=3D"st">&quot;button&quot;&= lt;/span><span class=3D"ot"> value=3D</span><span class= =3D"st">&quot;Apply&quot;</span><span class=3D"ot"> = title=3D</span><span class=3D"st">&quot;Button&quot;<= ;/span><span class=3D"kw">/&gt;</span></a>
<= a class=3D"sourceLine" id=3D"cb1-3" title=3D"3"><span class=3D"kw">= ;&lt;/form&gt;</span></a></code></pre></= div>

...

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_2421_89994857.1639150781758-- ------=_Part_2420_1683806078.1639150781758--