public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: primejade <hosteam01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: latex to markdown (gfm or commonMark)
Date: Sun, 17 Sep 2023 12:06:23 -0700 (PDT)	[thread overview]
Message-ID: <f2ccb8c5-7628-453e-a22e-041a7fc898f7n@googlegroups.com> (raw)


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

Hi, I have some LaTeX files which I need to convert them to Markdown (gfm 
or commonMark). But I need the LaTeX's \title{} (I guess metadata.title in 
pandoc) to be a # (h1). I have some lua filters to do a header.level shift, 
but I cannot add the metadata.title as a # heading.

lua-filter-1: shift headings
local title
function promote_header(header)
if header.level < 6 then
header.level = header.level + 1
return header
end
if not title then
title = header.content
print(title)
return {}
end
local msg = '[WARNING] title already set; discarding header "%s"\n'
io.stderr:write(msg:format(pandoc.utils.stringify(header)))
return {}
end
return {
{Meta = function (meta) title = meta.title end}, -- init title
{Header = promote_header},
{Meta = function (meta) meta.title = title; return meta end}, -- set title
}

lua-filter-2: append metadata.title at the beginning of the file as #
function Meta(m)
if m.title then
local title_text = pandoc.utils.stringify(m.title)
-- io.write("# " .. title_text .. "\n")
end
return {}
end

Any ideas how to achieve this?

-- 
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/f2ccb8c5-7628-453e-a22e-041a7fc898f7n%40googlegroups.com.

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

                 reply	other threads:[~2023-09-17 19:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2ccb8c5-7628-453e-a22e-041a7fc898f7n@googlegroups.com \
    --to=hosteam01-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).