From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31964 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: NOTE and WARNING in DocBook -> Word conversions Date: Fri, 6 Jan 2023 23:32:26 +0100 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000005ff50605f19ffe5c" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7331"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBAWD4KOQMGQE6SQXGXI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 06 23:32:38 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-vk1-f189.google.com ([209.85.221.189]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pDvGQ-0001jj-6U for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 06 Jan 2023 23:32:38 +0100 Original-Received: by mail-vk1-f189.google.com with SMTP id r23-20020a1f2b17000000b003b89463c349sf929295vkr.0 for ; Fri, 06 Jan 2023 14:32:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673044357; cv=pass; d=google.com; s=arc-20160816; b=BzX9lfBSt6/rCePspfvjMTeGyNUF7IX0tfx8IPa0ltdoEPfHKMhia4AHhVdulQGR3Y UOfe/zIdDmKWsVnj7IhFIpyOrYz29wLU/+R6DuDJwa3pS5ISeNfhm+Uyy7+qcJKQW9tm aCbTDHk2QJ/4pS3WncKLXd/NSqAEMWvA7LO9OarwWDdTpiuis8es53Iwu47vNUgw342w 0JVE9ZKsfSxapWKhZO2d97AJjgaWK6n5BvqinHxwvNMu8jM5GprAjquHXD+vN+jOZeQd l4+kvM9XxAQzNe2tCoFpJgbOrmsiXLcYP3X2L+bxd6DD4Key+hk+D+kGCinfD0SC5kKv 2MBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:sender:dkim-signature; bh=9YZWwYdd1PoAKNWbXYrJyCrvjzUkYTOy3Tx6cL4OYtk=; b=c7tLnJpazRTdwHUHpeVZuOheQaPz08ULjWsd/RMsvD8HKmQqFvGUSu3xrdvwd+s1Rg miZy0Np2w6m9lGGF2sAjNhM7XHMQi6LTLqSrnkB4yLXDjPgn5gPLwbG5La0NJMnCrVuz k915Ym2xMXMqL75p+u10OaZzjX341IvlKaV9P8+6QedFEwJKXRDWRmABhEpgmMkojlZ/ LNtzrIUNtP3VdvjOWkkSESdq4PI33/n1Vvv8am7WFUmAHVBaPcamJWfrzUbykSYAS7EF jcLF6KT5nCTdTVF5rDCd8nFMVxsrvxxgY/kJot09X7zcWZC9nhnM+8/CQapbzgt6zBGq 15Lg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.173 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:to:subject:message-id:date:from:reply-to :in-reply-to:references:mime-version:sender:from:to:cc:subject:date :message-id:reply-to; bh=9YZWwYdd1PoAKNWbXYrJyCrvjzUkYTOy3Tx6cL4OYtk=; b=rxt2wLUAbqvbBdhmwwjMtVLZ0jxma/j42Z/w5uYnUoRacK40LfA7FIcLm/iJCszgxN 8sgjT44jvBLAQNU2JhStmiyzzZb8TTZKqXxvsBY/L62EBw2c3NGrOtr+9r3ROOLXjk4l 5YOK0Zs3VtOEA/sEuduJPpY9sc9F3LoLW4xvb1xVvZhG8rT79NwYQdsJWB+mCMyDmLPO pEQf7kdCNo95aPXFoj9iRCSVDcP0iESRk90p8I1b6PlvBjH+F1WqFMpekjABX3pwnwe6 1dVCygLOOq2t/D64GNqh74aZck9GuFh/zyDh1AqzOFlJc4quzPvnJ4XKY55JMFhCtmuK MPww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:to:subject :message-id:date:from:reply-to:in-reply-to:references:mime-version :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=9YZWwYdd1PoAKNWbXYrJyCrvjzUkYTOy3Tx6cL4OYtk=; b=KIfhaKDF6FUFmAqAymvy6eUGWLvo1it5bZI+BFdt+HoYfUJZbOizbOjAtL4VK+qi2M GdE0RFGxvbjFNpIJoToH4EKBp+5rIV0htNWJ1tVzsFaaumz1VE6kGLZtRL9OOiDioQnE NGiiJhs9JYEYCpsNSdHJXIAUP/Zk/qG0EOZhkg9UGxW41Boe/tatBlAMaNa8oOirXOha Hf4qs4BIaKtf1hZSQ/gVWV0v72Nd33+AT4a0wUtfxKPJ/yjoj+WC2AVKaKTUl2pNC0T/ gXNjn5Cnsc2eoNDQpGaNDII9aS2mLsXFOVRU4vp4ZLcAdL Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2koFqR1Sebfl6QAX+M/7om1kI8E8kA/qYkQWSv9Ymq39HE/SpwL0 lKJ1U4n3j9qxb4G7fXtAwkE= X-Google-Smtp-Source: AMrXdXtwwLapayUgBg9s9mVIHB3rKgoyMhDM/kyzNDpK0Id4+BNLcUxJ5OZL1omJp+4yE+v7TKNSuQ== X-Received: by 2002:a05:6102:440a:b0:3bd:e865:72d4 with SMTP id df10-20020a056102440a00b003bde86572d4mr6757954vsb.32.1673044357156; Fri, 06 Jan 2023 14:32:37 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a67:c207:0:b0:3c9:2128:4bfc with SMTP id i7-20020a67c207000000b003c921284bfcls113070vsj.5.-pod-prod-gmail; Fri, 06 Jan 2023 14:32:34 -0800 (PST) X-Received: by 2002:a67:b306:0:b0:3aa:1665:5eae with SMTP id a6-20020a67b306000000b003aa16655eaemr26748415vsm.14.1673044353936; Fri, 06 Jan 2023 14:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673044353; cv=none; d=google.com; s=arc-20160816; b=ynv8lVOolNoMlYoypJ2sdnMDmv1fhXfhWN5RhLClbMJ1Wpcf16Oe948GpulRTLJjmF W41tzzJYzNyTX6SK1u38kOGoWDq8RbR3vrOHukB01WBDuN5Lr0vG48hxzRw3bnuPNaZm CUQ3l9D5ODNFthPDKaxEPHeL62OWroocD+Cg4whUHl4/yA4sFB41LfcnKjAlqFeIYwWq PeFHokDdLo1GuqWNXRSQX2CLzBvgwQ3Pq38QvxWDkphsnMe5CG8IyCWhHigCwmxZ0+9P OvX9z8XNZhzoQPGc+4xpOesaKyG+oUciT9+98dq7nQOh3mLg1T3Fo3ObuHbNhaB2cNrO aZ0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version; bh=3CgOu3Kbcz5e7n4SyzK4shmQ5pE4NuUlPWEoFfX+Ai8=; b=Z/xRlSJXmZxRdgxK1iFvLGvbZ7X+mzOvvlQMMhJODxSllu53eeYDHKUEp2r3Wd5yli 3PjJ2GV+iGDxpnkXtu9IW71ggGWx3aifl+83zaBx0LfNakMVqcIw3Q6zrdyzdTVRwJGZ YhWid8qFwkxX+tqpt83KeVoOw6F6MA8uIwks/CRVJ2cIq1X/1dAVAypF/i3UbrE8AUhr W6IzH50KgaLi5z4927XPPhOQsgiyaAiuzDE1lVfO6bFFdlFEoYXPv3LRlacQqbYskCi3 E0VKTyZBam0YT4Y4feT/qU3Kn2pUJvlZfm5U16QXiOPqV7bp7x0vAqg2ecUNu8klY0hL Aq+A== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.173 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com. [209.85.219.173]) by gmr-mx.google.com with ESMTPS id b15-20020a67e98f000000b003980b6c8861si188751vso.2.2023.01.06.14.32.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Jan 2023 14:32:33 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.173 as permitted sender) client-ip=209.85.219.173; Original-Received: by mail-yb1-f173.google.com with SMTP id l139so3315313ybl.12 for ; Fri, 06 Jan 2023 14:32:33 -0800 (PST) X-Received: by 2002:a25:d9d2:0:b0:745:38a3:e608 with SMTP id q201-20020a25d9d2000000b0074538a3e608mr5838550ybg.69.1673044353347; Fri, 06 Jan 2023 14:32:33 -0800 (PST) In-Reply-To: X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.219.173 as permitted sender) smtp.mailfrom=melroch-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:31964 Archived-At: --0000000000005ff50605f19ffe5c Content-Type: text/plain; charset="UTF-8" Since that docbook note element becomes a div with class "note" in the Pandoc AST you can use a Lua filter to modify the AST for divs with such a class, by inserting a paragraph with the "Note" label wrapped in div with a 'custom-style' attribute so that you can apply a custom paragraph style to the paragraph in docx. < https://github.com/jgm/pandoc/wiki/Defining-custom-DOCX-styles-in-LibreOffice-(and-Word) > Here is the Lua filter I use for this admonitions when converting to docx, slightly modified: ``` lua -- Edit this with labels and attributes for admonition div classes local cls_data = { note = { label = 'Note', label_attrs = { ['custom-style'] = 'NoteLabel' }, text_attrs = { -- ['custom-style'] = 'NoteText' } }, warning = { label = 'Warning', label_attrs = { ['custom-style'] = 'WarningLabel' }, text_attrs = { -- ['custom-style'] = 'WarningText' } } } -- Get the pandoc library under a shorter name local p = assert(pandoc, "Cannot find the pandoc library") if not ('table' == type(p)) then error("Expected variable pandoc to be table") end -- Create the label divs for cls, data in pairs(cls_data) do data.label = p.Div({ p.Para({ p.Str(data.label) }) }, data.label_attrs) end -- The filter function function Div (div) for _, cls in ipairs(div.classes) do local data = cls_data[cls] -- get data if any if data then -- if this is an admonition class -- Set the attributes on the div for name, val in pairs(data.text_attrs) do div.attributes[name] = val end -- Return the data and the div return { data.label:clone(), div } end end -- If no class matches return nil end ``` Each key in the table `cls_data` is a class which occurs on a div which should be styled as an admonition. You probably want to add and/or modify entries in this table to match the classes of divs you want to style and the paragraph style names you actually have in your reference-doc.docx. Each value in that table is a table with three fields: 1. `label` is the string you want as text in the label paragraph above the text of the div, e.g. "Note". 2. `label_attrs` is a table with the attributes you want to apply to the div containing the label paragraph, notably the custom-style to apply to the paragraph. 3. `text_attrs` is a table containing attributes you want to apply to the admonition text, i.e. the original div. I have commented out these attributes since a custom-style here will override any paragraph styles which Pandoc might apply to paragraphs inside the original div. _If_ you want a custom-style here you might want ro use it to apply some indentation for example. An alternative strategy might be to turn each admonition into a single-item definition list where the label is the "term" and the div text is the "definition". Please let me know if you want that. See here if you want to write your own Lua filter: Den fre 6 jan. 2023 20:58Joseph Ottinger skrev: > Hi. I have a book written with asciidoctor, from which I generate DocBook, > and that's fed into pandoc to generate Word output. > > However, WARNING and NOTE types aren't rendered very well, I *think* - or > it's entirely possible that they are rendered according to paragraph type > and I just can't tell. > > In the AST, WARNING and NOTE generate XML: > > > > When AsciiDoctor generates HTML, it annotates the content with NOTE: and a > paragraph with the contents of the note. In Word, generated from DocBook, > this annotation (the "NOTE:") is lost. That's sort of understandable, > but... how would one replicate the behavior from the HTML backend? The > DocBook *has* the types; the AST in Pandoc contains a DIV with a class that > maps to NOTE or WARNING, so the context is there, but I have no idea how > I'd update the Word output to reflect the NOTE or WARNING type. > > -- > 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/f05af404-d529-4e22-8334-3a637bc98efcn%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/CADAJKhA-pQMdwO%3DgnDcTAxmNK3QLt5VKaREmxkwuTMWZx6%3DPcQ%40mail.gmail.com. --0000000000005ff50605f19ffe5c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Since that docbook note element becomes= a div with class "note" in the
Pandoc AST= you can use a Lua filter to modify the AST for divs with such
a class, by inserting a paragraph with the "Note" labe= l wrapped in div
with a 'custom-style' attri= bute so that you can apply a custom paragraph
style = to the paragraph in docx.




