Displaying program generated markdown

Apologies if this is an obvious question…

I have a function that generates a big chunk of markdown with embedded newline characters. A simple version would be:


function makemd()
	md"# HELLO\n## Some\n	* list\n* list\n"	
end

That produces a string that prints correctly in the repl, but of course you can’t print to Pluto. So, how can I get the output to render nicely in Pluto, as when you simply type in a chunk of markdown? At present I just see the raw string, with the "\n"s embedded in it.

Graham

This works:

function makemd()
	md"""# HELLO
	## Some
	* list
	* list"""	
end

makemd()

Looks like the md macro automatically escapes \n.

Hi Lungbenm

Indeed that does work, but unfortunately it’s not possible for me to produce my markdown in that way: I’m actually producing quite big md tables line-by-line. Sorry if my example was misleading.

Graham

You can use Markdown.parse:

function makemd()
	Markdown.parse("# HELLO\n## Some\n	* list\n* list\n")
end

When str is a string of markdown code, Markdown.parse(str) and @eval @md_str $str work fine.

That’s brilliant; worked perfectly. Many thanks, both.

Graham