public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* regex captures on a Header element
@ 2022-08-24 12:30 Randy Josleyn
       [not found] ` <03fcdfd9-2811-4622-897e-98d2303e54e1n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Josleyn @ 2022-08-24 12:30 UTC (permalink / raw)
  To: pandoc-discuss


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

Hi group,

I am writing a multilingual document and I want to convert a markdown 
header to a latex command like so:

## A header | 中文标题
->
\bisection{A header}{中文标题}

Using this example 
<https://pandoc.org/lua-filters.html#modifying-pandocs-manual.txt-for-man-pages> 
about man pages from the documentation, I have come up with something like 
the following filter:

~~~lua
local text = pandoc.text
local raw = function (content)
  return pandoc.RawInline('latex', content)
end

function Header(el)
  local pattern = "(%a+)%s+|%s+(.*)"
  headertext = table.unpack(el.content).text
  local _, _, enh, zhh = string.find(headertext, pattern)
  return raw('\\bisection{'..enh..'}{'..zhh..'}')
end
~~~

However, Lua tells me I'm trying to concatenate a nil value `zhh`. I guess 
it could be that my regex is wrong, or that I'm using string.find 
incorrectly; I copied the pattern from the Lua manual Section 20.3, 
"Captures" <https://www.lua.org/pil/20.3.html>. Can anyone give me any 
pointers?

Thank you all!

Randy

-- 
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/03fcdfd9-2811-4622-897e-98d2303e54e1n%40googlegroups.com.

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

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

end of thread, other threads:[~2022-08-25 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24 12:30 regex captures on a Header element Randy Josleyn
     [not found] ` <03fcdfd9-2811-4622-897e-98d2303e54e1n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-24 16:42   ` John MacFarlane
     [not found]     ` <79D67508-3478-4C1D-9637-7084AE959EDD-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-08-25  3:29       ` Randy Josleyn
     [not found]         ` <85a8a23d-7e4e-4f1a-b54e-b2c0fb4e6182n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-25 17:21           ` Albert Krewinkel

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