Bug in nth-child

keith.knipling's Avatar


01 Feb, 2012 05:35 PM

There is a bug in how Marked interprets nth-child CSS selectors. See the attached markdown and CSS files. The CSS specifies:

h1:nth-child(2) {

color: red;


But in the output (PDF), the first nth-child is colored red.

  1. Support Staff 1 Posted by Brett on 01 Feb, 2012 06:06 PM

    Brett's Avatar

    Actually, you want nth-of-type() I think. nth-child matches any element, and there's no h1 in the second position of your markup.

    h1:nth-of-type(2) {
    color: red;

    Marked uses the standard webkit rendering for CSS, and you'll find very similar results if the output is loaded in Safari. Is your stylesheet entirely custom?


  2. 2 Posted by keith.knipling on 01 Feb, 2012 08:05 PM

    keith.knipling's Avatar

    OK, I agree that nth-of-type() is probably more appropriate. Thanks for the tip.

    I am still confused, though, why h1:nth-child(2) targets the first

    in Marked. Try it.

    Here is a screen grab showing the output of Safari and Marked. Marked is displaying the "bug.mdown" file uploaded previously, generated according to the "bug.css" file. The Safari window is showing "bug.html" (with equivalent CSS in the header). That file is attached.


  3. Support Staff 3 Posted by Brett on 08 Feb, 2012 03:14 PM

    Brett's Avatar

    Attached is the output I get in Safari and Marked. They are exactly the same, so I'm unsure why you're getting the results you are. As far as I can tell, the output is exactly what I'd expect from the CSS you're using...

    Could you attach a screenshot of your "Behavior" preferences?

  4. 4 Posted by keith.knipling on 08 Feb, 2012 08:57 PM

    keith.knipling's Avatar


    I agree that both HTML files will render the same in Safari and Marked.

    Open "bug.mdown" in Marked and use the "bug.css" file for output. It should generate the same result as "bug.html" in Safari but it does not.



Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Already uploaded files

  • bug.mdown 945 Bytes
  • bug.css 78 Bytes
  • bug.pdf 22.2 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac