CSS adding 1.1, 1.2, etc. to header

s_h_a_n_e's Avatar

s_h_a_n_e

23 Sep, 2013 06:15 PM

Hi. I found some code to help me convert headers to a numbered outline, but the counters don't seem to be working. I'm not sure what I'm missing. I just see "Chapter 1" in front of each header, rather than Chapter 1, Chapter 2 etc.

Here's the CSS:

body {  
    counter-reset: chapter;      /* Create a chapter counter scope */
}
h1:before {  
    content: "Chapter " counter(chapter) ". ";
    counter-increment: chapter;  /* Add 1 to chapter */
}
h1 {  
    counter-reset: section;      /* Set section to 0 */
}
h2:before {  
    content: counter(chapter) "." counter(section) " ";
    counter-increment: section;
}

And some Markdown:

# First Chapter #

# Second Chapter #

# Third Chapter #

Thanks.

  1. Support Staff 1 Posted by Brett on 23 Sep, 2013 06:37 PM

    Brett's Avatar

    I'm not sure why at this point, but the counter doesn't seem to increment in Marked 1.4. It works fine in Marked 2, which will be out Thursday, but I'm going to need to do some research to see if there's something in Marked 1.4 botching it up, or if the version of webkit is just old enough to not be comptible with counters.

  2. 2 Posted by s_h_a_n_e on 23 Sep, 2013 07:13 PM

    s_h_a_n_e's Avatar

    Okay, great, thanks.

    El Sep 23, 2013, a las 1:37 PM, Brett <[email blocked]> escribió:

  3. 3 Posted by s_h_a_n_e on 30 Sep, 2013 06:52 PM

    s_h_a_n_e's Avatar

    As Brett said, the above code does work in Marked 2, but for some reason, I cannot seem to embed it in a more complex CSS file (previewing in Marked 2). In that case, the counters do not work right. I am attaching the CSS, and below is some slightly more detailed multimarkdown code:

    # First Chapter #
    
    ## A Section ##
    
    ## Another Section ##
    
    # Second Chapter #
    
    ## A Section ##
    
    ## Another Section ##
    
    # Third Chapter #
    
    ## A Section ##
    
    ## Another Section ##
    
  4. 4 Posted by s_h_a_n_e on 30 Sep, 2013 07:06 PM

    s_h_a_n_e's Avatar

    My apologies. It was a simple issue. I added lines below the previously last line of some items in curly brackets. I didn't realize that I hadn't added a semicolon to that item, as it was no longer last. Once I included the semicolon, everything worked as expected.

  5. s_h_a_n_e closed this discussion on 30 Sep, 2013 07:06 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? 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