Improve rendering of examples.
- Join adjacent code blocks, prevent wrapping in HTML.
This commit is contained in:
parent
479aeaec22
commit
0f3a796bc1
@ -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
|
||||
|
||||
|
5
src/man-pandoc.inc.html
Normal file
5
src/man-pandoc.inc.html
Normal file
@ -0,0 +1,5 @@
|
||||
<style>
|
||||
code {
|
||||
white-space: pre;
|
||||
}
|
||||
</style>
|
30
src/man.rs
30
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user