|
3 | 3 | use crate::util::{header_text, parse_name_and_section}; |
4 | 4 | use crate::EventIter; |
5 | 5 | use anyhow::{bail, Error}; |
6 | | -use pulldown_cmark::{Alignment, Event, LinkType, Tag}; |
| 6 | +use pulldown_cmark::{Alignment, Event, HeadingLevel, LinkType, Tag}; |
7 | 7 | use std::fmt::Write; |
8 | 8 | use url::Url; |
9 | 9 |
|
@@ -122,10 +122,10 @@ impl<'e> ManRenderer<'e> { |
122 | 122 | self.output.push_str(".sp\n"); |
123 | 123 | } |
124 | 124 | } |
125 | | - Tag::Heading(n) => { |
126 | | - if n == 1 { |
| 125 | + Tag::Heading(level, ..) => { |
| 126 | + if level == HeadingLevel::H1 { |
127 | 127 | self.push_top_header()?; |
128 | | - } else if n == 2 { |
| 128 | + } else if level == HeadingLevel::H2 { |
129 | 129 | // Section header |
130 | 130 | let text = header_text(&mut self.parser)?; |
131 | 131 | self.flush(); |
@@ -255,7 +255,7 @@ impl<'e> ManRenderer<'e> { |
255 | 255 | Event::End(tag) => { |
256 | 256 | match &tag { |
257 | 257 | Tag::Paragraph => self.flush(), |
258 | | - Tag::Heading(_n) => {} |
| 258 | + Tag::Heading(..) => {} |
259 | 259 | Tag::BlockQuote => { |
260 | 260 | self.flush(); |
261 | 261 | // restore left margin, restore line length |
@@ -400,21 +400,27 @@ impl<'e> ManRenderer<'e> { |
400 | 400 | } |
401 | 401 |
|
402 | 402 | fn escape(s: &str) -> Result<String, Error> { |
| 403 | + // Note: Possible source on output escape sequences: https://man7.org/linux/man-pages/man7/groff_char.7.html. |
| 404 | + // Otherwise, use generic escaping in the form `\[u1EE7]` or `\[u1F994]`. |
| 405 | + |
403 | 406 | let mut replaced = s |
404 | 407 | .replace('\\', "\\(rs") |
405 | 408 | .replace('-', "\\-") |
406 | 409 | .replace('\u{00A0}', "\\ ") // non-breaking space (non-stretchable) |
407 | 410 | .replace('–', "\\[en]") // \u{2013} en-dash |
408 | 411 | .replace('—', "\\[em]") // \u{2014} em-dash |
| 412 | + .replace('‘', "\\[oq]") // \u{2018} left single quote |
| 413 | + .replace('’', "\\[cq]") // \u{2019} right single quote or apostrophe |
| 414 | + .replace('“', "\\[lq]") // \u{201C} left double quote |
| 415 | + .replace('”', "\\[rq]") // \u{201D} right double quote |
| 416 | + .replace('…', "\\[u2026]") // \u{2026} ellipsis |
409 | 417 | .replace('│', "|") // \u{2502} box drawing light vertical (could use \[br]) |
410 | 418 | .replace('├', "|") // \u{251C} box drawings light vertical and right |
411 | 419 | .replace('└', "`") // \u{2514} box drawings light up and right |
412 | 420 | .replace('─', "\\-") // \u{2500} box drawing light horizontal |
413 | 421 | ; |
414 | 422 | if replaced.starts_with('.') { |
415 | 423 | replaced = format!("\\&.{}", &replaced[1..]); |
416 | | - } else if replaced.starts_with('\'') { |
417 | | - replaced = format!("\\(aq{}", &replaced[1..]); |
418 | 424 | } |
419 | 425 |
|
420 | 426 | if let Some(ch) = replaced.chars().find(|ch| { |
|
0 commit comments