program define do2md
	syntax using/ [, Show Css(string)]
    if "`css'" != "" local css -c `css'

	set linesize 255
	capture log close
	log using `using'.log, replace
	do `using'.do
	log close

	log2markup using `using'.log, replace extension(md) ///
		codestart(<pre><code>) codeend(</code></pre>) ///
		samplestart(<pre><samp>) sampleend(</samp></pre>)

	local date: display %td_CCYY_NN_DD date(c(current_date), "DMY")
	local date = subinstr(trim("`date'"), " " , "-", .)

	file open fh using `using'.md, write text append
	file write fh _newline(2)
	file write fh "------"
	file write fh _newline
	file write fh `"[The do file for this document](`using'.do)"'
	file write fh _newline
	file write fh _newline
	file write fh `"Last update: `date', Stata version `c(version)'"'
	file close fh

	mata lines = file2mata(`"`using'.md"')
	mata lines = collapse_line_pattern(lines, "<pre><code>")
	mata lines = collapse_line_pattern(lines, "<pre><sample>")
	mata strlst2file(`"`using'.md"', lines, 1)

    shell pandoc -s "`using'.md" `css' -o "`using'.html" & timeout 30
    if "`show'" != "" shell "`using'.html" & timeout 30
end