Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 7cfb055

Browse files
Kevin Lifacebook-github-bot
authored andcommitted
fix(styles): avoid permanently accumulating attribute styles
Summary: Attribute styles defined on a node were permanently added to the persistent set of styles. This meant that any bold/italic/underline/strikethrough styles would persist until the end of the document, or until a different value was set for it. This wasn't an issue in `convertFromHTMLToContentBlocks` because it would clone the current styles before passing them off to its children. Since this was refactored away in `convertFromHTMLToContentBlocks2` (probably for perf reasons), I safely mutated `currentStyle` around its children, in the same way as `inlineStyle`. Reviewed By: claudiopro Differential Revision: D15737186 fbshipit-source-id: 494f75da48f9a23a5ece450ab66002f4a3f9c43a
1 parent 96c7221 commit 7cfb055

File tree

3 files changed

+432
-52
lines changed

3 files changed

+432
-52
lines changed

src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks2-test.js.snap

Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,363 @@ Array [
19621962
]
19631963
`;
19641964

1965+
exports[`Should scope attribute styles 1`] = `
1966+
Array [
1967+
Object {
1968+
"characterList": Array [
1969+
Object {
1970+
"entity": null,
1971+
"style": Array [
1972+
"BOLD",
1973+
],
1974+
},
1975+
Object {
1976+
"entity": null,
1977+
"style": Array [
1978+
"BOLD",
1979+
],
1980+
},
1981+
Object {
1982+
"entity": null,
1983+
"style": Array [
1984+
"BOLD",
1985+
],
1986+
},
1987+
Object {
1988+
"entity": null,
1989+
"style": Array [
1990+
"BOLD",
1991+
],
1992+
},
1993+
Object {
1994+
"entity": null,
1995+
"style": Array [
1996+
"BOLD",
1997+
],
1998+
},
1999+
Object {
2000+
"entity": null,
2001+
"style": Array [],
2002+
},
2003+
Object {
2004+
"entity": null,
2005+
"style": Array [
2006+
"ITALIC",
2007+
],
2008+
},
2009+
Object {
2010+
"entity": null,
2011+
"style": Array [
2012+
"ITALIC",
2013+
],
2014+
},
2015+
Object {
2016+
"entity": null,
2017+
"style": Array [
2018+
"ITALIC",
2019+
],
2020+
},
2021+
Object {
2022+
"entity": null,
2023+
"style": Array [
2024+
"ITALIC",
2025+
],
2026+
},
2027+
Object {
2028+
"entity": null,
2029+
"style": Array [
2030+
"ITALIC",
2031+
],
2032+
},
2033+
Object {
2034+
"entity": null,
2035+
"style": Array [],
2036+
},
2037+
Object {
2038+
"entity": null,
2039+
"style": Array [
2040+
"UNDERLINE",
2041+
],
2042+
},
2043+
Object {
2044+
"entity": null,
2045+
"style": Array [
2046+
"UNDERLINE",
2047+
],
2048+
},
2049+
Object {
2050+
"entity": null,
2051+
"style": Array [
2052+
"UNDERLINE",
2053+
],
2054+
},
2055+
Object {
2056+
"entity": null,
2057+
"style": Array [
2058+
"UNDERLINE",
2059+
],
2060+
},
2061+
Object {
2062+
"entity": null,
2063+
"style": Array [
2064+
"UNDERLINE",
2065+
],
2066+
},
2067+
Object {
2068+
"entity": null,
2069+
"style": Array [
2070+
"UNDERLINE",
2071+
],
2072+
},
2073+
Object {
2074+
"entity": null,
2075+
"style": Array [
2076+
"UNDERLINE",
2077+
],
2078+
},
2079+
Object {
2080+
"entity": null,
2081+
"style": Array [
2082+
"UNDERLINE",
2083+
],
2084+
},
2085+
Object {
2086+
"entity": null,
2087+
"style": Array [
2088+
"UNDERLINE",
2089+
],
2090+
},
2091+
Object {
2092+
"entity": null,
2093+
"style": Array [
2094+
"UNDERLINE",
2095+
],
2096+
},
2097+
Object {
2098+
"entity": null,
2099+
"style": Array [
2100+
"UNDERLINE",
2101+
],
2102+
},
2103+
Object {
2104+
"entity": null,
2105+
"style": Array [
2106+
"UNDERLINE",
2107+
],
2108+
},
2109+
Object {
2110+
"entity": null,
2111+
"style": Array [
2112+
"UNDERLINE",
2113+
],
2114+
},
2115+
Object {
2116+
"entity": null,
2117+
"style": Array [
2118+
"UNDERLINE",
2119+
],
2120+
},
2121+
Object {
2122+
"entity": null,
2123+
"style": Array [
2124+
"UNDERLINE",
2125+
],
2126+
},
2127+
Object {
2128+
"entity": null,
2129+
"style": Array [
2130+
"UNDERLINE",
2131+
],
2132+
},
2133+
Object {
2134+
"entity": null,
2135+
"style": Array [
2136+
"UNDERLINE",
2137+
],
2138+
},
2139+
Object {
2140+
"entity": null,
2141+
"style": Array [],
2142+
},
2143+
Object {
2144+
"entity": null,
2145+
"style": Array [
2146+
"BOLD",
2147+
],
2148+
},
2149+
Object {
2150+
"entity": null,
2151+
"style": Array [
2152+
"BOLD",
2153+
"ITALIC",
2154+
],
2155+
},
2156+
Object {
2157+
"entity": null,
2158+
"style": Array [
2159+
"BOLD",
2160+
"ITALIC",
2161+
"UNDERLINE",
2162+
],
2163+
},
2164+
Object {
2165+
"entity": null,
2166+
"style": Array [
2167+
"BOLD",
2168+
"ITALIC",
2169+
"UNDERLINE",
2170+
],
2171+
},
2172+
Object {
2173+
"entity": null,
2174+
"style": Array [
2175+
"BOLD",
2176+
"ITALIC",
2177+
"UNDERLINE",
2178+
],
2179+
},
2180+
Object {
2181+
"entity": null,
2182+
"style": Array [
2183+
"BOLD",
2184+
"ITALIC",
2185+
"UNDERLINE",
2186+
],
2187+
},
2188+
Object {
2189+
"entity": null,
2190+
"style": Array [
2191+
"BOLD",
2192+
"ITALIC",
2193+
"UNDERLINE",
2194+
],
2195+
},
2196+
Object {
2197+
"entity": null,
2198+
"style": Array [
2199+
"BOLD",
2200+
"ITALIC",
2201+
"UNDERLINE",
2202+
],
2203+
},
2204+
Object {
2205+
"entity": null,
2206+
"style": Array [
2207+
"BOLD",
2208+
"ITALIC",
2209+
"UNDERLINE",
2210+
],
2211+
},
2212+
Object {
2213+
"entity": null,
2214+
"style": Array [
2215+
"BOLD",
2216+
"ITALIC",
2217+
"UNDERLINE",
2218+
],
2219+
},
2220+
Object {
2221+
"entity": null,
2222+
"style": Array [
2223+
"BOLD",
2224+
"ITALIC",
2225+
"UNDERLINE",
2226+
],
2227+
},
2228+
Object {
2229+
"entity": null,
2230+
"style": Array [
2231+
"BOLD",
2232+
"ITALIC",
2233+
"UNDERLINE",
2234+
],
2235+
},
2236+
Object {
2237+
"entity": null,
2238+
"style": Array [
2239+
"BOLD",
2240+
"ITALIC",
2241+
"UNDERLINE",
2242+
],
2243+
},
2244+
Object {
2245+
"entity": null,
2246+
"style": Array [
2247+
"BOLD",
2248+
"ITALIC",
2249+
"UNDERLINE",
2250+
],
2251+
},
2252+
Object {
2253+
"entity": null,
2254+
"style": Array [
2255+
"BOLD",
2256+
"ITALIC",
2257+
"UNDERLINE",
2258+
],
2259+
},
2260+
Object {
2261+
"entity": null,
2262+
"style": Array [
2263+
"BOLD",
2264+
"ITALIC",
2265+
"UNDERLINE",
2266+
],
2267+
},
2268+
Object {
2269+
"entity": null,
2270+
"style": Array [
2271+
"BOLD",
2272+
"ITALIC",
2273+
"UNDERLINE",
2274+
],
2275+
},
2276+
Object {
2277+
"entity": null,
2278+
"style": Array [
2279+
"BOLD",
2280+
"ITALIC",
2281+
"UNDERLINE",
2282+
],
2283+
},
2284+
Object {
2285+
"entity": null,
2286+
"style": Array [
2287+
"BOLD",
2288+
"ITALIC",
2289+
"UNDERLINE",
2290+
],
2291+
},
2292+
Object {
2293+
"entity": null,
2294+
"style": Array [
2295+
"BOLD",
2296+
"ITALIC",
2297+
"UNDERLINE",
2298+
],
2299+
},
2300+
Object {
2301+
"entity": null,
2302+
"style": Array [
2303+
"BOLD",
2304+
"ITALIC",
2305+
"UNDERLINE",
2306+
],
2307+
},
2308+
],
2309+
"children": Array [],
2310+
"data": Object {},
2311+
"depth": 0,
2312+
"key": "key0",
2313+
"nextSibling": null,
2314+
"parent": null,
2315+
"prevSibling": null,
2316+
"text": "these won't accumulate styles but this span will",
2317+
"type": "unstyled",
2318+
},
2319+
]
2320+
`;
2321+
19652322
exports[`converts deeply nested html blocks when experimentalTreeDataSupport is enabled 1`] = `
19662323
Array [
19672324
Object {

src/model/encoding/__tests__/convertFromHTMLToContentBlocks2-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,25 @@ test('Should preserve spacing around inline tags', () => {
357357
});
358358
});
359359

360+
test('Should scope attribute styles', () => {
361+
const html_string = `
362+
<span style="font-weight: 700">these</span>
363+
<span style="font-style: italic">won't</span>
364+
<span style="text-decoration: underline">accumulate styles</span>
365+
<span style="font-weight: 700">
366+
<span style="font-style: italic">
367+
<span style="text-decoration: underline">
368+
<span>but this span will</span>
369+
</span>
370+
</span>
371+
</span>
372+
`;
373+
374+
assertConvertFromHTMLToContentBlocks(html_string, {
375+
experimentalTreeDataSupport: true,
376+
});
377+
});
378+
360379
test('Should recognized list deep nesting', () => {
361380
const html_string = `
362381
<ul>

0 commit comments

Comments
 (0)