From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/25322 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: K4zuki Newsgroups: gmane.text.pandoc Subject: Re: Panflute filter: wrapping code block with docx custom style without losing syntax highlighting Date: Wed, 3 Jun 2020 01:16:43 -0700 (PDT) Message-ID: <5eb81ba3-1b07-4207-8b73-8cb95ded3167@googlegroups.com> References: <7f65d550-17ce-474a-b830-31ff8b1d78b3@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_122_1578953231.1591172203422" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="22825"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCY7J2HL3ALBB3FY3X3AKGQEYJMJY2I-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 03 10:16:47 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f61.google.com ([209.85.210.61]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jgOZr-0005p0-Ht for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 03 Jun 2020 10:16:47 +0200 Original-Received: by mail-ot1-f61.google.com with SMTP id t10sf1005556otl.19 for ; Wed, 03 Jun 2020 01:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=t0F9x3hMdWBGNUuRgaUxtHJZjy76f7EIAsXpuFb2pec=; b=M9s/yeV0129ev1D4l6gR8H/cPIcnj9dO8J2gpNZngFwr/I1OlGpr9qUMDA752qLbfU sV6GXS5JxMHsCrz7H4rYKyNk9BckklkDGmZaTae79va6Y4Q9S9EldwxUnDOUbjc6mH+K UsJcmJP+8bWSqgZmNdzxaCxbqUrwhKsPnjUDdXKJdrnXjfT61lFZ4xpl4pkGtFu+HCZ1 /aRiQ3nYAqrbh0QWhmn+fG0tWXAQqksukgsp0xsxFdNsfaQ119wxvIlNeIlBqyS7kDVy v7z1Bznl5WTQm1g/quk/mOdPe8bTDmaFuONxqlt87oOCgSvLQqpachjJhkISMJi1QlMQ iRPQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; 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=t0F9x3hMdWBGNUuRgaUxtHJZjy76f7EIAsXpuFb2pec=; b=b+fuMqJNBoT/p51rBMD1V9njWuu4kw0sPmrM2KV9F30+9fdu8GTYuaKhDyOvKvV8PG rs9JNR3kFb2+HOIvW1bv9RtaGMTUlG3zSi3goaZpyGsHxlXB+j1NgEEGdDZHBSPKnJ4M zf/Ej4a34tt0cwfLWkhAn5lO8O6v3G89Zz+e9QnV+Q8o77qQ/EhnP48Raswg5cxLXSgM 9goP1LglrVgO61bPUY2SGugq80BSVYagxPYtHLNhsfxbVMOtUYFZyBd0Rc5hlv1PVVSr iOrOEfjgxkrao8v9kV8ZyGaL9TA+YMyHGqTRpJI6i32ebHilCgXqhTq13bfLn2vdmIkq N52g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=t0F9x3hMdWBGNUuRgaUxtHJZjy76f7EIAsXpuFb2pec=; b=Byx1moOgW3DRZPDt5YXggvz2WIZyrAIJl80+Wb85kLoUvGWBTT2iTyzs05FOlo7flc MlnmRli+APZwUA7aDzZ/IPm1+2TlUYNaOk70+WdXKKRn+G1c+kCUm5Ob7ufsxTUB7KWX 6EGqfMefd9HnHRGV3uRobnGkh4svPAOTkMcC7tGL7oY/KoZGIM2iiGayD/JtnU7vD9k2 vwptk98yZLaW3ts2e/W3AZDEcwfYA830Mlad4ShT+jNEo+x7uToo5WYhMIAFCDQUAooI QwWUuInziwOTLmPrtAIETVWpo/b2p3kHpU5QgarF2lRRgf4pHErXs3UPVHMrHDgH2SSc ShiQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532InuwlDplws/HyneNizaR79akeWGXkaKWDt6+8VuNUW1XPpOlv GyddYjtyzGAt1l8dTM4ar9Q= X-Google-Smtp-Source: ABdhPJxmDHj6qtrs5ZvJgT06mrAj7G0mk+YypsaE4Guorv53wShokn2qaL9Pd8btj9Dar8oBkVwlHg== X-Received: by 2002:aca:b582:: with SMTP id e124mr5594638oif.136.1591172206617; Wed, 03 Jun 2020 01:16:46 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:7d0d:: with SMTP id v13ls278694otn.3.gmail; Wed, 03 Jun 2020 01:16:44 -0700 (PDT) X-Received: by 2002:a9d:2de6:: with SMTP id g93mr2491671otb.28.1591172204172; Wed, 03 Jun 2020 01:16:44 -0700 (PDT) In-Reply-To: <7f65d550-17ce-474a-b830-31ff8b1d78b3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: k.yamamoto.08136891-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:25322 Archived-At: ------=_Part_122_1578953231.1591172203422 Content-Type: multipart/alternative; boundary="----=_Part_123_1819438594.1591172203422" ------=_Part_123_1819438594.1591172203422 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, I tried similar thing also by filters but finally chose two-pass processing= =20 cooperating with python-docx package: The 1st pass converts from your source to docx by pandoc, using a custom=20 template that contains the "Source Code Boxed" style. The standard "Source= =20 Code" style is applied for CodeBlock at this moment. The 2nd pass finds paragraphs that "Source Code" paragraph style is applied= =20 and replace by "Source Code Boxed" style. See also: https://github.com/K4zuki/docx-core-property-writer/blob/78688b7aae93244511= cafb15f9213c4cb294b65b/docx_coreprop_writer/__init__.py#L362 Hope this helps, K4zuki / Kazuki 2020=E5=B9=B45=E6=9C=8816=E6=97=A5=E5=9C=9F=E6=9B=9C=E6=97=A5 7=E6=99=8249= =E5=88=8616=E7=A7=92 UTC+9 Vittorio Romeo: > > Hello, I am trying to write a filter to find all code blocks and wrap the= m=20 > into a custom `.docx` style. This is what I tried: > > if type(elem) =3D=3D pf.CodeBlock: > return pf.Div(elem, attributes=3D{'custom-style': 'Source Code=20 > Boxed'}) > > However, that doesn't work - it seems that the syntax highlighting styles= =20 > override my desired `'Source Code Boxed'` style. I found a workaround, bu= t=20 > it is ugly, and loses all the syntax highlighting: > > if type(elem) =3D=3D pf.CodeBlock: > elemStr =3D pf.stringify(elem) > lines =3D [pf.LineItem(pf.Str(x)) for x in elemStr.splitlines()] > return pf.Div(pf.LineBlock(*lines),=20 > attributes=3D{ 'custom-style': 'Source Code Boxed'}) > > The above works (it surrounds my code block in a box in my final `.docx`= =20 > output), but all syntax highlighting is lost. > > **Is there a way to achieve my desired result?** I would the code being= =20 > surrounded in a box (thanks to my `'Source Code Boxed'` style), but still= =20 > retain its syntax highlighting. > > I have the same problem with TableCell, by the way. > --=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/5eb81ba3-1b07-4207-8b73-8cb95ded3167%40googlegroups.com. ------=_Part_123_1819438594.1591172203422 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I tried similar thing also by fi= lters but finally chose two-pass processing cooperating with python-docx pa= ckage:

