Could pandoc.read(markup, "html") help? On Mon, 16 Aug 2021 at 23:09, John MacFarlane wrote: > > I'm afraid you'll have to write some parsing code... > > pompez writes: > > > I'm starting out with Lua filters and apologize for this possibly > already > > answered question. You can also read this question on StackOverflow > > < > https://stackoverflow.com/questions/68809527/is-there-a-way-to-change-the-way-pandoc-parses-html-inside-of-markdown-documents > > > > . > > > > I'm using Pandoc to convert markdown to HTML. My markdown files also > > contain some raw HTML. In the examples, I'll be using `` and ``. > > > > Let's say I want to change every `` to a `` tag. We parse the > > input as HTML and look at the AST. > > > > ``` > > $ echo 'foo & bar' | pandoc --from=html --to native > > [Plain [Underline [Str "foo"],Space,Str "&",Space,Span ("", ["mark"],[]) > > [Str "bar"]]] > > ``` > > > > On this structure, we can use a simple filter which replaces `Span` > > elements representing the `` tag and replaces with `Underline` > > elements. > > > > ``` > > function Span(elem) > > if elem.classes[1]:gmatch('mark') then > > return pandoc.Underline(elem.content) > > end > > end > > ``` > > > > ``` > > [Plain [Underline [Str "foo"],Space,Str "&",Space,Underline [Str "bar"]]] > > ``` > > > > This is good. But if we parse the same input as markdown, we get a much > > less convenient structure. > > > > ``` > > $ echo 'foo & bar' | pandoc --from=markdown+raw_html > > --to native > > [Para [RawInline (Format "html") "",Str "foo",RawInline (Format > "html") > > "",Space,Str "&",Space,RawInline (Format "html") "",Str > > "bar",RawInline (Format "html") ""]] > > ``` > > > > And if we had some additional criteria by which to replace `` with > > `` (the content for example), we would have to identify the opening > and > > closing `RawInline` elements. > > > > I'm wondering if there is any good solutions to this problem? Is there a > > way to parse HTML in markdown just as HTML would be parsed otherwise? Or > is > > there way to solve this in a Lua filter without writing some parsing > code? > > > > -- > > 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/aae29ca7-60ca-4349-af03-939f0ac503efn%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/yh480k1r6tt53d.fsf%40johnmacfarlane.net > . > -- 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/CAEe_xxj-kp22oToH4o5J54s16W4WzMkiaEicOy%2BTuqDZf5LP3g%40mail.gmail.com.