Skip to content

Commit

Permalink
Add enumerate_heading_depth option, see #65
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink committed Jan 28, 2022
1 parent 3599b5c commit 184a58d
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 163 deletions.
5 changes: 4 additions & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ plugins:
For example "[google.com](https://www.google.com)" will be replaced by "[google.com](https://www.google.com) (https://www.google.com)"

`enumerate_headings`
: Default `true`. This will add numbering (enumeration) to all headings as well as the table of contents. Note this will only enumerate the print site page; if you want to enumerate the entire site, you can use [mkdocs-enumerate-headings-plugin](https://github.com/timvink/mkdocs-enumerate-headings-plugin).
: Default `true`. This will add numbering (enumeration) to all headings and sections, as well as the table of contents. Note this will only enumerate the print site page; if you want to enumerate the entire site, you can use [mkdocs-enumerate-headings-plugin](https://github.com/timvink/mkdocs-enumerate-headings-plugin).

Example "1.2 A chapter subsection".

`enumerate_headings_depth`
: Default `6`. If `enumerate_headings`, the depth until which headings and sections are enumerated.

`enumerate_figures`
: Default `true`. This will add numbering to all figure captions (for example "Figure 1: <caption>"). Works especially well with [mkdocs-img2fig-plugin](https://github.com/stuebersystems/mkdocs-img2fig-plugin).

Expand Down
75 changes: 75 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Enumerate headings
Only displayed when set in mkdocs.yml
print-site:
- print-site-enumerate_headings: true
*/

/* Reset all enumeration at start of page */
body {counter-reset: chapter sec-top toc-chapter toc-sec-chapter figurecounter;}

/* Enumerate headings of CHAPTERS,
that are part of an original included page */
.print-site-enumerate-headings .print-page h1 {counter-reset: section sub-section composite detail last; }
.print-site-enumerate-headings .print-page h2 {counter-reset: sub-section composite detail last; }
.print-site-enumerate-headings .print-page h3 {counter-reset: composite detail last; }
.print-site-enumerate-headings .print-page h4 {counter-reset: detail last; }
.print-site-enumerate-headings .print-page h5 {counter-reset: last; }
.print-site-enumerate-headings .print-page h1:before {
counter-increment: chapter;
content: counter(chapter) " " !important;
}
.print-site-enumerate-headings h1.print-page-toc-title:before,
#print-site-cover-page h1:before,
#print-site-cover-page h2:before,
#print-site-cover-page h3:before,
#print-site-cover-page h4:before,
#print-site-cover-page h5:before,
#print-site-cover-page h6:before {
content: none !important;
counter-increment: none;
}


/* Enumerate headings of SECTIONS,
that are part of an original included page */
.print-site-enumerate-headings h1 {counter-reset: sec-section sec-sub-section sec-composite sec-detail sec-last; }
.print-site-enumerate-headings h2.nav-section-title {counter-reset: sec-sub-section sec-composite sec-detail sec-last; }
.print-site-enumerate-headings h3.nav-section-title {counter-reset: sec-composite sec-detail sec-last; }
.print-site-enumerate-headings h4.nav-section-title {counter-reset: sec-detail sec-last; }
.print-site-enumerate-headings h5.nav-section-title {counter-reset: sec-last; }
.print-site-enumerate-headings h1.nav-section-title:before {
counter-increment: sec-top;
content: counter(sec-top, upper-roman) ". " !important;
}


/* Enumerate CHAPTERS in table of contents also */
.print-site-enumerate-headings .print-site-toc-level-1 > ul { counter-reset: toc-section; }
.print-site-enumerate-headings .print-site-toc-level-2 > ul { counter-reset: toc-sub-section; }
.print-site-enumerate-headings .print-site-toc-level-3 > ul { counter-reset: toc-composite; }
.print-site-enumerate-headings .print-site-toc-level-4 > ul { counter-reset: toc-detail; }
.print-site-enumerate-headings .print-site-toc-level-5 > ul { counter-reset: toc-last; }
.print-site-enumerate-headings .print-site-toc-level-1 > li a:before {
counter-increment: toc-chapter;
content: counter(toc-chapter) " ";
}

/* Enumerate SECTIONS in table of contents also */
.print-site-enumerate-headings li.toc-nav-section-title-level-1 { counter-reset: toc-sec-section; }
.print-site-enumerate-headings li.toc-nav-section-title-level-2 { counter-reset: toc-sec-sub-section; }
.print-site-enumerate-headings li.toc-nav-section-title-level-3 { counter-reset: toc-sec-composite; }
.print-site-enumerate-headings li.toc-nav-section-title-level-4 { counter-reset: toc-sec-detail; }
.print-site-enumerate-headings li.toc-nav-section-title-level-5 { counter-reset: toc-sec-last; }
.print-site-enumerate-headings li.toc-nav-section-title-level-1:before {
counter-increment: toc-sec-chapter;
content: counter(toc-sec-chapter, upper-roman) " ";
}


#print-page-toc li a.headerlink:before {
content: none !important;
counter-increment: none;
}
46 changes: 46 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

/*
Enumerate level 2 headings of CHAPTERS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/

.print-site-enumerate-headings .print-page h2:before {
counter-increment: section;
content: counter(chapter) "." counter(section) " " !important;
}

/*
Enumerate level 2 headings of SECTIONS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/
.print-site-enumerate-headings h2.nav-section-title:before {
counter-increment: sec-section;
content: counter(sec-top, upper-roman) "." counter(sec-section, upper-roman) " " !important;
}


/* Enumerate CHAPTERS in table of contents also */

.print-site-enumerate-headings .print-site-toc-level-2 > li a:before {
counter-increment: toc-section;
content: counter(toc-chapter) "." counter(toc-section) " ";
}

/* Enumerate SECTIONS in table of contents also */

.print-site-enumerate-headings li.toc-nav-section-title-level-2:before {
counter-increment: toc-sec-section;
content: counter(toc-sec-chapter, upper-roman) "." counter(toc-sec-section, upper-roman) " ";
}
52 changes: 52 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings3.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/*
Enumerate level 2 headings of CHAPTERS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/


.print-site-enumerate-headings .print-page h3:before {
counter-increment: sub-section;
content: counter(chapter) "." counter(section) "." counter(sub-section) " " !important;
}


/*
Enumerate level 2 headings of SECTIONS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/

.print-site-enumerate-headings h3.nav-section-title:before {
counter-increment: sec-sub-section;
content: counter(sec-top, upper-roman) "." counter(sec-section, upper-roman) "." counter(sec-sub-section, upper-roman) " " !important;
}


/* Enumerate CHAPTERS in table of contents also */


.print-site-enumerate-headings .print-site-toc-level-3 > li a:before {
counter-increment: toc-sub-section;
content: counter(toc-chapter) "." counter(toc-section) "." counter(toc-sub-section) " ";
}


/* Enumerate SECTIONS in table of contents also */


.print-site-enumerate-headings li.toc-nav-section-title-level-3:before {
counter-increment: toc-sec-sub-section;
content: counter(toc-sec-chapter, upper-roman) "." counter(toc-sec-section, upper-roman) "." counter(toc-sec-sub-section, upper-roman) " ";
}
49 changes: 49 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings4.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

/*
Enumerate level 2 headings of CHAPTERS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/

.print-site-enumerate-headings .print-page h4:before {
counter-increment: composite;
content: counter(chapter) "." counter(section) "." counter(sub-section) "." counter(composite) " " !important;
}

/*
Enumerate level 2 headings of SECTIONS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/


.print-site-enumerate-headings h4.nav-section-title:before {
counter-increment: sec-composite;
content: counter(sec-top, upper-roman) "." counter(sec-section, upper-roman) "." counter(sec-sub-section, upper-roman) "." counter(sec-composite, upper-roman) " " !important;
}

/* Enumerate CHAPTERS in table of contents also */

.print-site-enumerate-headings .print-site-toc-level-4 > li a:before {
counter-increment: toc-composite;
content: counter(toc-chapter) "." counter(toc-section) "." counter(toc-sub-section) "." counter(toc-composite) " ";
}


/* Enumerate SECTIONS in table of contents also */


.print-site-enumerate-headings li.toc-nav-section-title-level-4before {
counter-increment: toc-sec-composite;
content: counter(toc-sec-chapter, upper-roman) "." counter(toc-sec-section, upper-roman) "." counter(toc-sec-sub-section, upper-roman) "." counter(toc-sec-composite, upper-roman) " ";
}
49 changes: 49 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

/*
Enumerate level 2 headings of CHAPTERS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/

.print-site-enumerate-headings .print-page h5:before {
counter-increment: detail;
content: counter(chapter) "." counter(section) "." counter(sub-section) "." counter(composite) "." counter(detail) " " !important;
}

/*
Enumerate level 2 headings of SECTIONS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/


.print-site-enumerate-headings h5.nav-section-title:before {
counter-increment: sec-detail;
content: counter(sec-top, upper-roman) "." counter(sec-section, upper-roman) "." counter(sec-sub-section, upper-roman) "." counter(sec-composite, upper-roman) "." counter(sec-detail, upper-roman) " " !important;
}


/* Enumerate CHAPTERS in table of contents also */

.print-site-enumerate-headings .print-site-toc-level-5 > li a:before {
counter-increment: toc-detail;
content: counter(toc-chapter) "." counter(toc-section) "." counter(toc-sub-section) "." counter(toc-composite) "." counter(toc-detail) " ";
}


/* Enumerate SECTIONS in table of contents also */

.print-site-enumerate-headings li.toc-nav-section-title-level-5:before {
counter-increment: toc-detail;
content: counter(toc-sec-chapter, upper-roman) "." counter(toc-sec-section, upper-roman) "." counter(toc-sec-sub-section, upper-roman) "." counter(toc-sec-composite, upper-roman) "." counter(toc-sec-detail, upper-roman) " ";
}
49 changes: 49 additions & 0 deletions mkdocs_print_site_plugin/css/print-site-enum-headings6.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

/*
Enumerate level 2 headings of CHAPTERS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/


.print-site-enumerate-headings .print-page h6:before {
counter-increment: last;
content: counter(chapter) "." counter(section) "." counter(sub-section) "." counter(composite) "." counter(detail) "." counter(last) " " !important;
}

/*
Enumerate level 2 headings of SECTIONS,
that are part of an original included page
Only displayed when set in mkdocs.yml:
print-site:
- enumerate_headings: true
- enumerate_headings_depth: 2 # or more
*/

.print-site-enumerate-headings h6.nav-section-title:before {
counter-increment: sec-last;
content: counter(sec-top, upper-roman) "." counter(sec-section, upper-roman) "." counter(sec-sub-section, upper-roman) "." counter(sec-composite, upper-roman) "." counter(sec-detail, upper-roman) "." counter(sec-last, upper-roman) " " !important;
}


/* Enumerate CHAPTERS in table of contents also */

.print-site-enumerate-headings .print-site-toc-level-6 > li a:before {
counter-increment: toc-last;
content: counter(toc-chapter) "." counter(toc-section) "." counter(toc-sub-section) "." counter(toc-composite) "." counter(toc-detail) "." counter(toc-last) " ";
}

/* Enumerate SECTIONS in table of contents also */

.print-site-enumerate-headings li.toc-nav-section-title-level-6:before {
counter-increment: toc-sec-last;
content: counter(toc-sec-chapter, upper-roman) "." counter(toc-sec-section, upper-roman) "." counter(toc-sec-sub-section, upper-roman) "." counter(toc-sec-composite, upper-roman) "." counter(toc-sec-detail, upper-roman) "." counter(toc-last, upper-roman) " ";
}

Loading

0 comments on commit 184a58d

Please sign in to comment.