markdownpandocmultimarkdown

Setting bgcolor in markdown


I want to set the page bgcolor through markdown.

Is there any way besides explicitly including, say, <body bgcolor="#336655"> in the .md file? In particular, this seems to be implemented incorrectly. E.g. the following minimal file:

% Page Title

<body bgcolor="#336655">

## Some Body

Produces the following HTML file (through pandoc -s -o test.html test.md)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title>Page Title</title>
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<div id="header">
<h1 class="title">Page Title</h1>
</div>
<body bgcolor="#336655">
<h2 id="some-body">Some Body</h2>
</body>
</html>

In particular, the <body> tag I included did not overwrite the main <body> tag produced, as I'd intended (closing with </body> in the markdown doesn't change this).

Placing the <body> tag prior to the % Page Title line shuts down the interpretation of that line as the page title -- it just formats as % Page Title in plain text.

Is there no way to control the overall page background in markdown?


Solution

  • You should change the pandoc template for that and insert the needed CSS. Don't do styling in HTML, it's not the 90s anymore...

    $ pandoc -D html > template.html
    

    edit it to include:

    <style type="text/css">
      body {
        background-color: #336655;
      }
    </style>
    

    then

    $ pandoc -s --template template.html -o output.html input.md