Skip to content

Lua filter to preserve HTML comments #9514

Closed Answered by tarleb
jsx97 asked this question in Q&A
Feb 26, 2024 · 7 comments · 11 replies
Discussion options

You must be logged in to vote

Let me copy over my solution from StackOverflow.

local function starts_with(start, str)
  return str:sub(1, #start) == start
end

function RawInline(el)
  if not starts_with('<!--', el.text) then
    return {}
  end
end

As noted in the comments there, this is insufficient for your purpose. (I'd like to stress again that, in cases like this, a lot of everybody's time can be saved by including the example and expected output directly in the question). Since you don't want any HTML, it's best to use -t gfm-raw_html. This also suppresses all HTML snippets, so we need to pretend that our comments are actually Markdown. Modifying the filter like this will do the trick:

function RawInline (el)
  r…

Replies: 7 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@jsx97
Comment options

Comment options

You must be logged in to vote
1 reply
@jsx97
Comment options

Comment options

You must be logged in to vote
1 reply
@jsx97
Comment options

Comment options

You must be logged in to vote
1 reply
@jsx97
Comment options

Comment options

You must be logged in to vote
6 replies
@jgm
Comment options

@jsx97
Comment options

@jgm
Comment options

@jsx97
Comment options

@jgm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jsx97
Comment options

Answer selected by jsx97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants