[−][src]Crate cursive_markup
cursive-markup provides the MarkupView for cursive that can render HTML or other
markup.
Quickstart
To render an HTML document, create a MarkupView with the html method, configure the
maximum line width using the set_maximum_width method and set callbacks for the links
using the on_link_select and on_link_focus methods.
Typically, you’ll want to wrap the view in a ScrollView and add it to a
Cursive instance.
// Create the markup view let html = "<a href='https://rust-lang.org'>Rust</a>"; let mut view = cursive_markup::MarkupView::html(&html); view.set_maximum_width(120); // Set callbacks that are called if the link focus is changed and if a link is selected with // the Enter key view.on_link_focus(|s, url| {}); view.on_link_select(|s, url| {}); // Add the view to a Cursive instance use cursive::view::{Resizable, Scrollable}; let mut s = cursive::dummy(); s.add_global_callback('q', |s| s.quit()); s.add_fullscreen_layer(view.scrollable().full_screen()); s.run();
You can use the arrow keys to navigate between the links and press Enter to trigger the
on_link_select callback.
For a complete example, see examples/browser.rs, a very simple browser implementation.
Components
The main component of the crate is MarkupView. It is a cursive view that displays
hypertext: a combination of formatted text and links. You can use the arrow keys to navigate
between the links, and the Enter key to select a link.
The displayed content is provided and rendered by a Renderer instance. If the html
feature is enabled (default), the html::Renderer can be used to parse and render an HTML
document with html2text. But you can also implement your own Renderer.
MarkupView caches the rendered document (RenderedDocument) and only invokes the
renderer if the width of the view has been changed.
HTML rendering
To customize the HTML rendering, you can change the TextDecorator that is used by
html2text to transform the HTML DOM into annotated strings. Of course the renderer must
know how to interpret the annotations, so if you provide a custom decorator, you also have to
provide a Converter that extracts formatting and links from the annotations.
Modules
| html | A renderer for HTML documents. |
Structs
| Element | A hypertext element: a formatted string with an optional link target. |
| MarkupView | A view for hypertext that has been rendered by a |
| RenderedDocument | A rendered hypertext document that consists of lines of formatted text and links. |
Traits
| Renderer | A renderer that produces a hypertext document. |
Type Definitions
| LinkCallback | A callback that is triggered for a link. |