postpostscript avatar
postpostscript
multiFormat
Script
multiFormat: easily create outputs of multiple formats (e.g. text/html for Email) using tagged templates Examples import { format } from "https://esm.town/v/postpostscript/multiFormat"; console.log(format.Plain` ${format.Heading1`Some Heading`} Lorem ipsum dolor ${format.Strong`sit`} amet `); { "text": "\nSome Heading\n\nLorem ipsum dolor sit amet\n", "html": "\n<br><h1>Some Heading</h1>\n<br>\n<br>Lorem ipsum dolor <strong>sit</strong> amet\n<br>" } Create Your Own Formatters import { createFormatMethod, wrapHTMLTag, type MultiFormatWithHTML } from "https://esm.town/v/postpostscript/multiFormat"; export const Red = createFormatMethod<MultiFormatWithHTML>((value) => { return wrapHTMLTag("span", value, { style: "color: red;", }); }); console.log(Red`red text!`) { "text": "red text!", "html": "<span style=\"color: red;\">red text!</span>" } Sanitization Text is automatically sanitized when converted to HTML: console.log(format.Trim` ${format.Heading1`Some Heading`} <script>alert(1)</script> `.html.toString()) <h1>Some Heading</h1> <br> <br>&lt;script&gt;alert(1)&lt;/script&gt;
0
postpostscript avatar
postpostscript
meta
Script
An interactive, runnable TypeScript val by postpostscript
0
postpostscript avatar
postpostscript
ast
Script
// need to keep track of offsets because span counters aren't being reset
0
1
Next