How to Convert Markdown + CSS -> PDF

Using CSS when converting Markdown to PDF with Pandoc

I don't know LaTeX at all, but have hacked this solution using this helpful manual. First, create a style:

\definecolor{silver}{RGB}{230,230,230}

\newcommand{\inlinecodeblock}[1]{
\colorbox{silver}{
\texttt{#1}
}
}

And here's how to use it:

Some \inlinecodeblock{inline code}, and some widgets, go here

This creates a style with a background colour and a monospaced font. The margin and padding are a bit large for my preferences, but it's a very useable start. Here's what it looks like:

Screenshot of inline formatting

The disadvantage is that if I wish to output to a format that supports styles proper (such as HTML) then these are lost. Also, my solution only works with LaTeX/PDF. Thus, if you can fix these issues, please add a better answer!


Addendum: I have a better approach, which is thus:

\newcommand{\inlinecodeblock}[1]{
\fboxsep 1pt
\fboxrule 0pt
\colorbox{silver}{\strut{\texttt{#1}}}
}

This avoids the problem of excess horizontal padding - I think it was the line break in the colorbox parameter that did it. I've added in strut, which keeps highlights the same height regardless of whether the text has descenders.

It's not perfect though - there's still too much horizontal margin outside the box, and a comma after a box will still orphan onto the next line. I may give up with LaTeX, and render to HTML from Pandoc, and then use wkhtmltopdf to render the final document.

Convert Markdown + CSS to .doc or .pdf

You can also generate HTML from Markdown and convert it to .pdf or .xls format using DocRaptor. DocRaptor also handles CSS better than competitors do.

Here's a link to DocRaptor



Related Topics



Leave a reply



Submit