stream-sac
Stream related functions
Installation
Usage
The source code is the documentation.
concatAsStream.js
import {
concatAsStream,
} from "stream-sac/source/concatAsStream.js";
streamifyStringFunction.js
import {
streamifyStringFunction,
} from "stream-sac/source/streamifyStringFunction.js";
HtmlMinifier.js
The input should be valid. Optional pass jsMinifier and cssMinifier to minify inline.
import {
HtmlMinifier,
} from "stream-sac/source/html/HtmlMinifier.js";
const htmlStream = new HtmlMinifier({
jsMinifier: (x) => x,
cssMinifier: (y) => y,
});
MarkdownParser.js
The input should be valid.
import {
MarkdownParser,
} from "stream-sac/source/markdown/MarkdownParserNode.js";
const markdownStream = new MarkdownParser({
// all optional
languagePrefix: `language-`,
highlight: function (str, lang) {
// import hljs to get code highlighting
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (__) {}
}
return ``;
},
// for example to resize images on the fly
mediaHook: function (src, alt) {
return `<img alt="${alt}" src="${src}">`;
},
// for example to disable all external links
linkHrefHook: function (src) {
if (!src.startsWith("https://example.com")) {
return "#";
}
return src;
}
});
Deno and Web
createMarkdownParserStream
takes the same options as above, however it is a function that returns a web transform stream. It expects data to be strings, so TextDecoderStream may have to be used
import { createMarkdownParserStream } from "stream-sac/built/MarkdownParserWeb.es.js"
// or
import { createMarkdownParserStream } from "https://unpkg.com/stream-sac/built/MarkdownParserWeb.es.js";