fn render(
        &self,
        out: &mut dyn Write,
        handle_apostrophes: Apostrophes,
    ) -> Result<(), std::io::Error> {
        match self {
            Self::Control { name, args } => {
                write!(out, ".{}", name)?;
                for arg in args {
                    write!(out, " {}", &escape_spaces(arg))?;
                }
            }
            Self::Text(inlines) => {
                let mut at_line_start = true;
                for inline in inlines.iter() {
                    // We need to handle line breaking specially: it
                    // introduces a control line to the ROFF, and the
                    // leading period of that mustn't be escaped.
                    match inline {
                        Inline::LineBreak => {
                            if at_line_start {
                                writeln!(out, ".br")?;
                            } else {
                                writeln!(out, "\n.br")?;
                            }
                        }
                        Inline::Roman(text) | Inline::Italic(text) | Inline::Bold(text) => {
                            let mut text = escape_inline(text);
                            if handle_apostrophes == Apostrophes::Handle {
                                text = escape_apostrophes(&text)
                            };
                            let text = escape_leading_cc(&text);
                            if let Inline::Bold(_) = inline {
                                write!(out, r"\fB{}\fR", text)?;
                            } else if let Inline::Italic(_) = inline {
                                write!(out, r"\fI{}\fR", text)?;
                            } else {
                                if at_line_start && starts_with_cc(&text) {
                                    // Line would start with a period, so we
                                    // insert a non-printable, zero-width glyph to
                                    // prevent it from being interpreted as such.
                                    // We only do that when it's needed, though,
                                    // to avoid making the output ugly.
                                    //
                                    // Note that this isn't handled by
                                    // escape_leading_cc, as it
                                    // doesn't know when an inline
                                    // element is at the start of a
                                    // line.
                                    write!(out, r"\&").unwrap();
                                }
                                write!(out, "{}", text)?;
                            }
                        }
                    }
                    at_line_start = false;
                }
            }
        };
        writeln!(out)?;
        Ok(())
    }
/// Generate a ROFF line.
///
/// All the ROFF code generation and special handling happens here.
Generate a ROFF line.
All the ROFF code generation and special handling happens here.
Generate a ROFF line . All the ROFF code generation and special handling happens here .
fn render(
        &self,
        out: &mut dyn Write,
        handle_apostrophes: Apostrophes,
    ) -> Result<(), std::io::Error> {
        match self {
            Self::Control { name, args } => {
                write!(out, ".{}", name)?;
                for arg in args {
                    write!(out, " {}", &escape_spaces(arg))?;
                }
            }
            Self::Text(inlines) => {
                let mut at_line_start = true;
                for inline in inlines.iter() {
                    // We need to handle line breaking specially: it
                    // introduces a control line to the ROFF, and the
                    // leading period of that mustn't be escaped.
                    match inline {
                        Inline::LineBreak => {
                            if at_line_start {
                                writeln!(out, ".br")?;
                            } else {
                                writeln!(out, "\n.br")?;
                            }
                        }
                        Inline::Roman(text) | Inline::Italic(text) | Inline::Bold(text) => {
                            let mut text = escape_inline(text);
                            if handle_apostrophes == Apostrophes::Handle {
                                text = escape_apostrophes(&text)
                            };
                            let text = escape_leading_cc(&text);
                            if let Inline::Bold(_) = inline {
                                write!(out, r"\fB{}\fR", text)?;
                            } else if let Inline::Italic(_) = inline {
                                write!(out, r"\fI{}\fR", text)?;
                            } else {
                                if at_line_start && starts_with_cc(&text) {
                                    // Line would start with a period, so we
                                    // insert a non-printable, zero-width glyph to
                                    // prevent it from being interpreted as such.
                                    // We only do that when it's needed, though,
                                    // to avoid making the output ugly.
                                    //
                                    // Note that this isn't handled by
                                    // escape_leading_cc, as it
                                    // doesn't know when an inline
                                    // element is at the start of a
                                    // line.
                                    write!(out, r"\&").unwrap();
                                }
                                write!(out, "{}", text)?;
                            }
                        }
                    }
                    at_line_start = false;
                }
            }
        };
        writeln!(out)?;
        Ok(())
    }
fn render ( & self , out : & mut dyn Write , handle_apostrophes : Apostrophes , ) -> Result < ( ) , std :: io :: Error > { match self { Self :: Control { name , args } => { write ! ( out " " name ) ? ; for arg in args { write ! ( out " " escape_spaces ( arg ) ) ? ; } } Self :: Text ( inlines ) => { let mut at_line_start = true ; for inline in inlines . iter ( ) { // We need to handle line breaking specially: it // introduces a control line to the ROFF, and the // leading period of that mustn't be escaped. match inline { Inline :: LineBreak => { if at_line_start { writeln ! ( out " " ) ? ; } else { writeln ! ( out " \n " ) ? ; } } Inline :: Roman ( text ) | Inline :: Italic ( text ) | Inline :: Bold ( text ) => { let mut text = escape_inline ( text ) ; if handle_apostrophes == Apostrophes :: Handle { text = escape_apostrophes ( & text ) } ; let text = escape_leading_cc ( & text ) ; if let Inline :: Bold ( _ ) = inline { write ! ( out r"\fB{}\fR" text ) ? ; } else if let Inline :: Italic ( _ ) = inline { write ! ( out r"\fI{}\fR" text ) ? ; } else { if at_line_start && starts_with_cc ( & text ) { // Line would start with a period, so we // insert a non-printable, zero-width glyph to // prevent it from being interpreted as such. // We only do that when it's needed, though, // to avoid making the output ugly. // // Note that this isn't handled by // escape_leading_cc, as it // doesn't know when an inline // element is at the start of a // line. write ! ( out r"\&" ) . unwrap ( ) ; } write ! ( out " " text ) ? ; } } } at_line_start = false ; } } } ; writeln ! ( out ) ? ; Ok ( ( ) ) }
Generate a ROFF line.
Generate a ROFF line .
&self
out
&mut dyn Write
handle_apostrophes
Apostrophes