Skip to main content

Crate autumn_plugin_markstream

Crate autumn_plugin_markstream 

Source
Expand description

markstream for Autumn: render and stream Markdown with Maud and htmx.

Add MarkstreamPlugin to the app. Put markstream_head() in the page head. Render Markdown with Markstream, and stream it with sse::markstream_sse:

use autumn_plugin_markstream::sse::{markstream_sse, stream};
use autumn_plugin_markstream::{Markstream, MarkstreamPlugin, Mode, markstream_head};
use autumn_web::prelude::*;

#[get("/")]
async fn index() -> Markup {
    html! {
        html {
            head { (markstream_head()) }
            body {
                (Markstream::new("# Hello\n\nSome *Markdown*."))
                (Markstream::stream("/answer").mode(Mode::Chat))
            }
        }
    }
}

#[get("/answer")]
async fn answer() -> impl IntoResponse {
    markstream_sse(stream::iter(["## Answer\n", "Some ", "*text*."]))
}

autumn_web::app()
    .plugin(MarkstreamPlugin::new())
    .routes(routes![index, answer])
    .run()
    .await;

The crate vendors markstream-vue MARKSTREAM_VERSION and Vue VUE_VERSION (runtime build). Autumn serves them from memory under /static/_plugins/markstream/. The page needs no inline script and no import map, so the default Autumn CSP works.

§Limits

  • Syntax highlighting is light: keywords, strings, numbers and comments for common languages. It is not Monaco or Shiki.
  • No Mermaid, D2 or infographic. These blocks show their source.
  • No KaTeX unless the page loads KaTeX as a global (window.katex).
  • The browser does not reconnect a stream. A dropped stream shows the error state.

Modules§

sse
Server-Sent Events that stream Markdown into a Markstream.

Structs§

Markstream
One markstream container: Markdown, an optional stream URL and options.
MarkstreamPlugin
Installs the markstream assets in an Autumn app.

Enums§

HtmlPolicy
What markstream does with raw HTML in the Markdown (htmlPolicy prop).
Mode
The markstream render mode (mode prop).
Theme
The color theme.

Constants§

ALLOW_TRUSTED_META
Name of the meta tag that allows HtmlPolicy::Trusted on a page.
ASSETS_NAMESPACE
URL namespace of the bundle: /static/_plugins/markstream/.
MARKSTREAM_VERSION
Vendored markstream-vue version.
PLUGIN_NAME
The plugin name in Autumn diagnostics.
VUE_VERSION
Vendored Vue version (runtime ESM build).

Statics§

MARKSTREAM_ASSETS
The plugin asset bundle.

Functions§

markstream_allow_trusted
Writes the meta tag that allows HtmlPolicy::Trusted on this page.
markstream_head
Writes all markstream head tags: styles, preloads, then the script.
markstream_preloads
Writes one <link rel="modulepreload"> for core.js and for each eager module.
markstream_script
Writes the <script type="module"> tag for the init module.
markstream_stylesheet
Writes the <link rel="stylesheet"> tags: markstream, then the plugin.