react-native-enriched 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/ReactNativeEnriched.podspec +5 -1
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +12 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +4 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.cpp +149 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/EventEmitters.h +146 -0
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/Props.cpp +16 -1
- package/android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec/Props.h +46 -0
- package/android/src/main/java/com/swmansion/enriched/common/GumboNormalizer.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCheckboxListSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedUnorderedListSpan.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt +166 -20
- package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/MeasurementStore.kt +19 -2
- package/android/src/main/java/com/swmansion/enriched/textinput/events/OnContextMenuItemPressEvent.kt +35 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedLineHeightSpan.kt +44 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt +16 -0
- package/android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpanState.kt +18 -12
- package/android/src/main/new_arch/CMakeLists.txt +9 -13
- package/android/src/main/new_arch/GumboNormalizerJni.cpp +14 -0
- package/android/src/main/new_arch/react/renderer/components/ReactNativeEnrichedSpec/conversions.h +2 -21
- package/cpp/CMakeLists.txt +50 -0
- package/cpp/GumboParser/GumboParser.h +34043 -0
- package/cpp/README.md +59 -0
- package/cpp/parser/GumboNormalizer.c +915 -0
- package/cpp/parser/GumboParser.cpp +16 -0
- package/cpp/parser/GumboParser.hpp +23 -0
- package/cpp/tests/GumboParserTest.cpp +457 -0
- package/ios/EnrichedTextInputView.h +2 -0
- package/ios/EnrichedTextInputView.mm +152 -2
- package/ios/config/InputConfig.h +3 -0
- package/ios/config/InputConfig.mm +15 -0
- package/ios/extensions/LayoutManagerExtension.mm +34 -11
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.cpp +149 -0
- package/ios/generated/ReactNativeEnrichedSpec/EventEmitters.h +146 -0
- package/ios/generated/ReactNativeEnrichedSpec/Props.cpp +16 -1
- package/ios/generated/ReactNativeEnrichedSpec/Props.h +46 -0
- package/ios/generated/ReactNativeEnrichedSpec/RCTComponentViewHelpers.h +29 -0
- package/ios/inputParser/InputParser.mm +27 -0
- package/ios/inputTextView/InputTextView.mm +3 -3
- package/lib/module/EnrichedTextInput.js +43 -30
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/spec/EnrichedTextInputNativeComponent.ts +118 -22
- package/lib/typescript/src/EnrichedTextInput.d.ts +24 -6
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts +111 -21
- package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/EnrichedTextInput.tsx +79 -40
- package/src/index.tsx +0 -1
- package/src/spec/EnrichedTextInputNativeComponent.ts +118 -22
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#include "GumboParser.hpp"
|
|
2
|
+
|
|
3
|
+
// C functions defined in GumboNormalizer.c (compiled as C)
|
|
4
|
+
extern "C" {
|
|
5
|
+
char *normalize_html(const char *html, size_t len);
|
|
6
|
+
void free_normalized_html(char *result);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
std::string GumboParser::normalizeHtml(const std::string &html) {
|
|
10
|
+
char *raw = normalize_html(html.c_str(), html.size());
|
|
11
|
+
if (!raw)
|
|
12
|
+
return {};
|
|
13
|
+
std::string result(raw);
|
|
14
|
+
free_normalized_html(raw);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform HTML normalizer powered by Gumbo.
|
|
3
|
+
* Converts arbitrary external HTML (Google Docs, Word, etc.) into a canonical
|
|
4
|
+
* subset that our enriched parser understands.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* C++ wrapper around the Gumbo-based HTML normalizer.
|
|
13
|
+
*/
|
|
14
|
+
class GumboParser {
|
|
15
|
+
public:
|
|
16
|
+
/**
|
|
17
|
+
* Normalize an HTML string into the canonical subset.
|
|
18
|
+
*
|
|
19
|
+
* @param html UTF-8 encoded HTML fragment or full document.
|
|
20
|
+
* @return Canonical HTML string, or empty string on failure.
|
|
21
|
+
*/
|
|
22
|
+
static std::string normalizeHtml(const std::string &html);
|
|
23
|
+
};
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
#include "GumboParser.hpp"
|
|
2
|
+
#include <gtest/gtest.h>
|
|
3
|
+
|
|
4
|
+
TEST(GumboParserTest, TagRemappings) {
|
|
5
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<strong>x</strong>"), "<b>x</b>");
|
|
6
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<em>x</em>"), "<i>x</i>");
|
|
7
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<del>x</del>"), "<s>x</s>");
|
|
8
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<strike>x</strike>"), "<s>x</s>");
|
|
9
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<ins>x</ins>"), "<u>x</u>");
|
|
10
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<pre>x</pre>"),
|
|
11
|
+
"<codeblock><p>x</p></codeblock>");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
TEST(GumboParserTest, GoogleDocsWrapper) {
|
|
15
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
16
|
+
"<b id=\"docs-internal-guid-1234567890\">x</b>"),
|
|
17
|
+
"x");
|
|
18
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
19
|
+
"<b id=\"docs-internal-guid-1234567890\"></b>"),
|
|
20
|
+
"");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
TEST(GumboParserTest, TagOmissions) {
|
|
24
|
+
EXPECT_EQ(
|
|
25
|
+
GumboParser::normalizeHtml("<meta name='author' content='John Doe'>"),
|
|
26
|
+
"");
|
|
27
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<style></style>"), "");
|
|
28
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<script></script>"), "");
|
|
29
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<title></title>"), "");
|
|
30
|
+
EXPECT_EQ(
|
|
31
|
+
GumboParser::normalizeHtml("<link rel='stylesheet' href='styles.css'>"),
|
|
32
|
+
"");
|
|
33
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<html></html>"), "");
|
|
34
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<body></body>"), "");
|
|
35
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<head></head>"), "");
|
|
36
|
+
|
|
37
|
+
// Nested tags
|
|
38
|
+
EXPECT_EQ(
|
|
39
|
+
GumboParser::normalizeHtml("<html><head></head><body></body></html>"),
|
|
40
|
+
"");
|
|
41
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<html><body><p>x</p></body></html>"),
|
|
42
|
+
"<p>x</p>");
|
|
43
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<html><p>x</p></html>"), "<p>x</p>");
|
|
44
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<body><p>x</p></body>"), "<p>x</p>");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
TEST(GumboParserTest, TableOmissions) {
|
|
48
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<table></table>"), "");
|
|
49
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<thead></thead>"), "");
|
|
50
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<tbody></tbody>"), "");
|
|
51
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<tfoot></tfoot>"), "");
|
|
52
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<tr></tr>"), "");
|
|
53
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<td></td>"), "");
|
|
54
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<th></th>"), "");
|
|
55
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<caption></caption>"), "");
|
|
56
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<colgroup></colgroup>"), "");
|
|
57
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<col></col>"), "");
|
|
58
|
+
|
|
59
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
60
|
+
"<table "
|
|
61
|
+
"style=\"width:100%\"><tr><td>Emil</td><td>Tobias</"
|
|
62
|
+
"td><td>Linus</td></tr></table>"),
|
|
63
|
+
"<p>Emil Tobias Linus</p>");
|
|
64
|
+
|
|
65
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
66
|
+
"<table><tr><td>Emil</td><td>Tobias</td><td>Linus</td></tr>"
|
|
67
|
+
"<tr><td>16</td><td>14</td><td>10</td></tr></table>"),
|
|
68
|
+
"<p>Emil Tobias Linus</p><p>16 14 10</p>");
|
|
69
|
+
|
|
70
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
71
|
+
"<table><tr><th>Person 1</th><th>Person 2</th><th>Person "
|
|
72
|
+
"3</th></tr><tr><td>Emil</td><td>Tobias</td><td>Linus</td></"
|
|
73
|
+
"tr><tr><td>16</td><td>14</td><td>10</td></tr></table>"),
|
|
74
|
+
"<p>Person 1 Person 2 Person 3</p><p>Emil Tobias Linus</p><p>16 14 "
|
|
75
|
+
"10</p>");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
TEST(GumboParserTest, SpanRemappings) {
|
|
79
|
+
// Bold
|
|
80
|
+
EXPECT_EQ(
|
|
81
|
+
GumboParser::normalizeHtml("<span style=\"font-weight: bold;\">x</span>"),
|
|
82
|
+
"<b>x</b>");
|
|
83
|
+
EXPECT_EQ(
|
|
84
|
+
GumboParser::normalizeHtml("<span style=\"font-weight: bold\">x</span>"),
|
|
85
|
+
"<b>x</b>");
|
|
86
|
+
EXPECT_EQ(
|
|
87
|
+
GumboParser::normalizeHtml("<span style='font-weight: bold'>x</span>"),
|
|
88
|
+
"<b>x</b>");
|
|
89
|
+
|
|
90
|
+
// Italic
|
|
91
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
92
|
+
"<span style=\"font-style: italic;\">x</span>"),
|
|
93
|
+
"<i>x</i>");
|
|
94
|
+
EXPECT_EQ(
|
|
95
|
+
GumboParser::normalizeHtml("<span style=\"font-style: italic\">x</span>"),
|
|
96
|
+
"<i>x</i>");
|
|
97
|
+
EXPECT_EQ(
|
|
98
|
+
GumboParser::normalizeHtml("<span style='font-style: italic'>x</span>"),
|
|
99
|
+
"<i>x</i>");
|
|
100
|
+
|
|
101
|
+
// Underline
|
|
102
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
103
|
+
"<span style=\"text-decoration: underline;\">x</span>"),
|
|
104
|
+
"<u>x</u>");
|
|
105
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
106
|
+
"<span style=\"text-decoration: underline\">x</span>"),
|
|
107
|
+
"<u>x</u>");
|
|
108
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
109
|
+
"<span style='text-decoration: underline'>x</span>"),
|
|
110
|
+
"<u>x</u>");
|
|
111
|
+
|
|
112
|
+
// Strikethrough
|
|
113
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
114
|
+
"<span style=\"text-decoration: line-through;\">x</span>"),
|
|
115
|
+
"<s>x</s>");
|
|
116
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
117
|
+
"<span style=\"text-decoration: line-through\">x</span>"),
|
|
118
|
+
"<s>x</s>");
|
|
119
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
120
|
+
"<span style='text-decoration: line-through'>x</span>"),
|
|
121
|
+
"<s>x</s>");
|
|
122
|
+
|
|
123
|
+
// Bold and Italic
|
|
124
|
+
EXPECT_EQ(
|
|
125
|
+
GumboParser::normalizeHtml(
|
|
126
|
+
"<span style=\"font-weight: bold; font-style: italic;\">x</span>"),
|
|
127
|
+
"<b><i>x</i></b>");
|
|
128
|
+
EXPECT_EQ(
|
|
129
|
+
GumboParser::normalizeHtml(
|
|
130
|
+
"<span style=\"font-weight: bold; font-style: italic\">x</span>"),
|
|
131
|
+
"<b><i>x</i></b>");
|
|
132
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
133
|
+
"<span style='font-weight: bold; font-style: italic'>x</span>"),
|
|
134
|
+
"<b><i>x</i></b>");
|
|
135
|
+
|
|
136
|
+
// Italic and Bold
|
|
137
|
+
EXPECT_EQ(
|
|
138
|
+
GumboParser::normalizeHtml(
|
|
139
|
+
"<span style=\"font-style: italic; font-weight: bold;\">x</span>"),
|
|
140
|
+
"<b><i>x</i></b>");
|
|
141
|
+
EXPECT_EQ(
|
|
142
|
+
GumboParser::normalizeHtml(
|
|
143
|
+
"<span style=\"font-style: italic; font-weight: bold\">x</span>"),
|
|
144
|
+
"<b><i>x</i></b>");
|
|
145
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
146
|
+
"<span style='font-style: italic; font-weight: bold'>x</span>"),
|
|
147
|
+
"<b><i>x</i></b>");
|
|
148
|
+
|
|
149
|
+
// Bold and Underline
|
|
150
|
+
EXPECT_EQ(
|
|
151
|
+
GumboParser::normalizeHtml("<span style=\"font-weight: bold; "
|
|
152
|
+
"text-decoration: underline;\">x</span>"),
|
|
153
|
+
"<b><u>x</u></b>");
|
|
154
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<span style=\"font-weight: bold; "
|
|
155
|
+
"text-decoration: underline\">x</span>"),
|
|
156
|
+
"<b><u>x</u></b>");
|
|
157
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<span style='font-weight: bold; "
|
|
158
|
+
"text-decoration: underline'>x</span>"),
|
|
159
|
+
"<b><u>x</u></b>");
|
|
160
|
+
|
|
161
|
+
// Underline and Bold
|
|
162
|
+
EXPECT_EQ(
|
|
163
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: underline; "
|
|
164
|
+
"font-weight: bold;\">x</span>"),
|
|
165
|
+
"<b><u>x</u></b>");
|
|
166
|
+
EXPECT_EQ(
|
|
167
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: underline; "
|
|
168
|
+
"font-weight: bold\">x</span>"),
|
|
169
|
+
"<b><u>x</u></b>");
|
|
170
|
+
EXPECT_EQ(
|
|
171
|
+
GumboParser::normalizeHtml("<span style='text-decoration: underline; "
|
|
172
|
+
"font-weight: bold'>x</span>"),
|
|
173
|
+
"<b><u>x</u></b>");
|
|
174
|
+
|
|
175
|
+
// Bold and Strikethrough
|
|
176
|
+
EXPECT_EQ(
|
|
177
|
+
GumboParser::normalizeHtml("<span style=\"font-weight: bold; "
|
|
178
|
+
"text-decoration: line-through;\">x</span>"),
|
|
179
|
+
"<b><s>x</s></b>");
|
|
180
|
+
EXPECT_EQ(
|
|
181
|
+
GumboParser::normalizeHtml("<span style=\"font-weight: bold; "
|
|
182
|
+
"text-decoration: line-through\">x</span>"),
|
|
183
|
+
"<b><s>x</s></b>");
|
|
184
|
+
EXPECT_EQ(
|
|
185
|
+
GumboParser::normalizeHtml("<span style='font-weight: bold; "
|
|
186
|
+
"text-decoration: line-through'>x</span>"),
|
|
187
|
+
"<b><s>x</s></b>");
|
|
188
|
+
|
|
189
|
+
// Strikethrough and Bold
|
|
190
|
+
EXPECT_EQ(
|
|
191
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: line-through; "
|
|
192
|
+
"font-weight: bold;\">x</span>"),
|
|
193
|
+
"<b><s>x</s></b>");
|
|
194
|
+
EXPECT_EQ(
|
|
195
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: line-through; "
|
|
196
|
+
"font-weight: bold\">x</span>"),
|
|
197
|
+
"<b><s>x</s></b>");
|
|
198
|
+
EXPECT_EQ(
|
|
199
|
+
GumboParser::normalizeHtml("<span style='text-decoration: line-through; "
|
|
200
|
+
"font-weight: bold'>x</span>"),
|
|
201
|
+
"<b><s>x</s></b>");
|
|
202
|
+
|
|
203
|
+
// Underline and Strikethrough
|
|
204
|
+
EXPECT_EQ(
|
|
205
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: underline; "
|
|
206
|
+
"text-decoration: line-through;\">x</span>"),
|
|
207
|
+
"<u><s>x</s></u>");
|
|
208
|
+
EXPECT_EQ(
|
|
209
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: underline; "
|
|
210
|
+
"text-decoration: line-through\">x</span>"),
|
|
211
|
+
"<u><s>x</s></u>");
|
|
212
|
+
EXPECT_EQ(
|
|
213
|
+
GumboParser::normalizeHtml("<span style='text-decoration: underline; "
|
|
214
|
+
"text-decoration: line-through'>x</span>"),
|
|
215
|
+
"<u><s>x</s></u>");
|
|
216
|
+
|
|
217
|
+
// Strikethrough and Underline
|
|
218
|
+
EXPECT_EQ(
|
|
219
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: line-through; "
|
|
220
|
+
"text-decoration: underline;\">x</span>"),
|
|
221
|
+
"<u><s>x</s></u>");
|
|
222
|
+
EXPECT_EQ(
|
|
223
|
+
GumboParser::normalizeHtml("<span style=\"text-decoration: line-through; "
|
|
224
|
+
"text-decoration: underline\">x</span>"),
|
|
225
|
+
"<u><s>x</s></u>");
|
|
226
|
+
EXPECT_EQ(
|
|
227
|
+
GumboParser::normalizeHtml("<span style='text-decoration: line-through; "
|
|
228
|
+
"text-decoration: underline'>x</span>"),
|
|
229
|
+
"<u><s>x</s></u>");
|
|
230
|
+
|
|
231
|
+
// Combined
|
|
232
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
233
|
+
"<span style=\"font-weight: bold; font-style: italic; "
|
|
234
|
+
"text-decoration: underline;\">x</span>"),
|
|
235
|
+
"<b><i><u>x</u></i></b>");
|
|
236
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
237
|
+
"<span style=\"font-weight: bold; font-style: italic; "
|
|
238
|
+
"text-decoration: underline\">x</span>"),
|
|
239
|
+
"<b><i><u>x</u></i></b>");
|
|
240
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
241
|
+
"<span style='font-weight: bold; font-style: italic; "
|
|
242
|
+
"text-decoration: underline'>x</span>"),
|
|
243
|
+
"<b><i><u>x</u></i></b>");
|
|
244
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
245
|
+
"<span style='font-weight: bold; text-decoration: underline; "
|
|
246
|
+
"font-style: italic;'>x</span>"),
|
|
247
|
+
"<b><i><u>x</u></i></b>");
|
|
248
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
249
|
+
"<span style='text-decoration: underline; font-weight: bold; "
|
|
250
|
+
"font-style: italic;'>x</span>"),
|
|
251
|
+
"<b><i><u>x</u></i></b>");
|
|
252
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
253
|
+
"<span style='text-decoration: line-through; font-weight: "
|
|
254
|
+
"bold; font-style: italic;'>x</span>"),
|
|
255
|
+
"<b><i><s>x</s></i></b>");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
TEST(GumboParserTest, EnrichedTagRemappings) {
|
|
259
|
+
// Block elements
|
|
260
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<codeblock>x</codeblock>"),
|
|
261
|
+
"<codeblock><p>x</p></codeblock>");
|
|
262
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<codeblock><p>x</p></codeblock>"),
|
|
263
|
+
"<codeblock><p>x</p></codeblock>");
|
|
264
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<blockquote>x</blockquote>"),
|
|
265
|
+
"<blockquote><p>x</p></blockquote>");
|
|
266
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<blockquote><p>x</p></blockquote>"),
|
|
267
|
+
"<blockquote><p>x</p></blockquote>");
|
|
268
|
+
|
|
269
|
+
// Headings
|
|
270
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h1>x</h1>"), "<h1>x</h1>");
|
|
271
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h2>x</h2>"), "<h2>x</h2>");
|
|
272
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h3>x</h3>"), "<h3>x</h3>");
|
|
273
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h4>x</h4>"), "<h4>x</h4>");
|
|
274
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h5>x</h5>"), "<h5>x</h5>");
|
|
275
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<h6>x</h6>"), "<h6>x</h6>");
|
|
276
|
+
|
|
277
|
+
// Self-closing tags
|
|
278
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<br>"), "<br>");
|
|
279
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
280
|
+
"<img src=\"x\" width=\"100\" height=\"100\" />"),
|
|
281
|
+
"<img src=\"x\" width=\"100\" height=\"100\" />");
|
|
282
|
+
EXPECT_EQ(
|
|
283
|
+
GumboParser::normalizeHtml("<img src='x' width='100' height='100' />"),
|
|
284
|
+
"<img src=\"x\" width=\"100\" height=\"100\" />");
|
|
285
|
+
|
|
286
|
+
// Lists
|
|
287
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<ul><li>x</li></ul>"),
|
|
288
|
+
"<ul><li>x</li></ul>");
|
|
289
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<ol><li>x</li></ol>"),
|
|
290
|
+
"<ol><li>x</li></ol>");
|
|
291
|
+
|
|
292
|
+
// Checkbox lists
|
|
293
|
+
EXPECT_EQ(
|
|
294
|
+
GumboParser::normalizeHtml("<ul data-type='checkbox'><li>x</li></ul>"),
|
|
295
|
+
"<ul data-type=\"checkbox\"><li>x</li></ul>");
|
|
296
|
+
EXPECT_EQ(
|
|
297
|
+
GumboParser::normalizeHtml("<ul data-type=\"checkbox\"><li>x</li></ul>"),
|
|
298
|
+
"<ul data-type=\"checkbox\"><li>x</li></ul>");
|
|
299
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
300
|
+
"<ul data-type='checkbox'><li checked>x</li></ul>"),
|
|
301
|
+
"<ul data-type=\"checkbox\"><li checked>x</li></ul>");
|
|
302
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
303
|
+
"<ul data-type=\"checkbox\"><li checked>x</li></ul>"),
|
|
304
|
+
"<ul data-type=\"checkbox\"><li checked>x</li></ul>");
|
|
305
|
+
|
|
306
|
+
// Mentions
|
|
307
|
+
EXPECT_EQ(
|
|
308
|
+
GumboParser::normalizeHtml(
|
|
309
|
+
"<mention text='@John Doe' indicator='@' id='1'>@John Doe</mention>"),
|
|
310
|
+
"<mention id=\"1\" text=\"@John Doe\" indicator=\"@\">@John "
|
|
311
|
+
"Doe</mention>");
|
|
312
|
+
EXPECT_EQ(
|
|
313
|
+
GumboParser::normalizeHtml("<mention text=\"@John Doe\" indicator=\"@\" "
|
|
314
|
+
"id=\"1\">@John Doe</mention>"),
|
|
315
|
+
"<mention id=\"1\" text=\"@John Doe\" indicator=\"@\">@John "
|
|
316
|
+
"Doe</mention>");
|
|
317
|
+
|
|
318
|
+
// Link
|
|
319
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
320
|
+
"<a href=\"https://www.google.com\">Google</a>"),
|
|
321
|
+
"<a href=\"https://www.google.com\">Google</a>");
|
|
322
|
+
EXPECT_EQ(
|
|
323
|
+
GumboParser::normalizeHtml("<a href='https://www.google.com'>Google</a>"),
|
|
324
|
+
"<a href=\"https://www.google.com\">Google</a>");
|
|
325
|
+
|
|
326
|
+
// Inline
|
|
327
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<code>x</code>"), "<code>x</code>");
|
|
328
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<s>x</s>"), "<s>x</s>");
|
|
329
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<u>x</u>"), "<u>x</u>");
|
|
330
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<i>x</i>"), "<i>x</i>");
|
|
331
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<b>x</b>"), "<b>x</b>");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
TEST(GumboParserTest, DivRemappings) {
|
|
335
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<div>x</div>"), "<p>x</p>");
|
|
336
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<div><p>x</p></div>"), "<p>x</p>");
|
|
337
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<div><p>x</p><p>y</p></div>"),
|
|
338
|
+
"<p>x</p><p>y</p>");
|
|
339
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<div><p>x</p><p>y</p></div>"),
|
|
340
|
+
"<p>x</p><p>y</p>");
|
|
341
|
+
EXPECT_EQ(GumboParser::normalizeHtml("<div><span>x</span></div>"),
|
|
342
|
+
"<p>x</p>");
|
|
343
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
344
|
+
"<div><div><span>x</span></div><span>y</span></div>"),
|
|
345
|
+
"<p>x</p><p>y</p>");
|
|
346
|
+
|
|
347
|
+
// Without whitespace
|
|
348
|
+
EXPECT_EQ(
|
|
349
|
+
GumboParser::normalizeHtml(
|
|
350
|
+
"<span>--</span><br><div><div><span>John<span> "
|
|
351
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
352
|
+
"</span>Engineer</div></div></div>"),
|
|
353
|
+
"<p>--</p><p>John <b>Doe</b></p><p><u><i>Software</i></u> Engineer</p>");
|
|
354
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
355
|
+
"<div><div><span>John<span> "
|
|
356
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
357
|
+
"</span>Engineer</div></div></div>"),
|
|
358
|
+
"<p>John <b>Doe</b></p><p><u><i>Software</i></u> Engineer</p>");
|
|
359
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
360
|
+
"<span style='font-weight: "
|
|
361
|
+
"700'>--</span><br><div><div><span>John<span> "
|
|
362
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
363
|
+
"</span>Engineer</div></div></div>"),
|
|
364
|
+
"<p><b>--</b></p><p>John <b>Doe</b></p><p><u><i>Software</i></u> "
|
|
365
|
+
"Engineer</p>");
|
|
366
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
367
|
+
"<span style='font-style: "
|
|
368
|
+
"italic'>--</span><br><div><div><span>John<span> "
|
|
369
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
370
|
+
"</span>Engineer</div></div></div>"),
|
|
371
|
+
"<p><i>--</i></p><p>John <b>Doe</b></p><p><u><i>Software</i></u> "
|
|
372
|
+
"Engineer</p>");
|
|
373
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
374
|
+
"<span style='font-style: italic; font-weight: "
|
|
375
|
+
"bold'>--</span><br><div><div><span>John<span> "
|
|
376
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
377
|
+
"</span>Engineer</div></div></div>"),
|
|
378
|
+
"<p><b><i>--</i></b></p><p>John "
|
|
379
|
+
"<b>Doe</b></p><p><u><i>Software</i></u> Engineer</p>");
|
|
380
|
+
EXPECT_EQ(
|
|
381
|
+
GumboParser::normalizeHtml(
|
|
382
|
+
"<span style='font-style: italic; font-weight: bold; "
|
|
383
|
+
"text-decoration: underline'>--</span><br><div><div><span>John<span> "
|
|
384
|
+
"</span></span><b>Doe</b><div><u><i>Software</i></u><span> "
|
|
385
|
+
"</span>Engineer</div></div></div>"),
|
|
386
|
+
"<p><b><i><u>--</u></i></b></p><p>John "
|
|
387
|
+
"<b>Doe</b></p><p><u><i>Software</i></u> Engineer</p>");
|
|
388
|
+
|
|
389
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
390
|
+
"<div><br>here's more!</div><div><br></div><img "
|
|
391
|
+
"src=\"https://example.com/image.png\" alt=\"image.png\" "
|
|
392
|
+
"width=\"336\" height=\"297\">"),
|
|
393
|
+
"<br><p>here's more!</p><br><p><img "
|
|
394
|
+
"src=\"https://example.com/image.png\" alt=\"image.png\" "
|
|
395
|
+
"width=\"336\" height=\"297\" /></p>");
|
|
396
|
+
|
|
397
|
+
EXPECT_EQ(
|
|
398
|
+
GumboParser::normalizeHtml(
|
|
399
|
+
"<div>what do you think of this "
|
|
400
|
+
"craziness</div><span><blockquote><div><div><ul><li><b>another one "
|
|
401
|
+
"</b>hello<div><br></div><div>hi</div></li></ul></div></div></"
|
|
402
|
+
"blockquote></span>"),
|
|
403
|
+
"<p>what do you think of this craziness</p><blockquote><p><b>another one "
|
|
404
|
+
"</b>hello</p><p>hi</p></blockquote>");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
TEST(GumboParserTest, ListFlattening) {
|
|
408
|
+
EXPECT_EQ(
|
|
409
|
+
GumboParser::normalizeHtml("<ul><ol><li>x</li><li>y</li></ol></ul>"),
|
|
410
|
+
"<ul><li>x</li><li>y</li></ul>");
|
|
411
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
412
|
+
"<ul><li>x</li><ol><li>y</li><li>z</li></ol></ul>"),
|
|
413
|
+
"<ul><li>x</li><li>y</li><li>z</li></ul>");
|
|
414
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
415
|
+
"<ul><ol><li>x</li><li>y</li></ol><li>z</li></ul>"),
|
|
416
|
+
"<ul><li>x</li><li>y</li><li>z</li></ul>");
|
|
417
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
418
|
+
"<ol><li>x</li><ul><li>y</li><li>z</li></ul></ol>"),
|
|
419
|
+
"<ol><li>x</li><li>y</li><li>z</li></ol>");
|
|
420
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
421
|
+
"<ol><ul><li>x</li><li>y</li></ul><li>z</li></ol>"),
|
|
422
|
+
"<ol><li>x</li><li>y</li><li>z</li></ol>");
|
|
423
|
+
EXPECT_EQ(
|
|
424
|
+
GumboParser::normalizeHtml(
|
|
425
|
+
"<ol><ul "
|
|
426
|
+
"data-type='checkbox'><li>x</li><li>y</li></ul><li>z</li></ol>"),
|
|
427
|
+
"<ol><li>x</li><li>y</li><li>z</li></ol>");
|
|
428
|
+
EXPECT_EQ(
|
|
429
|
+
GumboParser::normalizeHtml(
|
|
430
|
+
"<ul "
|
|
431
|
+
"data-type='checkbox'><ol><li>x</li><li>y</li></ol><li>z</li></ul>"),
|
|
432
|
+
"<ul data-type=\"checkbox\"><li>x</li><li>y</li><li>z</li></ul>");
|
|
433
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
434
|
+
"<ul><li>x</li><ol><li>y</li><ul><li>z</li></ul></ol></ul>"),
|
|
435
|
+
"<ul><li>x</li><li>y</li><li>z</li></ul>");
|
|
436
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
437
|
+
"<ul><li>x</li><ol><li>y</li><ul "
|
|
438
|
+
"data-type='checkbox'><li>z</li></ul></ol></ul>"),
|
|
439
|
+
"<ul><li>x</li><li>y</li><li>z</li></ul>");
|
|
440
|
+
EXPECT_EQ(
|
|
441
|
+
GumboParser::normalizeHtml("<ul "
|
|
442
|
+
"data-type='checkbox'><li>x</li><ol><li>y</"
|
|
443
|
+
"li><ul><li>z</li></ul></ol></ul>"),
|
|
444
|
+
"<ul data-type=\"checkbox\"><li>x</li><li>y</li><li>z</li></ul>");
|
|
445
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
446
|
+
"<ul><li><b>another one </b>hi "
|
|
447
|
+
"kacper,<div><br></div><div>hi</div></li></ul>"),
|
|
448
|
+
"<ul><li><b>another one </b>hi kacper,</li><li>hi</li></ul>");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
TEST(GumboParserTest, BrRemappings) {
|
|
452
|
+
EXPECT_EQ(GumboParser::normalizeHtml(
|
|
453
|
+
"<p><b>Asdasdasd</b></p><br><br><p>Sent with<span> </span><a "
|
|
454
|
+
"href='https://google.com'>Net</a></p>"),
|
|
455
|
+
"<p><b>Asdasdasd</b></p><br><br><p>Sent with <a "
|
|
456
|
+
"href=\"https://google.com\">Net</a></p>");
|
|
457
|
+
}
|
|
@@ -30,6 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
30
30
|
NSMutableDictionary<NSNumber *, NSArray<NSNumber *> *> *blockingStyles;
|
|
31
31
|
@public
|
|
32
32
|
BOOL blockEmitting;
|
|
33
|
+
@public
|
|
34
|
+
BOOL useHtmlNormalizer;
|
|
33
35
|
}
|
|
34
36
|
- (CGSize)measureSize:(CGFloat)maxWidth;
|
|
35
37
|
- (void)emitOnLinkDetectedEvent:(NSString *)text
|