File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
src/FSharp.Data.Html.Core
tests/FSharp.Data.Core.Tests Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ The `Load` method allows reading the data from a file or web resource. We could
66
66
The following sample calls the `Load` method with an URL that points to a live version of the same page on wikipedia.
67
67
*)
68
68
// Download the table for the 2017 F1 calendar from Wikipedia
69
- let f1Calendar = F1_ 2017.Load( F1_ 2017_ URL) .Tables.`` Season calendaredit ``
69
+ let f1Calendar = F1_ 2017.Load( F1_ 2017_ URL) .Tables.`` Season calendar ``
70
70
71
71
// Look at the top row, being the first race of the calendar
72
72
let firstRow = f1Calendar.Rows |> Seq.head
@@ -146,7 +146,7 @@ let doctorWho = new HtmlProvider<DrWho>()
146
146
147
147
// Get the average number of viewers for each doctor's series run
148
148
let viewersByDoctor =
149
- doctorWho.Tables.`` Season 1 (1963-1964) edit `` .Rows
149
+ doctorWho.Tables.`` Season 1 (1963-1964) `` .Rows
150
150
|> Seq.groupBy ( fun season -> season.`` Directed by `` )
151
151
|> Seq.map ( fun ( doctor , seasons ) ->
152
152
let averaged =
Original file line number Diff line number Diff line change @@ -132,7 +132,11 @@ type HtmlNode =
132
132
| HtmlText _ -> true
133
133
| _ -> false )
134
134
135
- if canAddNewLine && not onlyText then newLine 0
135
+ let isPreTag = name = " pre"
136
+
137
+ if canAddNewLine && not ( onlyText || isPreTag) then
138
+ newLine 0
139
+
136
140
append " <"
137
141
append name
138
142
@@ -150,14 +154,14 @@ type HtmlNode =
150
154
appendEndTag name
151
155
else
152
156
append " >"
153
- if not onlyText then newLine 2
157
+ if not ( onlyText || isPreTag ) then newLine 2
154
158
let mutable canAddNewLine = false
155
159
156
160
for element in elements do
157
161
serialize sb ( indentation + 2 ) canAddNewLine element
158
162
canAddNewLine <- true
159
163
160
- if not onlyText then newLine 0
164
+ if not ( onlyText || isPreTag ) then newLine 0
161
165
appendEndTag name
162
166
| HtmlText str -> append str
163
167
| HtmlComment str ->
Original file line number Diff line number Diff line change @@ -857,6 +857,18 @@ let ``Drops whitespace outside pre``() =
857
857
let expected = $" <div>%s {nl} foo <pre> bar </pre> baz%s {nl}</div>"
858
858
result |> should equal expected
859
859
860
+ [<Test>]
861
+ let ``Maintain whitespace inside pre tag through round - trip`` () =
862
+ let html = """ <pre>
863
+ <span>Line 1</span>
864
+ <span>Line 2</span>
865
+ <span>Line 3</span></pre>"""
866
+
867
+ let result = HtmlDocument.Parse( html) .ToString()
868
+
869
+ let expected = html
870
+ result |> should equal expected
871
+
860
872
[<Test>]
861
873
let ``Can parse national rail mobile site correctly`` () =
862
874
HtmlDocument.Load " UKDepartures.html"
You can’t perform that action at this time.
0 commit comments