Extract HTML fixtures out of the FormattedBoxyText previews.

This commit is contained in:
Stefan Ceriu
2025-08-27 13:38:25 +03:00
committed by Doug
parent 3370f3906e
commit d16f0ac8d0
3 changed files with 113 additions and 83 deletions
@@ -142,90 +142,8 @@ struct FormattedBodyText_Previews: PreviewProvider, TestablePreview {
}
@ViewBuilder
// swiftlint:disable:next function_body_length
static func body(_ attributedStringBuilder: AttributedStringBuilderProtocol) -> some View {
let htmlStrings = [
"""
Nothing is as permanent as a temporary solution that works.
Experience is the name everyone gives to their mistakes.
If debugging is the process of removing bugs, then programming must be the process of putting them in.
""",
"""
<h1>H1 Header</h1></br>
<h2>H2 Header</h2></br>
<h3>H3 Header</h3></br>
<h4>H4 Header</h4></br>
<h5>H5 Header</h5></br>
<h6>H6 Header</h6>
""",
"""
<p>This is a paragraph.</p><p>And this is another one.</p>
<div>And this is a division.</div>
New lines are ignored.\n\nLike so.</br>
But this line comes after a line break.</br>
""",
"""
We expect various identifiers to be (partially) detected:</br>
!room:matrix.org, #room:matrix.org, $event:matrix.org, @user:matrix.org</br>
matrix://roomid/room:matrix.org, matrix://r/room:matrix.org, matrix://roomid/room:matrix.org/e/event:matrix.org, matrix://roomid/room:matrix.org/u/user:matrix.org</br>
""",
"""
Links too:</br><a href=\"https://www.matrix.org/\">Matrix rules! 🤘</a>, matrix.org, www.matrix.org, http://matrix.org
""",
"""
<b>Text</b> <i>formatting</i> <u>should</u> <s>work</s> properly.</br>
<strong>Text</strong> <em>formatting</em> does <del>work!</del>.</br>
<b>And <i>mixed</i></b> <em><s>formatting</s></em> <del><strong>works</strong></del> <u><b>too!!1!</b></u>.
<br>
<sup>Thumbs</sup> if you liked it, <sub>sub</sub> if you loved it!
""",
"""
Text before blockquote<blockquote><b>Nothing</b> <i>is</i> as permanent as a <u>temporary<u> solution that <a href=\"https://www.matrix.org/\">works.</blockquote>Text after blockquote
""",
"""
<blockquote>First blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Second blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Third blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
""",
"""
<blockquote>A blockquote that is long and goes onto multiple lines </blockquote>
<p>Then another line of text to reply to the blockquote, also multiline.</p>
<blockquote>Then a short blockquote.</blockquote><p>Followed by another short sentence.</p>
""",
"""
<pre>A preformatted code block<code>struct ContentView: View {
var body: some View {
VStack {
Text("Knock, knock!")
.padding()
.background(Color.yellow, in: RoundedRectangle(cornerRadius: 8))
Text("Who's there?")
}
.padding()
}
}</code></pre></br>
Followed by some plain code blocks</br>
<code>Hello, world!</code>
<code><b>Hello</b>, <i>world!</i></code>
<code><b>Hello</b>, <a href="https://www.matrix.org">world!</a></code>
""",
"""
This is an unordered list
<ul>
<li>Jones’ <b>Crumpets</b></li>
<li><i>Crumpetorium</i></li>
<li>Village <u>Bakery</u></li>
</ul>
""",
"""
This is an ordered list
<ol>
<li>Jelly Belly</li>
<li>Starburst</li>
<li>Skittles</li>
</ol>
"""
]
let htmlStrings = HTMLFixtures.allCases.map(\.rawValue)
ScrollView {
VStack(alignment: .leading, spacing: 4.0) {