Crate gemrendr

Crate gemrendr 

Source
Expand description

Turns Gemtext into idiomatic HTML.

let document = "# Hello, world!";
let output = gemrendr::html_from_gemtext(document, Default::default());
assert!(output.ends_with("<h1>Hello, world!</h1>"));

By default, the output includes a comment that points to gemrendr’s public source code repository. To omit this line, configure render options like so:

use gemrendr::{RenderOptions, html_from_gemtext};

let options = RenderOptions {
	preamble: false,
	..Default::default()
};
let document = "# Hello, world!";
let output = html_from_gemtext(document, options);
assert_eq!(output, "<h1>Hello, world!</h1>");

See RenderOptions for more available options.

To only parse the gemtext, without transforming it right away into an HTML string, use the various parse methods on gemtext::Document:

use gemrendr::gemtext::Document;

let parsed = Document::parse_from_gemtext("# Hello, world!");
let also_parsed = "# Hello, world!".parse::<Document>().unwrap();

With this representation you can, for example, do additional processing to determine the page title (e.g. by considering first headings). To convert the parsed document data into HTML, use Document::into_html:

use gemrendr::gemtext::Document;

let parsed = Document::parse_from_gemtext("# Hello, world!");
/* do something with parsed */
let output = parsed.into_html(Default::default());
assert!(output.into_string().ends_with("<h1>Hello, world!</h1>"));

§Crate Features

  • std (enabled by default) — When not enabled, gemrendr is guaranteed not to use any standard library features (other than core and alloc).

Modules§

gemtext
Structures that deal with deserialized Gemtext documents.

Structs§

RenderOptions
Options to use when rendering Gemtext as HTML.

Enums§

CopyButtonStyle
Whether and how a Copy Text button should be generated in preformatted blocks.
EmptyLineTag
The tag that should be used to represent empty Text lines.

Functions§

html_from_gemtext
Transforms the given Gemtext document string into an HTML document string.