How to Style Markdown with CSS


Series: Awesome Tips about Pandoc and Markdown


The Problem

  • How can we make come text red in Markdown?
  • How Can we add custom CSS style to elements in Markdown?
  • The default CSS has no border, how can we add border to table?

Defining the CSS

We can define the following CSS in markdown itself, or for example add it into template in Blogger.

Embedding HTML Code

We can use any valid HTML code directly in Markdown.

red text

One of the reason to choose Markdown for writing is to focus on the content, not format.

The drawback of this approach is too much html code: prefix, suffix, attributes etc.

In Pandoc, we can easily use attributes to add CSS style to headers, fenced code, div, inline code, bracketed spans, link etc.

Heading Identifiers

Red text title

Fenced Code Attributes

```{.red .numberLines startFrom="1"}
Here is a paragraph.

And another.
```

Divs and Spans

Here is a paragraph.

And another.

Inline Code Attributes

red text

Bracketed Spans

This is some red text

  • We can css class, width, height
DNCE’s Waving Pug
DNCE’s Waving Pug

Custom CSS for Markdown

Blockquotes CSS
Table CSS
  • Pandoc’s default CSS has no border, we can add the following CSS to add border.

Themes

  • We can also add our own css or change the existing one.
  • We can edit blogger’s theme and add the css there so the theme applies to all posts.
  • Create truly standalone html files
    • -H fullpath_pandoc.css or –include-in-header=FILE
  • Themes to use

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)