Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translating colours on Matrix #32

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/format/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule M51.Format do
iex> M51.Format.matrix2irc(~s(foo<br/>bar))
"foo\nbar"

iex> M51.Format.matrix2irc(~s(foo <font data-mx-color="FF0000">bar</font> baz))
iex> M51.Format.matrix2irc(~s(foo <font data-mx-color="#FF0000">bar</font> baz))
"foo \x04FF0000,FFFFFFbar\x0399,99 baz"
"""
def matrix2irc(html, homeserver \\ nil) do
Expand All @@ -81,8 +81,8 @@ defmodule M51.Format do
{"foo\nbar", ~s(foo<br/>bar)}

iex> M51.Format.irc2matrix("foo \x0304bar")
{"foo bar", ~s(foo <font data-mx-color="FF0000">bar</font>)}
{"foo bar", ~s(foo <font data-mx-color="#FF0000">bar</font>)}

"""
def irc2matrix(text, nicklist \\ []) do
stateful_tokens =
Expand Down
202 changes: 101 additions & 101 deletions lib/format/irc2matrix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,203 +34,203 @@ defmodule M51.Format.Irc2Matrix do
# * https://modern.ircdocs.horse/formatting.html#colors-16-98
@color2hex {
# 00, white
"FFFFFF",
"#FFFFFF",
# 01, black
"000000",
"#000000",
# 02, blue
"0000FF",
"#0000FF",
# 03, green
"009300",
"#009300",
# 04, red
"FF0000",
"#FF0000",
# 05, brown
"7F0000",
"#7F0000",
# 06, magenta
"9C009C",
"#9C009C",
# 07, orange
"FC7F00",
"#FC7F00",
# 08, yellow
"FFFF00",
"#FFFF00",
# 09, light green
"00FC00",
"#00FC00",
# 10, cyan
"009393",
"#009393",
# 11, light cyan
"00FFFF",
"#00FFFF",
# 12, light blue
"0000FC",
"#0000FC",
# 13, pink
"FF00FF",
"#FF00FF",
# 14, grey
"7F7F7F",
"#7F7F7F",
# 15, light grey
"D2D2D2",
"#D2D2D2",
# 16
"470000",
"#470000",
# 17
"472100",
"#472100",
# 18
"474700",
"#474700",
# 19
"324700",
"#324700",
# 20
"004700",
"#004700",
# 21
"00472C",
"#00472C",
# 22
"004747",
"#004747",
# 23
"002747",
"#002747",
# 24
"000047",
"#000047",
# 25
"2E0047",
"#2E0047",
# 26
"470047",
"#470047",
# 27
"47002A",
"#47002A",
# 28
"740000",
"#740000",
# 29
"743A00",
"#743A00",
# 30
"747400",
"#747400",
# 31
"517400",
"#517400",
# 32
"007400",
"#007400",
# 33
"007449",
"#007449",
# 34
"007474",
"#007474",
# 35
"004074",
"#004074",
# 36
"000074",
"#000074",
# 37
"4B0074",
"#4B0074",
# 38
"740074",
"#740074",
# 39
"740045",
"#740045",
# 40
"B50000",
"#B50000",
# 41
"B56300",
"#B56300",
# 42
"B5B500",
"#B5B500",
# 43
"7DB500",
"#7DB500",
# 44
"00B500",
"#00B500",
# 45
"00B571",
"#00B571",
# 46
"00B5B5",
"#00B5B5",
# 47
"0063B5",
"#0063B5",
# 48
"0000B5",
"#0000B5",
# 49
"7500B5",
"#7500B5",
# 50
"B500B5",
"#B500B5",
# 51
"B5006B",
"#B5006B",
# 52
"FF0000",
"#FF0000",
# 53
"FF8C00",
"#FF8C00",
# 54
"FFFF00",
"#FFFF00",
# 55
"B2FF00",
"#B2FF00",
# 56
"00FF00",
"#00FF00",
# 57
"00FFA0",
"#00FFA0",
# 58
"00FFFF",
"#00FFFF",
# 59
"008CFF",
"#008CFF",
# 60
"0000FF",
"#0000FF",
# 61
"A500FF",
"#A500FF",
# 62
"FF00FF",
"#FF00FF",
# 63
"FF0098",
"#FF0098",
# 64
"FF5959",
"#FF5959",
# 65
"FFB459",
"#FFB459",
# 66
"FFFF71",
"#FFFF71",
# 67
"CFFF60",
"#CFFF60",
# 68
"6FFF6F",
"#6FFF6F",
# 69
"65FFC9",
"#65FFC9",
# 70
"6DFFFF",
"#6DFFFF",
# 71
"59B4FF",
"#59B4FF",
# 72
"5959FF",
"#5959FF",
# 73
"C459FF",
"#C459FF",
# 74
"FF66FF",
"#FF66FF",
# 75
"FF59BC",
"#FF59BC",
# 76
"FF9C9C",
"#FF9C9C",
# 77
"FFD39C",
"#FFD39C",
# 78
"FFFF9C",
"#FFFF9C",
# 79
"E2FF9C",
"#E2FF9C",
# 80
"9CFF9C",
"#9CFF9C",
# 81
"9CFFDB",
"#9CFFDB",
# 82
"9CFFFF",
"#9CFFFF",
# 83
"9CD3FF",
"#9CD3FF",
# 84
"9C9CFF",
"#9C9CFF",
# 85
"DC9CFF",
"#DC9CFF",
# 86
"FF9CFF",
"#FF9CFF",
# 87
"FF94D3",
"#FF94D3",
# 88
"000000",
"#000000",
# 89
"131313",
"#131313",
# 90
"282828",
"#282828",
# 91
"363636",
"#363636",
# 92
"4D4D4D",
"#4D4D4D",
# 93
"656565",
"#656565",
# 94
"818181",
"#818181",
# 95
"9F9F9F",
"#9F9F9F",
# 96
"BCBCBC",
"#BCBCBC",
# 97
"E2E2E2",
"#E2E2E2",
# 98
"FFFFFF",
"#FFFFFF",
# 99, reset
nil
}
Expand Down Expand Up @@ -361,10 +361,10 @@ defmodule M51.Format.Irc2Matrix do
{:color, nil, nil}

<<0x04, a, b, c, d, e, f, ?,, g, h, i, j, k, l>> ->
{:color, <<a, b, c, d, e, f>>, <<g, h, i, j, k, l>>}
{:color, "#" <> <<a, b, c, d, e, f>>, "#" <> <<g, h, i, j, k, l>>}

<<0x04, a, b, c, d, e, f, ?,>> ->
{:color, <<a, b, c, d, e, f>>, nil}
{:color, "#" <> <<a, b, c, d, e, f>>, nil}

<<0x04>> ->
{:color, nil, nil}
Expand Down
6 changes: 4 additions & 2 deletions lib/format/matrix2irc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,18 @@ defmodule M51.Format.Matrix2Irc do
transform_children(children, state)

_ ->
fg = String.trim_leading(fg || "000000", "#")
bg = String.trim_leading(bg || "FFFFFF", "#")
restored_colors =
case state.color do
# reset
{nil, nil} -> "\x0399,99"
{fg, bg} -> "\x04#{fg || "000000"},#{bg || "FFFFFF"}"
{fg, bg} -> "\x04#{fg},#{bg}"
end

state = %M51.Format.Matrix2Irc.State{state | color: {fg, bg}}

~s(\x04#{fg || "000000"},#{bg || "FFFFFF"}) <>
~s(\x04#{fg},#{bg}) <>
transform_children(children, state) <> restored_colors
end
end
Expand Down
Loading