Crate roffman

Source
Expand description

§roffman - create ROFF man pages in rust with ease!

§Example usage

use roffman::{Roff, RoffNode, Roffable, SectionNumber, SynopsisOpt};

let roff = Roff::new("roffman", SectionNumber::Miscellaneous)
.date("August 2021")
.section(
   "BASIC USAGE",
   [
       RoffNode::paragraph([
           "This is how you create a basic paragraph using roffman.",
       ]),
       RoffNode::indented_paragraph(
           [
               "This line should be slightly indented to the ".roff(),
               "right.".roff().bold(),
           ],
           Some(4),
           Some("optional-title")
       ),
       RoffNode::synopsis(
                "roffman-command",
                [
                "This is the description of this command. It will be displayed right next to".roff(),
" it".roff().italic()
]                     ,
                [
                SynopsisOpt::new("--opt").description(["some simple opt"]),
                SynopsisOpt::new("--opt-with-arg").argument("ARG").description(["opt with an argument"]),
                SynopsisOpt::new("--bold")
       ]),
       RoffNode::paragraph(["Example:".roff().bold()]),
       RoffNode::example([
            r#"
impl Roffable for u8 {
    fn roff(&self) -> RoffText {
        self.to_string().roff()
    }
}"#,
        ]),
       RoffNode::url("GitHub", "https://github.com/vv9k/roffman"),
       RoffNode::text("\nvv9k"),
       RoffNode::trademark_sign(),
    ],
);

let rendered = roff.to_string().unwrap();

let output = r#".TH roffman 7 "August 2021"
.SH "BASIC USAGE"
.P
This is how you create a basic paragraph using roffman.
.IP optional\-title 4
This line should be slightly indented to the \fBright.\fR
.SY roffman\-command
This is the description of this command. It will be displayed right next to\fI it\fR

.OP \-\-opt
some simple opt

.OP \-\-opt\-with\-arg ARG
opt with an argument

.OP \-\-bold

.YS
.P
\fBExample:\fR
.EX

impl Roffable for u8 {
    fn roff(&self) \-> RoffText {
        self.to_string().roff()
    }
}
.EE
.UR https://github.com/vv9k/roffman
GitHub
.UE

vv9k\*(Tm
"#;

assert_eq!(rendered.trim(), output.trim());

which will look something like this:

roffman(7)                                         Miscellaneous Information Manual                                  roffman(7)

BASIC USAGE
       This is how you create a basic paragraph using roffman.

           This line should be slightly indented to the right.

       roffman-command This is the description of this command. It will be displayed right next to it

                       [--opt] some simple opt

                       [--opt-with-arg ARG] opt with an argument

                       [--bold]

       Example:

       impl Roffable for u8 {
           fn roff(&self) -> RoffText {
               self.to_string().roff()
           }
       }
       GitHub ⟨https://github.com/vv9k/roffman⟩

       vv9k™
                                                              August 2021                                             roffman(7)

Structs§

Roff
Represents a ROFF document that can be rendered and displayed with tools like man.
RoffNode
Building block of ROFF documents.
RoffText
Wrapper type for styled text in ROFF. The most basic unit of text used in the document. It can be styled with various FontStyles and will escape it’s contents on creation so that they are safe to render and will be correctly displayed on various viewers.
Section
A single section of the ROFF document.
SynopsisOpt
An option used by the RoffNode::synopsis block.

Enums§

FontStyle
Style that can be applied to RoffText.
RoffError
An error type returned by the functions used in this crate.
SectionNumber
Defines the section to which the given ROFF belongs.

Traits§

IntoRoffNode
A trait that describes items that can be turned into a RoffNode.
Roffable
Convenience trait to convert items to RoffText.