Here is the Lua filter I use for= this admonitions when converting to
docx, slightly = modified:

``` lua
<= div dir=3D"auto">-- Edit this with labels and attributes for admonition div= classes
local cls_data =3D {
=C2=A0 note =3D {
=C2=A0 =C2=A0 label =3D 'Note= ',
=C2=A0 =C2=A0 label_attrs =3D {
=C2=A0 =C2=A0 =C2=A0 ['custom-style'] =3D 'NoteLabel&= #39;
=C2=A0 =C2=A0 },
=C2=A0 = =C2=A0 text_attrs =3D {
=C2=A0 =C2=A0 =C2=A0 -- [= 9;custom-style'] =3D 'NoteText'
=C2=A0 = =C2=A0 }
=C2=A0 },
=C2=A0 war= ning =3D {
=C2=A0 =C2=A0 label =3D 'Warning'= ,
=C2=A0 =C2=A0 label_attrs =3D {
=C2=A0 =C2=A0 =C2=A0 ['custom-style'] =3D 'WarningLabel= 9;
=C2=A0 =C2=A0 },
=C2=A0 = =C2=A0 text_attrs =3D {
=C2=A0 =C2=A0 =C2=A0 -- [= 9;custom-style'] =3D 'WarningText'
=C2= =A0 =C2=A0 }
=C2=A0 }
}
=

-- Get the pandoc library und= er a shorter name
local p =3D assert(pandoc, "C= annot find the pandoc library")
if not ('ta= ble' =3D=3D type(p)) then
=C2=A0 error("Exp= ected variable pandoc to be table")
end

-- Create the label divs
<= div dir=3D"auto">for cls, data in pairs(cls_data) do
=C2=A0 data.label =3D p.Div({
=C2=A0 =C2=A0 p.Para(= { p.Str(data.label) })
=C2=A0 }, data.label_attrs)
end

-- The filter function
function Div (div)
=C2=A0 for _, cls in ipairs(div.classes) do
=C2=A0 =C2=A0 local data =3D cls_data[cls] -- get data if any
<= div dir=3D"auto">=C2=A0 =C2=A0 if data then -- if this is an admonition cla= ss
=C2=A0 =C2=A0 =C2=A0 -- Set the attributes on the= div
=C2=A0 =C2=A0 =C2=A0 for name, val in pairs(dat= a.text_attrs) do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 div.att= ributes[name] =3D val
=C2=A0 =C2=A0 =C2=A0 end
=
=C2=A0 =C2=A0 =C2=A0 -- Return the data and the div
=
=C2=A0 =C2=A0 =C2=A0 return { data.label:clone(), div }
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 -- If no class matches
= =C2=A0 return nil
end
```