The 1st pass converts from your source to d= ocx by pandoc, using a custom template that contains the "Source Code = Boxed" style. The standard "Source Code" style is applied fo= r CodeBlock at this moment.
The 2nd pass finds paragraphs that &q= uot;Source Code" paragraph style is applied and replace by "Sourc= e Code Boxed" style.

See also:
http= s://github.com/K4zuki/docx-core-property-writer/blob/78688b7aae93244511cafb= 15f9213c4cb294b65b/docx_coreprop_writer/__init__.py#L362

=
Hope this helps,
K4zuki / Kazuki

2020=E5= =B9=B45=E6=9C=8816=E6=97=A5=E5=9C=9F=E6=9B=9C=E6=97=A5 7=E6=99=8249=E5=88= =8616=E7=A7=92 UTC+9 Vittorio Romeo:
Hello, I am trying to write a filter to find al= l code blocks and wrap them into a custom `.docx` style. This is what I tri= ed:

if type(elem) =3D=3D pf.CodeBlock:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return pf.Div(elem, att= ributes=3D{'custom-style': 'Source Code Boxed'})

However, that doesn't work - it seem= s that the syntax highlighting styles override my desired `'Source Code= Boxed'` style. I found a workaround, but it is ugly, and loses all the= syntax highlighting:

if type(elem) =3D=3D pf.CodeBlock:
<= div>=C2=A0 =C2=A0 elemStr =3D pf.stri= ngify(elem)
=C2=A0 = =C2=A0 lines =3D [pf.LineItem(pf.Str(x)) for x in elemStr.splitlines()]
=C2=A0 =C2=A0 return pf= .Div(pf.LineBlock(*lines),=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 attributes=3D{ '= custom-style': 'Source Code Boxed'})

The above works (it surrounds my code block in a box in = my final `.docx` output), but all syntax highlighting is lost.
**Is there a way to achieve my desired result?** I would the c= ode being surrounded in a box (thanks to my `'Source Code Boxed'` s= tyle), but still retain its syntax highlighting.

I have the same pro= blem with TableCell, by the way.

--
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/5eb81ba3-1b07-4207-8b73-8cb95ded3167%40googlegroups.co= m.
------=_Part_123_1819438594.1591172203422-- ------=_Part_122_1578953231.1591172203422--