Skip to content

Commit ec058ad

Browse files
Remove legacy summary adjustments
- Update snapshot expected results for testing - Resolves #17
1 parent 138b850 commit ec058ad

File tree

4 files changed

+1132
-1124
lines changed

4 files changed

+1132
-1124
lines changed

Sources/EvolutionMetadataExtraction/Extractors/FieldExtractors/SummaryExtractor.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,31 @@ struct SummaryExtractor: ValueExtractor {
1919

2020
var summary = ""
2121
var foundIntroduction = false
22-
var foundIntroductionIndex = -1
2322
for child in document.children {
2423

2524
if let heading = child as? Heading {
2625
if heading.plainText.contains("Introduction") {
2726
foundIntroduction = true
28-
foundIntroductionIndex = heading.indexInParent
2927
} else if foundIntroduction {
3028
break
3129
}
3230
} else if foundIntroduction, let textConvertible = child as? any PlainTextConvertibleMarkup {
33-
// let formatString = textConvertible.format(options: MarkupFormatter.Options(preferredLineLimit:MarkupFormatter.Options.PreferredLineLimit(maxLength: 80, breakWith: .softBreak)))
31+
3432
let formatString = textConvertible.format()
35-
36-
// The previous implementation did not find summaries if there was a some unrecognized element in the way, such as a blockquote or a paragraph with HTML markup
37-
// It probably makes sense to remove the (textConvertible.indexInParent - foundIntroductionIndex == 1) restriction after the transition
38-
if textConvertible.indexInParent - foundIntroductionIndex == 1 {
39-
summary += formatString.replacingOccurrences(of: "\n\n", with: "").replacingOccurrences(of: " \n", with: "\n") + "\n"
33+
34+
// The returned string begins with two consecutive newlines
35+
// A hard line break in the middle of a paragraph appears as a single newline
36+
// A hard line break followed by a backtick appears as two consecutive newlines
37+
38+
// To adjust find matches of one or two newlines.
39+
// If the match is at the start of the string, replace with empty string.
40+
// Otherwise replace it with a space.
41+
let processedSummary = formatString.replacing(/\n\n?/) { match in
42+
match.range.lowerBound == formatString.startIndex ? "" : " "
4043
}
41-
break
44+
summary += processedSummary
45+
46+
break // Break to include only the first plain text convertable (typically a paragraph)
4247
}
4348
}
4449

Tests/ExtractionTests/Resources/AllProposals.evosnapshot/README.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ The expected-result.json file in this snapshot is generated by the swift-evoluti
22

33
It is the current proposals.json file at the time of the snapshot.
44

5-
Created Mar 13, 2024
5+
Proposals data captured on Mar 13, 2024
6+
7+
Expected results updated on Mar 17, 2024

0 commit comments

Comments
 (0)