summaryrefslogtreecommitdiff
path: root/_includes
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-03-26 20:35:25 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-03-26 20:42:50 -0700
commitabd0895322985dd4a590f3dd96a488f4e4ff87bf (patch)
tree458be2ba2e8e9c017ff51b7e50a402b688179b4a /_includes
parent5997e32397db4efac1cbb3b74bd29289d203a775 (diff)
downloadscala-abd0895322985dd4a590f3dd96a488f4e4ff87bf.tar.gz
scala-abd0895322985dd4a590f3dd96a488f4e4ff87bf.tar.bz2
scala-abd0895322985dd4a590f3dd96a488f4e4ff87bf.zip
Fix #6: automatic section numbering.
Add chapter number to YAML, which is replace in numbering.css. Use CSS counters for chapters, sections, subsections | examples. Examples are detected by looking at the H3 element's id, which redcarpet derives from the heading's title. It must start with "Example:", and the whole title is suppressed by a little javascript, so we can make Examples look like in the pdf. For example, `### Example:` becomes `Example 3.2.10`, if it's the 10th example in Section 3.2.
Diffstat (limited to '_includes')
-rw-r--r--_includes/numbering.css56
1 files changed, 56 insertions, 0 deletions
diff --git a/_includes/numbering.css b/_includes/numbering.css
new file mode 100644
index 0000000000..e8404652dc
--- /dev/null
+++ b/_includes/numbering.css
@@ -0,0 +1,56 @@
+// based on http://philarcher.org/css/numberheadings.css,
+h1 {
+ /* must reset here */
+ counter-reset: chapter {{ page.chapter }};
+}
+h1:before {
+ /* and must reset again here */
+ counter-reset: chapter {{ page.chapter }};
+ content: "Chapter " counter(chapter);
+ display: block;
+}
+
+h2 {
+ /* must increment here */
+ counter-increment: section;
+ counter-reset: subsection;
+}
+h2:before {
+ /* and must reset again here */
+ counter-reset: chapter {{ page.chapter }};
+
+ content: counter(chapter) "." counter(section) ;
+ display: inline;
+ margin-right: 1em;
+}
+h2:after {
+ /* can only have one counter-reset per tag, so can't do it in h2/h2:before... */
+ counter-reset: example;
+}
+
+h3 {
+ /* must increment here */
+ counter-increment: subsection;
+}
+h3:before {
+ /* and must reset again here */
+ counter-reset: chapter {{ page.chapter }};
+
+ content: counter(chapter) "." counter(section) "." counter(subsection);
+ display: inline;
+ margin-right: 1em;
+}
+
+h3[id*='example:'] {
+ /* must increment here */
+ counter-increment: example;
+ display: inline;
+}
+h3[id*='example:']:before {
+ /* and must reset again here */
+ counter-reset: chapter {{ page.chapter }};
+
+ content: "Example " counter(chapter) "." counter(section) "." counter(example);
+ display: inline;
+ margin-right: 1em;
+}