Each key in the table `cls_= data` is a class which occurs on a div which
should = be styled as an admonition. You probably want to add and/or
modify entries in this table to match the classes of divs you wan= t to
style and the paragraph style names you actuall= y have in your
reference-doc.docx.

Each value in that table is a table with = three fields:

1.=C2=A0 `= label` is the string you want as text in the label paragraph above
=C2=A0 =C2=A0 the text of the div, e.g. "Note".

2.=C2=A0 `label_attrs` is = a table with the attributes you want to apply to
=C2= =A0 =C2=A0 the div containing the label paragraph, notably the custom-style= to
=C2=A0 =C2=A0 apply to the paragraph.

3.=C2=A0 `text_attrs` is a table c= ontaining attributes you want to apply to
=C2=A0 =C2= =A0 the admonition text, i.e. the original div. I have commented out
<= div dir=3D"auto">=C2=A0 =C2=A0 these attributes since a custom-style here w= ill override any
=C2=A0 =C2=A0 paragraph styles whic= h Pandoc might apply to paragraphs inside the
=C2=A0= =C2=A0 original div. _If_ you want a custom-style here you might want ro
=C2=A0 =C2=A0 use it to apply some indentation for ex= ample.

An alternative st= rategy might be to turn each admonition into a
singl= e-item definition list where the label is the "term" and the div<= /div>
text is the "definition". Please let me kn= ow if you want that.

