noosphere_into/transform/
file.rs1use async_stream::stream;
2use futures::Stream;
3use noosphere_core::context::SphereFile;
4use noosphere_core::data::ContentType;
5use tokio::io::AsyncRead;
6
7use crate::{subtext_to_html_document_stream, subtext_to_html_fragment_stream, Transform};
8
9pub enum HtmlOutput {
11 Document,
13 Fragment,
15}
16
17pub fn file_to_html_stream<T, R>(
22 file: SphereFile<R>,
23 output: HtmlOutput,
24 transform: T,
25) -> impl Stream<Item = String>
26where
27 T: Transform,
28 R: AsyncRead + Unpin,
29{
30 stream! {
31 match file.memo.content_type() {
32 Some(ContentType::Subtext) => {
33 match output {
34 HtmlOutput::Document => {
35 let stream = subtext_to_html_document_stream(transform, file);
36 for await part in stream {
37 yield part;
38 }
39 },
40 HtmlOutput::Fragment => {
41 let stream = subtext_to_html_fragment_stream(file, transform);
42 for await part in stream {
43 yield part;
44 }
45 }
46 };
47 }
48 _ => {
49 yield "<article><p>Format cannot be rendered as HTML</p></article>".into();
50 }
51 };
52 }
53}