From 890161a7e02d138fdc56202c86f8fb78b7429893 Mon Sep 17 00:00:00 2001 From: finanalyst Date: Sat, 16 Dec 2023 10:51:47 +0000 Subject: [PATCH] start work on numbered headings --- .gitignore | 1 + lib/ProcessedPod.rakumod | 214 ++++++++++++++-------- xt/75-numbered.rakutest | 374 ++++++++++++++++++++++++++++++++++++++ xt/80-placements.rakutest | 77 ++++++++ 4 files changed, 588 insertions(+), 78 deletions(-) create mode 100644 xt/75-numbered.rakutest create mode 100644 xt/80-placements.rakutest diff --git a/.gitignore b/.gitignore index a6f976c..1a9965b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ raku-pod-render.iml /.sass-cache/ /problems/ /check/ +/dump diff --git a/lib/ProcessedPod.rakumod b/lib/ProcessedPod.rakumod index 3825aed..2f0934f 100644 --- a/lib/ProcessedPod.rakumod +++ b/lib/ProcessedPod.rakumod @@ -40,6 +40,25 @@ grammar FC { # TODO: use "make" to pull inside-quotes value to meta } +#| Class for setting numeration of headings and items +class Numeration { + has Int @!counters is default(0); + method Str () { @!counters>>.Str.join('.') ~ '.' } + method inc ($level) { + @!counters[$level - 1]++; + @!counters.splice($level); + self + } + method reset () { + @!counters = Nil; + self + } + method set ( $level, $value ) { + @!counters[ $level - 1 ] = $value; + self + } +} + #| the name of the anchor at the top of a source file constant DEFAULT_TOP = '___top'; @@ -178,9 +197,14 @@ class ProcessedPod does SetupTemplates { # variables to manage Pod state, where rendering is dependent on local context #| for multilevel lists has @.itemlist; + #| item counter + has Numeration $.item-counter .= new; #| used to register state when processing a definition list has Bool $!in-defn-list = False; + #| for numbered headings + has Numeration $.header-counter .=new; + #| the Config stack has @.config-stack ; #| contains the configuration for the outer pod/rakudoc block @@ -597,15 +621,16 @@ class ProcessedPod does SetupTemplates { my $template = $node.config