Basically, I gsub ==text== into <mark>text</text> which works fine but if text contains any other markdown, like a link or bold or whatever, that markdown doesn’t get converted into HTML downstream and is rendered to the page as raw markdown.
Perhaps I am invoking the wrong hook or something?
So read up a bit and seocnd attempt probably a better approach but the same problem persists: gsub does its thing, but any markdown contained in between does not get rendered as HTML afterwards (even though we are firing this “pre_render”).
Markdown in “\1” is left intact pre_render, why isn’t Kramdown converting it?
kramdown will only convert documents with a Markdown extension (markdown,mkdown,mkdn,mkd,md). If you put Markdown text inside an HTML file, it’ll be ignored. To ensure Markdown conversion in an HTML file, you’ll need to pass the text through the liquid filter markdownify or have your plugin invoke kramdown converter on the gsubbed content.
Therefore, your generator would now look like the following:
class HighlightsGenerator < Jekyll::Generator
def generate(site)
all_docs = site.documents
# Converts Markdown-plus ==text== to <mark>text</mark>
all_docs.each do |current_note|
current_note.content = current_note.content.gsub(
/\=\=(.*)\=\=/i,
'<mark markdown="span">\1</mark>'
)
end
end
end
@ashmaroli !!! That worked!
I didn’t catch the suggestion the first time to add markdown="1" (which now that I tried it didn’t work) but yes markdown="span" totally does the trick.
If I understand correctly, my plugin is generating HTML… and kramdown just ignores stuff that is between html tags? Unless one sets the markdown="span" flag explicitly? Ok. Hunh. Dunno if I would have ever caught that on my own.
Yes, that is correct.
And it is not always markdown="span". According to the documentation I linked to previously, even markdown="block" may be used based on the use-case.