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.
- Markstream
Plugin - Installs the markstream assets in an Autumn app.
Enums§
- Html
Policy - What markstream does with raw HTML in the Markdown (
htmlPolicyprop). - Mode
- The markstream render mode (
modeprop). - Theme
- The color theme.
Constants§
- ALLOW_
TRUSTED_ META - Name of the meta tag that allows
HtmlPolicy::Trustedon 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::Trustedon this page. - markstream_
head - Writes all markstream head tags: styles, preloads, then the script.
- markstream_
preloads - Writes one
<link rel="modulepreload">forcore.jsand 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.