From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/21665 Path: news.gmane.org!.POSTED!not-for-mail From: Joey Dumont Newsgroups: gmane.text.pandoc Subject: Re: Pandoc + TWiki (writer) output Date: Wed, 12 Dec 2018 05:03:38 -0800 (PST) Message-ID: <6a8f82dc-1d9a-473e-ab21-c6ab413a75ba@googlegroups.com> References: <976a9019-374b-4cc9-b9cf-c2e98e04fed9@googlegroups.com> <2ba0d474-f0db-456e-922a-bb7282e60bf5@googlegroups.com> <5bffbda3-8281-4247-99c2-3826011ec9ca@googlegroups.com> <8631e4f1-8744-40b4-a3ce-a8d8e1bb0202@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_298_1725081935.1544619818779" X-Trace: blaine.gmane.org 1544619699 27216 195.159.176.226 (12 Dec 2018 13:01:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Dec 2018 13:01:39 +0000 (UTC) To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCFIT7VQSAOBBLEOYTQAKGQENDTQTVI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Dec 12 14:01:35 2018 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-oi1-f186.google.com ([209.85.167.186]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gX48o-0006td-6O for gtp-pandoc-discuss@m.gmane.org; Wed, 12 Dec 2018 14:01:30 +0100 Original-Received: by mail-oi1-f186.google.com with SMTP id w128sf9464757oie.20 for ; Wed, 12 Dec 2018 05:03:41 -0800 (PST) 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=9SY7BpOt0b+xiM/PwGj3xjCSfAfo7MjuyeOe2MQRz08=; b=KcWH3dnF2wFMnT63D/4VY5AHHwEGgPVGIqLrh5ANgfiGsFfQ/NTXtRES5U40w2WPuh h8GCU1y303A8o+r+cIrGYH2SObMT+AhLIYrrZlIaYfbyKmTwYtaPmOYh1DNEKuztIL9z 1SNW1bNoDfk+iglM8ICJa8k7i/xH7IGOOZQ9zFBwqXdiWMUPEf1U82Jtj7Nx/KKViRtD /Q8IQayWtTipunBRW+9U1tkj6Nthj9NVEkOhUNJRYP+hOTbMMLp6cesGBHU7E99xJ13A vG2xKwPuSeTRQPXrAyOduUNsmdwetC6lZQiss85z5bfsgTIYtsfXImCSvyEuQYye19j+ e0xA== 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=9SY7BpOt0b+xiM/PwGj3xjCSfAfo7MjuyeOe2MQRz08=; b=DOh96svoIqOJ7cPPD0yLLElEWUdwrvnAlI+Dq2ckZJ1QIPp+cehQ4bZ9+KVf48qO1N hWUJX1lRrzjc/82Zj2U5BVGesMNaBTlqW3B3I8eSZ4zOhdqmFhI3QskM3K5exgCFNEu0 yXLaZ9EmL4Si45e3NdbgV4/JniLjgUT1FQAQnW8rukigAwWezJQlQVvyyXVGoAoeBYA4 az2DuUOtWWUt4hdTdXgIJvt4jSrc67guj4SCLKgpymHDzvzHkS2SpoPWqD7FI6FYqZFa nFs4YG6+MGzlHCh85SGYRdfNiZRDm1c0PLkUGsbEXHOhoaLlcJ6gy3KxZQ0SQ5c79f+m 5oCg== 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=9SY7BpOt0b+xiM/PwGj3xjCSfAfo7MjuyeOe2MQRz08=; b=GIuITwj6b3YZBLBoYFG5swoR5qIBKJkKhH6G7N5GtmMOTPONtZ5mn3MwV4l2iwRZaE hFan0vJwv7tluK8HOekhLs2/zfFceERMmVRjCDqKXFbVKf6Qkuf8t9HojYy8hoyaEG+C +Ce9/JXUEOHDppMqCiEJefwVyoHQbIj6/oTCPJ3HVYniN2pYWArvxf+6L/rsLTCUT6f4 53w753uh9hMmvRSBPx2oQOd3aRT1JhDOS94D/6QGAZrXXClSnAGrOgiOr/luP2CiQV/R a+hcnvbyaQJiInyMIphgoAWZDuBcr7H8Lg6zJwQZ5flVepoF6frfktgKHoXJUiNt0T0Q 9V9Q== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AA+aEWZymKHHntpQBEN1JAPJfY25BkuQZMLfKRBQlCTGjQIU8j6+YFQH CLR5wAaCsuuwqGDo5OkOyJg= X-Google-Smtp-Source: AFSGD/WI2kslpEkzhU94viyiycFkqXi1OxyQ9S6sUe/90pPuP61RfeHRjS6jW9Od7svjfZ0cYG+LZA== X-Received: by 2002:a9d:2c22:: with SMTP id f31mr502767otb.4.1544619820674; Wed, 12 Dec 2018 05:03:40 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:24a7:: with SMTP id z36ls6930954ota.5.gmail; Wed, 12 Dec 2018 05:03:39 -0800 (PST) X-Received: by 2002:a9d:2c22:: with SMTP id f31mr502763otb.4.1544619819496; Wed, 12 Dec 2018 05:03:39 -0800 (PST) In-Reply-To: X-Original-Sender: joey.dumont-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-Spam-Checked-In-Group: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:21665 Archived-At: ------=_Part_298_1725081935.1544619818779 Content-Type: multipart/alternative; boundary="----=_Part_299_450667038.1544619818779" ------=_Part_299_450667038.1544619818779 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Nice! I added this section to escape(),=20 -- For TWiki installations that don't support Unicode. -- We replace some common Unicode-only symbols by their closest ASCII -- counterpart. for p, c in utf8.codes(s) do if (c =3D=3D 0x2019 or c =3D=3D 0x2018) then new_string =3D new_string .. "'" elseif (c =3D=3D 0x201C or c =3D=3D 0x201D) then new_string =3D new_string .. '"' elseif (c =3D=3D 0x00A0) then new_string =3D new_string .. ' ' else new_string =3D new_string .. utf8.char(c) end end return new_string end I haven't gone and fixed accents and stuff, I'll probably add to this as I= =20 need more. Thanks John for all the help, it is appreciated. I've attached the full=20 custom writer in case somebody wants to build on it.=20 Cheers, On Tuesday, December 11, 2018 at 2:05:12 PM UTC-5, John MacFarlane wrote: > > > The problem is that lua's gsub is not really UTF-8=20 > aware. [<>^\"'] will match a single BYTE, but the=20 > quote characters are multibyte.=20 > > You can use the functions documented in sec 6.5=20 > here: https://www.lua.org/manual/5.3/manual.html#6.5.=20 > > These allow you to iterate over the characters in a=20 > string.=20 > > for p, c in utf8.codes(s) do=20 > -- c is the code point (integer) of the character=20 > end=20 > > You can use this to build up a new string, escaping=20 > each code point appropriately.=20 > > > Joey Dumont > writes:=20 > > > I tried that already. My escape function is probably bad then.=20 > >=20 > > -- Character escaping=20 > > local function escape(s, in_attribute)=20 > > return s:gsub("[<>&\"']",=20 > > function(x)=20 > > if x =3D=3D '<' then=20 > > return '<'=20 > > elseif x =3D=3D '>' then=20 > > return '>'=20 > > elseif x =3D=3D '&' then=20 > > return '&'=20 > > elseif x =3D=3D '"' then=20 > > return ''=20 > > elseif x =3D=3D "'" then=20 > > return "'"=20 > > else=20 > > return x=20 > > end=20 > > end)=20 > > end=20 > >=20 > > Should I put something more specific in the x =3D=3D "'" and x =3D=3D '= "'=20 > fields?=20 > >=20 > > On Tuesday, December 11, 2018 at 1:49:13 PM UTC-5, John MacFarlane=20 > wrote:=20 > >>=20 > >>=20 > >> You can always change the 'escape' function in your=20 > >> custom writer so it outputs ASCII entities instead of=20 > >> UTF-8 characters.=20 > >>=20 > >> Joey Dumont > writes:=20 > >>=20 > >> > Oh.=20 > >> >=20 > >> > It might be my TWiki installation then. Nothing I can really do abou= t=20 > >> that=20 > >> > though.=20 > >> >=20 > >> > Thanks for the help!=20 > >> >=20 > >> > On Monday, December 10, 2018 at 2:49:58 PM UTC-5, John MacFarlane=20 > wrote:=20 > >> >>=20 > >> >>=20 > >> >> This is an encoding issue. It looks like twiki is=20 > >> >> generating the right UTF-8 encoded output, but your=20 > >> >> browser isn't displaying it as UTF-8. You should=20 > >> >> be able to fix this by ensuring that twiki produces=20 > >> >> HTML containing a meta tag that sets the charset to=20 > >> >> UTF-8.=20 > >> >>=20 > >> >> Joey Dumont > writes:=20 > >> >>=20 > >> >> > I'm having trouble with quotes and what I believe are thin spaces= ,=20 > >> >> however.=20 > >> >> >=20 > >> >> > For instance, writing "he'll test something" in Markdown, then=20 > >> >> converting=20 > >> >> > to TWiki yields an HTML curly quote instead of a plain ' quote.= =20 > TWiki=20 > >> >> then=20 > >> >> > freaks and renders that as "he=C3=A2=E2=82=AC=E2=84=A2ll test som= ething"*.*=20 > >> >> >=20 > >> >> > The string "Dec. 5th" seems to yield a thin space between the=20 > period=20 > >> and=20 > >> >> > the decimal, but TWiki renders it as "Dec.=C3=82 5th"=20 > >> >> >=20 > >> >> > Not sure how to fix this. Tried escaping with escape(s) in=20 > multiple=20 > >> >> places,=20 > >> >> > such as Str, Plain and Para, but that didn't work. Tried modifyin= g=20 > >> >> > SingleQuoted to return "\'" .. s .. "\'", but that also didn't=20 > work.=20 > >> Not=20 > >> >> > sure what to do about the thin space either.=20 > >> >> >=20 > >> >> > On Saturday, February 25, 2017 at 3:29:07 PM UTC-5, ss infod=20 > wrote:=20 > >> >> >>=20 > >> >> >> Hello,=20 > >> >> >>=20 > >> >> >> I have a small question about Pandoc.=20 > >> >> >>=20 > >> >> >> Is there any plan to add the "Twiki Markup" language as an outpu= t=20 > >> >> (writer)=20 > >> >> >> option ?=20 > >> >> >>=20 > >> >> >> If not, do you think it is a big job to add it ?=20 > >> >> >> Is there some kind of dictionnary or script to create if I want= =20 > to=20 > >> add=20 > >> >> a=20 > >> >> >> new output format ?=20 > >> >> >>=20 > >> >> >> Would it be a big task to modify dokuwiki format to Twiki ? (bot= h=20 > >> seems=20 > >> >> >> rather similar..)=20 > >> >> >>=20 > >> >> >> Thanks for your input.=20 > >> >> >>=20 > >> >> >=20 > >> >> > --=20 > >> >> > You received this message because you are subscribed to the Googl= e=20 > >> >> Groups "pandoc-discuss" group.=20 > >> >> > To unsubscribe from this group and stop receiving emails from it,= =20 > >> send=20 > >> >> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org .=20 > >> >> > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org= =20 > >> >> .=20 > >> >> > To view this discussion on the web visit=20 > >> >>=20 > >>=20 > https://groups.google.com/d/msgid/pandoc-discuss/2ba0d474-f0db-456e-922a-= bb7282e60bf5%40googlegroups.com.=20 > > >>=20 > >> >>=20 > >> >> > For more options, visit https://groups.google.com/d/optout.=20 > >> >>=20 > >> >=20 > >> > --=20 > >> > You received this message because you are subscribed to the Google= =20 > >> Groups "pandoc-discuss" group.=20 > >> > To unsubscribe from this group and stop receiving emails from it,=20 > send=20 > >> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org .=20 > >> > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org=20 > >> .=20 > >> > To view this discussion on the web visit=20 > >>=20 > https://groups.google.com/d/msgid/pandoc-discuss/5bffbda3-8281-4247-99c2-= 3826011ec9ca%40googlegroups.com.=20 > > >>=20 > >> > For more options, visit https://groups.google.com/d/optout.=20 > >>=20 > >=20 > > --=20 > > You received this message because you are subscribed to the Google=20 > Groups "pandoc-discuss" group.=20 > > To unsubscribe from this group and stop receiving emails from it, send= =20 > an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org .=20 > > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org=20 > .=20 > > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/8631e4f1-8744-40b4-a3ce-= a8d8e1bb0202%40googlegroups.com.=20 > > > For more options, visit https://groups.google.com/d/optout.=20 > --=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 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/6a8f82dc-1d9a-473e-ab21-c6ab413a75ba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. ------=_Part_299_450667038.1544619818779 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Nice! I added this section to escape(),=C2=A0