See= here if you want to write your own Lua filter:

=


Den fre 6 jan. 2023 20:58Joseph Ottinger <dreamreal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Hi. I have a book written with asciidoctor, from which I gene= rate DocBook, and that's fed into pandoc to generate Word output.
<= br>
However, WARNING and NOTE types aren't rendered very well= , I *think* - or it's entirely possible that they are rendered accordin= g to paragraph type and I just can't tell.

In = the AST, WARNING and NOTE generate XML:

<note><simpara />= ;</note> <!-- for NOTE types, obviously -->

When AsciiDo= ctor generates HTML, it annotates the content with NOTE: and a paragraph wi= th the contents of the note. In Word, generated from DocBook, this annotati= on (the "NOTE:") is lost. That's sort of understandable, but.= .. how would one replicate the behavior from the HTML backend? The DocBook = *has* the types; the AST in Pandoc contains a DIV with a class that maps to= NOTE or WARNING, so the context is there, but I have no idea how I'd u= pdate the Word output to reflect the NOTE or WARNING type.

--
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 pandoc-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f05af404-d= 529-4e22-8334-3a637bc98efcn%40googlegroups.com.

--
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://gro= ups.google.com/d/msgid/pandoc-discuss/CADAJKhA-pQMdwO%3DgnDcTAxmNK3QLt5VKaR= EmxkwuTMWZx6%3DPcQ%40mail.gmail.com.
--0000000000005ff50605f19ffe5c--