Skip to content

Commit

Permalink
Merge pull request #1 from tadzik/add-strike-support
Browse files Browse the repository at this point in the history
Fixup strikethrough support
  • Loading branch information
thomwiggers authored Aug 4, 2024
2 parents 8908be3 + 6be5205 commit d4cc1a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions spec/unit/formatting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe("Formatting", function() {
formatting.ircToHtml("The quick brown \u0002fox\u000f jumps over the lazy \u0002dog\u000f.")
).toBe("The quick brown <b>fox</b> jumps over the lazy <b>dog</b>.");
});
it("should <del> for strikethrough inputs", function() {
expect(
formatting.ircToHtml("The quick brown \u001efox\u000f jumps over the lazy \u001edog\u000f.")
).toBe("The quick brown <del>fox</del> jumps over the lazy <del>dog</del>.");
});
it("should <code> for monospace inputs", function() {
expect(
formatting.ircToHtml("The quick brown \u0011fox\u000f jumps over the lazy \u0011dog\u000f.")
Expand Down
8 changes: 4 additions & 4 deletions src/irc/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function htmlToIrc(html?: string): string|null {
// things like case-sensitivity and spacing). Use he to decode any html entities
// because we don't want those.
let cleanHtml = he.decode(sanitizeHtml(html, {
allowedTags: ["b", "code", "i", "u", "strong", "font", "em"],
allowedTags: ["b", "code", "del", "i", "u", "strong", "font", "em"],
allowedAttributes: {
font: ["color"]
}
Expand Down Expand Up @@ -262,13 +262,13 @@ export function ircToHtml(text: string): string {
// Replace all mIRC formatting characters.
// The color character can have arguments.
// The regex matches:
// - Any single 'simple' formatting character: \x02, \x11, \x1d, \x1f, \x0f and
// \x16 for bold, italics, underline, reset and reverse respectively.
// - Any single 'simple' formatting character: \x02, \x11, \x1d, \x1e, \x1f, \x0f and
// \x16 for bold, italics, underline, strikethrough, reset and reverse respectively.
// - The colour formatting character (\x03) followed by 0 to 2 digits for
// the foreground colour and (optionally) a comma and 1-2 digits for the
// background colour.
// eslint-disable-next-line no-control-regex
const colorRegex = /[\x02\x11\x1d\x1f\x0f\x16]|\x03(\d{0,2})(?:,(\d{1,2}))?/g;
const colorRegex = /[\x02\x11\x1d\x1e\x1f\x0f\x16]|\x03(\d{0,2})(?:,(\d{1,2}))?/g;

// Maintain a small state machine of which tags are open so we can close the right
// ones on RESET codes and toggle appropriately if they do the same code again.
Expand Down

0 comments on commit d4cc1a3

Please sign in to comment.