=C2=A0 -- For TWiki installations= that don't support Unicode.
=C2=A0 = -- We replace some common Unicode-only symbols by their closest ASCII
=
=C2=A0 -- counterpart.
=C2=A0 for p, c in utf8.codes(s) do
=C2=A0 =C2=A0 if (c =3D=3D 0x2019 or c =3D=3D 0x2018) then
=C2=A0 =C2=A0 =C2=A0 new_string =3D new_string = .. "'"
=C2=A0 =C2=A0 elsei= f (c =3D=3D 0x201C or c =3D=3D 0x201D) then
=C2=A0 =C2=A0 =C2=A0 new_string =3D new_string .. '"'
=C2=A0 =C2=A0 elseif (c =3D=3D 0x00A0) then<= /div>
=C2=A0 =C2=A0 =C2=A0 new_string =3D new_= string .. '&nbsp;'
=C2=A0 = =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 new_str= ing =3D new_string .. utf8.char(c)
=C2= =A0 =C2=A0 end
=C2=A0 end
=C2=A0 return new_string
end

I haven't gone and fixed acc= ents and stuff, I'll probably add to this as I need more.
Thanks John for all the help, it is appreciated. I've attac= hed the full custom writer in case somebody wants to build on it.=C2=A0

Cheers,

On Tuesday, December 11, 2018 at 2:05:= 12 PM UTC-5, John MacFarlane wrote:

The problem is that lua's gsub is not really UTF-8
aware. =C2=A0[<>^\"'] will match a single BYTE, but the
quote characters are multibyte.

You can use the functions documented in sec 6.5
here: https://www.lua.org/manual/5.3/manual.html#6.5.

These allow you to iterate over the characters in a
string.

for p, c in utf8.codes(s) do
=C2=A0 -- c is the code point (integer) of the character
end

You can use this to build up a new string, escaping
each code point appropriately.


Joey Dumont <joey....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I tried that already. My escape function is probably bad then.=20
>
> -- Character escaping
> local function escape(s, in_attribute)
> =C2=A0 return s:gsub("[<>&\"']",
> =C2=A0 =C2=A0 function(x)
> =C2=A0 =C2=A0 =C2=A0 if x =3D=3D '<' then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return '&lt;'
> =C2=A0 =C2=A0 =C2=A0 elseif x =3D=3D '>' then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return '&gt;'
> =C2=A0 =C2=A0 =C2=A0 elseif x =3D=3D '&' then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return '&amp;'
> =C2=A0 =C2=A0 =C2=A0 elseif x =3D=3D '"' then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return ''
> =C2=A0 =C2=A0 =C2=A0 elseif x =3D=3D "'" then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return "'"
> =C2=A0 =C2=A0 =C2=A0 else
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return x
> =C2=A0 =C2=A0 =C2=A0 end
> =C2=A0 =C2=A0 end)
> end
>
> Should I put something more specific in the x =3D=3D "'&q= uot; and x =3D=3D '"' fields?
>
> On Tuesday, December 11, 2018 at 1:49:13 PM UTC-5, John MacFarlane= wrote:
>>
>>
>> You can always change the 'escape' function in your=20
>> custom writer so it outputs ASCII entities instead of=20
>> UTF-8 characters.=20
>>
>> Joey Dumont <joey....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>&= gt; writes:=20
>>
>> > Oh.=20
>> >=20
>> > It might be my TWiki installation then. Nothing I can rea= lly do about=20
>> that=20
>> > though.=20
>> >=20
>> > Thanks for the help!=20
>> >=20
>> > On Monday, December 10, 2018 at 2:49:58 PM UTC-5, John Ma= cFarlane wrote:=20
>> >>=20
>> >>=20
>> >> This is an encoding issue. It looks like twiki is=20
>> >> generating the right UTF-8 encoded output, but your= =20
>> >> browser isn't displaying it as UTF-8. =C2=A0You s= hould=20
>> >> be able to fix this by ensuring that twiki produces= =20
>> >> HTML containing a meta tag that sets the charset to= =20
>> >> UTF-8.=20
>> >>=20
>> >> Joey Dumont <joey....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascr= ipt:>> writes:=20
>> >>=20
>> >> > I'm having trouble with quotes and what I be= lieve are thin spaces,=20
>> >> however.=20
>> >> >=20
>> >> > For instance, writing "he'll test somet= hing" in Markdown, then=20
>> >> converting=20
>> >> > to TWiki yields an HTML curly quote instead of a= plain ' quote. TWiki=20
>> >> then=20
>> >> > freaks and renders that as "he=C3=A2=E2=82= =AC=E2=84=A2ll test something"*.*=20
>> >> >=20
>> >> > The string "Dec. 5th" seems to yield a= thin space between the period=20
>> and=20
>> >> > the decimal, but TWiki renders it as "Dec.= =C3=82 5th"=20
>> >> >=20
>> >> > Not sure how to fix this. Tried escaping with es= cape(s) in multiple=20
>> >> places,=20
>> >> > such as Str, Plain and Para, but that didn't= work. Tried modifying=20
>> >> > SingleQuoted to return "\'" .. s .= . "\'", but that also didn't work.=20
>> Not=20
>> >> > sure what to do about the thin space either.=20
>> >> >=20
>> >> > On Saturday, February 25, 2017 at 3:29:07 PM UTC= -5, ss infod wrote:=20
>> >> >>=20
>> >> >> Hello,=20
>> >> >>=20
>> >> >> I have a small question about Pandoc.=20
>> >> >>=20
>> >> >> Is there any plan to add the "Twiki Mar= kup" language as an output=20
>> >> (writer)=20
>> >> >> option ?=20
>> >> >>=20
>> >> >> If not, do you think it is a big job to add = it ?=20
>> >> >> Is there some kind of dictionnary or script = to create if I want to=20
>> add=20
>> >> a=20
>> >> >> new output format ?=20
>> >> >>=20
>> >> >> Would it be a big task to modify dokuwiki fo= rmat to Twiki ? (both=20
>> seems=20
>> >> >> rather similar..)=20
>> >> >>=20
>> >> >> Thanks for your input.=20
>> >> >>=20
>> >> >=20
>> >> > --=20
>> >> > You received this message because you are subscr= ibed to the Google=20
>> >> Groups "pandoc-discuss" group.=20
>> >> > To unsubscribe from this group and stop receivin= g emails from it,=20
>> send=20
>> >> an email to pandoc-discus...@googlegroups.com= <javascript:>.=20
>> >> > To post to this group, send email to pandoc-.= ..@googlegroups.com=20
>> >> <javascript:>.=20
>> >> > To view this discussion on the web visit=20
>> >>=20
>> https://groups.google.com/d/msgid/pandoc-discus= s/2ba0d474-f0db-456e-922a-bb7282e60bf5%40googlegroups.com.=20
>>
>> >>=20
>> >> > For more options, visit https://groups.google.com/d/optout.=20
>> >>=20
>> >=20
>> > --=20
>> > You received this message because you are subscribed to t= he Google=20
>> Groups "pandoc-discuss" group.=20
>> > To unsubscribe from this group and stop receiving emails = from it, send=20
>> an email to pandoc-discus...@googlegroups.com <= javascript:>.=20
>> > To post to this group, send email to pandoc-...@google= groups.com=20
>> <javascript:>.=20
>> > To view this discussion on the web visit=20
>> https://groups.google.com/d/msgid/pandoc-discus= s/5bffbda3-8281-4247-99c2-3826011ec9ca%40googlegroups.com.=20
>>
>> > For more options, visit https:= //groups.google.com/d/optout.=20
>>
>
> --=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 email to pandoc-discus...@googlegroups.com.
> To post to this group, send email to pandoc-...@googlegroups.com.
> To view this discussion on the web visit
https://groups.= google.com/d/msgid/pandoc-discuss/8631e4f1-8744-40b4-a3ce-a8d8e1b= b0202%40googlegroups.com.
> For more options, visit https://groups.go= ogle.com/d/optout.

--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/= msgid/pandoc-discuss/6a8f82dc-1d9a-473e-ab21-c6ab413a75ba%40googlegroups.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_299_450667038.1544619818779-- ------=_Part_298_1725081935.1544619818779 Content-Type: application/octet-stream; name=PandocTWikiWriter.lua Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=PandocTWikiWriter.lua X-Attachment-Id: ec597620-7705-4b9a-ac82-62a26d2eaec4 Content-ID: -- ------------------------------------------------------------------------- -- -- Author: Joey Dumont -- -- Date created: Dec. 7th, 2018 -- -- Description: Custom Lua writer for Pandoc. Outputs TWiki markup. -- -- License: CC BY-SA 4.0 -- -- -- -- -- -- Taken from data/sample.lua in the pandoc GitHub repo. -- -- ------------------------------------------------------------------------- -- local pipe = pandoc.pipe local stringify = (require "pandoc.utils").stringify -- The global variable PANDOC_DOCUMENT contains the full AST of -- the document which is going to be written. It can be used to -- configure the writer. local meta = PANDOC_DOCUMENT.meta -- Chose the image format based on the value of the -- `image_format` meta value. local image_format = meta.image_format and stringify(meta.image_format) or "png" local image_mime_type = ({ jpeg = "image/jpeg", jpg = "image/jpeg", gif = "image/gif", png = "image/png", svg = "image/svg+xml", })[image_format] or error("unsupported image format `" .. img_format .. "`") -- Character escaping (now with utf-8) local function escape(s, in_attribute) -- We escape home common HTML symbols. new_string = "" new_string = new_string:gsub("[<>&]", function(x) if x == '<' then return '<' elseif x == '>' then return '>' elseif x == '&' then return '&' elseif x == '"' then return '"' elseif x == "'" then return ''' else return x end end) -- For TWiki installations that don't support Unicode. -- We replace some common Unicode-only symbols by their closest ASCII -- counterpart. for p, c in utf8.codes(s) do if (c == 0x2019 or c == 0x2018) then new_string = new_string .. "'" elseif (c == 0x201C or c == 0x201D) then new_string = new_string .. '"' elseif (c == 0x00A0) then new_string = new_string .. ' ' else new_string = new_string .. utf8.char(c) end end return new_string end --- Pads str to length len with char from right local function lpad(str, len, char) if char == nil then char = ' ' end return str .. string.rep(char, len - #str) end -- Replace line breaks with line breaks + 3 spaces. local function IndentLineBreaks(str) str = string.gsub(str, "\n\n","\n") str = string.gsub(str, "\n", "\n ") return str end -- Helper function to convert an attributes table into -- a string that can be put into HTML tags. local function attributes(attr) local attr_table = {} for x,y in pairs(attr) do if y and y ~= "" then table.insert(attr_table, ' ' .. x .. '="' .. escape(y,true) .. '"') end end return table.concat(attr_table) end -- Table to store footnotes, so they can be included at the end. local notes = {} -- Blocksep is used to separate block elements. function Blocksep() return "\n\n" end -- This function is called once for the whole document. Parameters: -- body is a string, metadata is a table, variables is a table. -- This gives you a fragment. You could use the metadata table to -- fill variables in a custom lua template. Or, pass `--template=...` -- to pandoc, and pandoc will add do the template processing as -- usual. function Doc(body, metadata, variables) local buffer = {} local function add(s) table.insert(buffer, s) end add(body) if #notes > 0 then add('
    ') for _,note in pairs(notes) do add(note) end add('
') end return table.concat(buffer,'\n') .. '\n' end -- The functions that follow render corresponding pandoc elements. -- s is always a string, attr is always a table of attributes, and -- items is always an array of strings (the items in a list). -- Comments indicate the types of other variables. function Str(s) return escape(s) end function Space() return " " end function SoftBreak() return " " end function LineBreak() return "
" end function Emph(s) return "_" .. s .. "_" end function Strong(s) return "*" .. s .. "*" end function Subscript(s) return "" .. s .. "" end function Superscript(s) return "" .. s .. "" end function SmallCaps(s) return '' .. s .. '' end function Strikeout(s) return '' .. s .. '' end function Link(s, src, tit, attr) return "[[" .. escape(src,true) .. "][" .. s .. "]]" end function Image(s, src, tit, attr) return "" end function Code(s, attr) return "" .. escape(s) .. "" end function InlineMath(s) return "\\(" .. escape(s) .. "\\)" end function DisplayMath(s) return "\\[" .. escape(s) .. "\\]" end function SingleQuoted(s) return "‘" .. s .. "’" end function DoubleQuoted(s) return "“" .. s .. "”" end function Note(s) local num = #notes + 1 -- insert the back reference right before the final closing tag. s = string.gsub(s, '(.*)' .. s .. '') -- return the footnote reference, linked to the note. return '' .. num .. '' end function Span(s, attr) for x,y in pairs(attr) do local first = 1 local last = 1 if (x == 'class') then -- Extract the relevant Twiki macro. first,last = string.find(y, 'twiki%-macro ') macro_substring = string.sub(y, last+1,string.len(y)) if (macro_substring == "USERSIG") then return '%' .. escape(macro_substring,true) .. '{' .. s .. '}%' else return '%' .. escape(macro_substring,true) .. '%' end end end return "" .. s .. "" end function RawInline(format, str) if format == "html" then return str else return '' end end function Cite(s, cs) local ids = {} for _,cit in ipairs(cs) do table.insert(ids, cit.citationId) end return "" .. s .. "" end function Plain(s) return s end function Para(s) return s end -- lev is an integer, the header level. function Header(lev, s, attr) return "---" .. string.rep("+",lev) .. " " .. s end function BlockQuote(s) return "
\n" .. s .. "\n
" end function HorizontalRule() return "
" end function LineBlock(ls) return '
' .. table.concat(ls, '\n') .. '
' end function CodeBlock(s, attr) return "" .. escape(s) .. "" end function BulletList(items) local buffer = {} for _, item in pairs(items) do table.insert(buffer, " * " .. IndentLineBreaks(item)) end return table.concat(buffer, "\n") end function OrderedList(items) local buffer = {} for _, item in pairs(items) do table.insert(buffer, " 1. " .. IndentLineBreaks(item)) end return table.concat(buffer, "\n") end function DefinitionList(items) local buffer = {} for _,item in pairs(items) do local k, v = next(item) table.insert(buffer, " $ " .. k .. ": " .. v) end return table.concat(buffer, "\n") end -- Convert pandoc alignment to something HTML can use. -- align is AlignLeft, AlignRight, AlignCenter, or AlignDefault. function html_align(align) if align == 'AlignLeft' then return 'left' elseif align == 'AlignRight' then return 'right' elseif align == 'AlignCenter' then return 'center' else return 'left' end end function CaptionedImage(src, tit, caption, attr) return '
\n\n' .. '

' .. caption .. '

\n
' end -- Caption is a string, aligns is an array of strings, -- widths is an array of floats, headers is an array of -- strings, rows is an array of arrays of strings. -- TODO: Deal with alignment. function Table(caption, aligns, widths, headers, rows) -- Buffer to hold the table, and function to tadd to the buffer. local buffer = {} local function add(s) table.insert(buffer,s) end -- Determine the longest string in the table, per column. local function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end local max_length = {} for i,h in pairs(headers) do table.insert(max_length,string.len(h)) end for _,row in pairs(rows) do for i,c in pairs(row) do max_length[i] = string.len(c) > max_length[i] and string.len(c) or max_length[i] end end local header_row = {} local empty_header = true for i, h in pairs(headers) do local align = html_align(aligns[i]) if (align == 'center') then table.insert(header_row, "| *" .. lpad(h,max_length[i]) .. "* ") elseif (align == 'right') then table.insert(header_row, "| *" .. lpad(h,max_length[i]) .. "* ") else table.insert(header_row, "| *" .. lpad(h,max_length[i]) .. "* ") end empty_header = empty_header and h == "" end table.insert(header_row, " |\n") for _,h in pairs(header_row) do add(h) end for _, row in pairs(rows) do for i,c in pairs(row) do add("| " .. lpad(c,max_length[i]) .. " ") end add(" |\n") end return table.concat(buffer) end function RawBlock(format, str) if format == "html" then return str else return '' end end function Div(s, attr) return "\n" .. s .. "
" end -- The following code will produce runtime warnings when you haven't defined -- all of the functions you need for the custom writer, so it's useful -- to include when you're working on a writer. local meta = {} meta.__index = function(_, key) io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) return function() return "" end end setmetatable(_G, meta) ------=_Part_298_1725081935.1544619818779--