@matrix-js/irc-formatting
v0.0.1
Published
Convert between basic HTML markup and IRC formatting codes
Readme
@matrix-js/irc-formatting
HTML to IRC
Convert basic HTML markup elements to IRC formatting codes. Intended for a subset of the HTML elements defined in the Matrix m.room.message spec. Unknown elements will have their tags discarded (but not their content).
| HTML | IRC | Style
|---|---|---|
| <b>, <strong> | 0x02 | Bold |
| <i>, <em> | 0x1D | Italics |
| <u> | 0x1F | Underline |
| <s>, <del> | 0x1E | Strikethrough |
| <code> | 0x11 | Monospace |
| <font>, <span> | 0x03 | Color |
For <font> and <span> to set the foreground and background color, these attributes are used:
| Attribute | Color
|---|---|
| data-mx-color, color | Foreground |
| data-mx-bg-color, bgcolor | Background |
| data-mx-spoiler | Spoiler (foreground and background colors set to gray) |
For usage in combination with sanitize-html or sanitize-replace-html to sanitize/transform HTML beforehand, this package exports the allowedTags and allowedAttributes it is able to properly use.
Example
const { htmlToIrc } = require("@matrix-js/irc-formatting");
const html = `<b>bold</b> <b>bold <i>with <span color="red">red italics</span></i> <span color="black" bgcolor="lime">limes limes limes</span></b> normal text <span bgcolor="red">red bg<span bgcolor="yellow" color="black"><b>CYBER</b></span>red bg continues</span>`;
let result = htmlToIrc(html);
console.log("html:", html);
console.log("irc:", result);
// \x02bold\x02 \x02bold \x02\x1dwith \x04FF0000\x02\x1dred italics\x04\x02 \x04000000,00FC00\x02limes limes limes\x04\x02 normal text \x04FFFFFF,FF0000red bg\x04000000,FFFF00\x02CYBER\x04FFFFFF,FF0000\x02red bg continues
console.log("allowedTags:", htmlToIrc.allowedTags);
console.log("allowedAttributes:", htmlToIrc.allowedAttributes);IRC to HTML
Work in progress.
License, donations
GPL-3.0. If you want to support my work, you can:
Changelog
0.0.1 (December 23, 2024)
- Initial release
