diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0664ea87..0e007a37 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -242,7 +242,7 @@ pages: - mkdir public - mv -v target/doc public/impl - - for M in /tmp/assets/man-pages/*; do pandoc -s $M -L src/man-pandoc.lua -o $M.html ; done + - for M in /tmp/assets/man-pages/*; do pandoc -s $M -L src/man-pandoc.lua -H src/man-pandoc.inc.html -o $M.html ; done - mkdir public/man - mv -v /tmp/assets/man-pages/*.html public/man diff --git a/src/man-pandoc.inc.html b/src/man-pandoc.inc.html new file mode 100644 index 00000000..0a75a42c --- /dev/null +++ b/src/man-pandoc.inc.html @@ -0,0 +1,5 @@ + diff --git a/src/man.rs b/src/man.rs index 14a1b6f3..99fe9cec 100644 --- a/src/man.rs +++ b/src/man.rs @@ -550,6 +550,9 @@ impl CommandOption { pub struct ManualPage { filename: PathBuf, roff: Roff, + + // Are we in code mode (emitted .nf)? + in_code: bool, } impl ManualPage { @@ -557,6 +560,7 @@ impl ManualPage { Self { filename, roff: Roff::new(), + in_code: false, } } @@ -577,6 +581,22 @@ impl ManualPage { self.roff.text([roman(&format!("{} - {}", name, summary))]); } + /// Typeset code blocks, joining adjacent blocks. + fn code(&mut self, code: bool) { + match (self.in_code, code) { + (false, false) => (), + (false, true) => { + self.roff.control("nf", []); + self.in_code = true; + }, + (true, false) => { + self.roff.control("fi", []); + self.in_code = false; + }, + (true, true) => (), + } + } + /// Typeset the synopsis of a command. This is going to be part of /// the SYNOPSIS section. There are conventions for how it should /// be typeset. For sq, we simplify them by summarizing options @@ -690,6 +710,7 @@ impl ManualPage { TARGET_LINE_LENGTH - 3 * RS_INDENTATION; if let Some(line) = line.strip_prefix("# ") { + self.code(false); self.roff.text([roman(line)]); } else if let Some(line) = line.strip_prefix("$ ") { let line = line.trim(); @@ -698,11 +719,10 @@ impl ManualPage { EXAMPLE_COMMAND_MAX_WIDTH); fail!("{}", line); } - self.roff.control("nf", []); + self.code(true); self.roff.control("RS", []); self.roff.text([roman(line)]); self.roff.control("RE", []); - self.roff.control("fi", []); } else if continuation { let line = line.trim(); if line.len() > EXAMPLE_CONTINUATION_MAX_WIDTH { @@ -710,14 +730,14 @@ impl ManualPage { EXAMPLE_CONTINUATION_MAX_WIDTH); fail!("{}", line); } - self.roff.control("nf", []); + self.code(true); self.roff.control("RS", []); self.roff.control("RS", []); self.roff.text([roman(line)]); self.roff.control("RE", []); self.roff.control("RE", []); - self.roff.control("fi", []); } else { + self.code(false); self.roff.text([roman(line)]); } @@ -733,6 +753,8 @@ impl ManualPage { need_para = true; } } + + self.code(false); } } }