Skip to content

I try to create a Lua filter to preserve videos while converting from HTML to GitHub Flavored Markdown (GFM). #11355

@cs5vsm99xq-wq

Description

@cs5vsm99xq-wq

I try to create a Lua filter to preserve videos while converting from HTML to GitHub Flavored Markdown (GFM).

pandoc -f html+raw_html from.htm -t gfm-raw_html -o to.md --wrap=none --lua-filter preserve-videos.lua
local function starts_with(start, str)
  return str:sub(1, #start) == start
end

function RawBlock(el)
  return starts_with('<source', el.text)
    and pandoc.RawBlock('markdown', el.text)
    or {}
end

Input HTML:

<h1>heading</h1>
<p>paragraph</p>
<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
</video>

Output Markdown:

# heading

paragraph

<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">

As you can see, the problem is that it preserves <source>, whereas it is also necessary to preserve <video>.

Changing return starts_with('<source', el.text) to return starts_with('<video', el.text) doesn't solve the problem, and results to

# heading

paragraph

<video width="320" height="240" controls>

Originally posted by @johnmapeson in #9658

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions