[][src]Crate cursive_markup

cursive-markup provides the MarkupView for cursive that can render HTML or other markup.


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);

// 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());

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.


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.



A renderer for HTML documents.



A hypertext element: a formatted string with an optional link target.


A view for hypertext that has been rendered by a Renderer.


A rendered hypertext document that consists of lines of formatted text and links.



A renderer that produces a hypertext document.

Type Definitions


A callback that is triggered for a link.