Skip to content

Commit 92bdca2

Browse files
committed
Add support for parsing font-weight == 700 in addition to font-weight == "bold".
This fixes the pasting bold content from google docs(and possibly other sources).
1 parent 3b8b034 commit 92bdca2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

crates/wysiwyg/src/composer_model/replace_html.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod test {
100100
let html_str = html.to_string();
101101
assert!(!html_str.contains("<meta"));
102102
assert!(!html_str.contains("docs-internal-guid"));
103-
assert_eq!(html_str, "<ol><li><p><i>Italic</i></p></li><li><p>Bold</p></li><li><p>Unformatted</p></li><li><p><del>Strikethrough</del></p></li><li><p><u>Underlined</u></p></li><li><p><a style=\"text-decoration:none;\" href=\"http://matrix.org\"><u>Linked</u></a></p><ul><li><p>Nested</p></li></ul></li></ol>");
103+
assert_eq!(html_str, "<ol><li><p><i>Italic</i></p></li><li><p><b>Bold</b></p></li><li><p>Unformatted</p></li><li><p><del>Strikethrough</del></p></li><li><p><u>Underlined</u></p></li><li><p><a style=\"text-decoration:none;\" href=\"http://matrix.org\"><u>Linked</u></a></p><ul><li><p>Nested</p></li></ul></li></ol>");
104104
}
105105

106106
#[test]

crates/wysiwyg/src/dom/parser/parse.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ mod sys {
262262
// For external sources, we check for common formatting styles for spans
263263
// and convert them to appropriate formatting nodes.
264264
let mut formatting_tag = None;
265-
if child.contains_style("font-weight", "bold") {
265+
if child.contains_style("font-weight", "bold")
266+
|| child.contains_style("font-weight", "700")
267+
{
266268
formatting_tag = Some("b");
267269
} else if child.contains_style("font-style", "italic") {
268270
formatting_tag = Some("i");
@@ -1174,6 +1176,7 @@ mod sys {
11741176
)
11751177
.unwrap();
11761178
let tree = dom.to_tree().to_string();
1179+
println!("{}", tree);
11771180
assert_eq!(
11781181
tree,
11791182
indoc! {
@@ -1186,7 +1189,8 @@ mod sys {
11861189
│ └>"Italic"
11871190
├>li
11881191
│ └>p
1189-
│ └>"Bold"
1192+
│ └>b
1193+
│ └>"Bold"
11901194
├>li
11911195
│ └>p
11921196
│ └>"Unformatted"
@@ -1214,7 +1218,7 @@ mod sys {
12141218
dom.to_markdown().unwrap().to_string(),
12151219
indoc! {r#"
12161220
1. *Italic*
1217-
2. Bold
1221+
2. __Bold__
12181222
3. Unformatted
12191223
4. ~~Strikethrough~~
12201224
5. <u>Underlined</u>
@@ -1915,6 +1919,12 @@ mod js {
19151919
.get_property_value("font-weight")
19161920
.unwrap_or_default()
19171921
== "bold"
1922+
|| style
1923+
.get_property_value(
1924+
"font-weight",
1925+
)
1926+
.unwrap_or_default()
1927+
== "700"
19181928
{
19191929
Some(InlineFormatType::Bold)
19201930
} else if style
@@ -2123,12 +2133,12 @@ mod js {
21232133
HtmlSource::GoogleDoc,
21242134
)
21252135
.unwrap();
2126-
assert_eq!(dom.to_string(), "<ol><li><p><em>Italic</em></p></li><li><p>Bold</p></li><li><p>Unformatted</p></li><li><p><del>Strikethrough</del></p></li><li><p><u>Underlined</u></p></li><li><p><a style=\"text-decoration:none;\" href=\"http://matrix.org\"><u>Linked</u></a></p><ul><li><p>Nested</p></li></ul></li></ol>");
2136+
assert_eq!(dom.to_string(), "<ol><li><p><em>Italic</em></p></li><li><p><strong>Bold</strong></p></li><li><p>Unformatted</p></li><li><p><del>Strikethrough</del></p></li><li><p><u>Underlined</u></p></li><li><p><a style=\"text-decoration:none;\" href=\"http://matrix.org\"><u>Linked</u></a></p><ul><li><p>Nested</p></li></ul></li></ol>");
21272137
assert_eq!(
21282138
dom.to_markdown().unwrap().to_string(),
21292139
indoc! {r#"
21302140
1. *Italic*
2131-
2. Bold
2141+
2. __Bold__
21322142
3. Unformatted
21332143
4. ~~Strikethrough~~
21342144
5. <u>Underlined</u>

0 commit comments

Comments
 (0)