diff --git a/KsApi/lib/HTML Parser/HTMLParserTests.swift b/KsApi/lib/HTML Parser/HTMLParserTests.swift index 57fee33723..535760b549 100644 --- a/KsApi/lib/HTML Parser/HTMLParserTests.swift +++ b/KsApi/lib/HTML Parser/HTMLParserTests.swift @@ -218,27 +218,39 @@ final class HTMLParserTests: XCTestCase { XCTAssertEqual(viewElement.embeddedURLContentHeight, 400) } - func testHTMLParser_WithTextHeadline_Success() { - let viewElements = self.htmlParser.parse(bodyHtml: HTMLParserTemplates.validHeaderText.data) - - guard let viewElement = viewElements.first as? TextViewElement else { - XCTFail("text view element should be created.") - - return - } - - guard viewElement.components.count == 1 else { - XCTFail() - - return + func testHTMLParser_WithTextHeadlines_Success() { + let viewElementsToTextStyleHeaders = + [ + HTMLParserTemplates.validHeader1Text.data: TextComponent.TextStyleType.header1, + HTMLParserTemplates.validHeader2Text.data: TextComponent.TextStyleType.header2, + HTMLParserTemplates.validHeader3Text.data: TextComponent.TextStyleType.header3, + HTMLParserTemplates.validHeader4Text.data: TextComponent.TextStyleType.header4, + HTMLParserTemplates.validHeader5Text.data: TextComponent.TextStyleType.header5, + HTMLParserTemplates.validHeader6Text.data: TextComponent.TextStyleType.header6 + ] + + _ = viewElementsToTextStyleHeaders.map { textData, headerStyle in + let viewElements = self.htmlParser.parse(bodyHtml: textData) + + guard let viewElement = viewElements.first as? TextViewElement else { + XCTFail("text view element should be created.") + + return + } + + guard viewElement.components.count == 1 else { + XCTFail() + + return + } + + XCTAssertEqual( + viewElement.components[0].text, + "Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute." + ) + XCTAssertNil(viewElement.components[0].link) + XCTAssertEqual(viewElement.components[0].styles, [headerStyle]) } - - XCTAssertEqual( - viewElement.components[0].text, - "Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute." - ) - XCTAssertNil(viewElement.components[0].link) - XCTAssertEqual(viewElement.components[0].styles, [TextComponent.TextStyleType.header]) } func testHTMLParser_WithMultipleParagraphsLinksAndStyles_Success() { diff --git a/KsApi/lib/HTML Parser/Templates/HTMLParserTemplates.swift b/KsApi/lib/HTML Parser/Templates/HTMLParserTemplates.swift index 417c155693..0d038fb749 100644 --- a/KsApi/lib/HTML Parser/Templates/HTMLParserTemplates.swift +++ b/KsApi/lib/HTML Parser/Templates/HTMLParserTemplates.swift @@ -11,7 +11,12 @@ public enum HTMLParserTemplates { case validHiddenVideo case validIFrame case validIFrameWithEmbeddedSource - case validHeaderText + case validHeader1Text + case validHeader2Text + case validHeader3Text + case validHeader4Text + case validHeader5Text + case validHeader6Text case validParagraphTextWithStyles case validParagraphTextWithLinksAndStyles case validListWithNestedLinks @@ -39,8 +44,18 @@ public enum HTMLParserTemplates { return self.validExternalSource case .validIFrameWithEmbeddedSource: return self.validEmbeddedExternalSource - case .validHeaderText: - return self.validHeaderText + case .validHeader1Text: + return self.validHeader1Text + case .validHeader2Text: + return self.validHeader2Text + case .validHeader3Text: + return self.validHeader3Text + case .validHeader4Text: + return self.validHeader4Text + case .validHeader5Text: + return self.validHeader5Text + case .validHeader6Text: + return self.validHeader6Text case .validParagraphTextWithLinksAndStyles: return self.validParagraphTextWithLinksAndStyles case .validParagraphTextWithStyles: @@ -74,13 +89,48 @@ public enum HTMLParserTemplates { """ } - private var validHeaderText: String { + private var validHeader1Text: String { """

Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.

\n
\n """ } + private var validHeader2Text: String { + """ +

Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.

+ \n
\n + """ + } + + private var validHeader3Text: String { + """ +

Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.

+ \n
\n + """ + } + + private var validHeader4Text: String { + """ +

Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.

+ \n
\n + """ + } + + private var validHeader5Text: String { + """ +
Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.
+ \n
\n + """ + } + + private var validHeader6Text: String { + """ +
Please participate in helping me finish my film! Just pick a level in the right hand column and click to donate — it only takes a minute.
+ \n
\n + """ + } + private var validAudio: String { """ \n diff --git a/KsApi/lib/HTML Parser/View Elements/TextComponent.swift b/KsApi/lib/HTML Parser/View Elements/TextComponent.swift index 0a0afc28f2..be87fbeb1c 100644 --- a/KsApi/lib/HTML Parser/View Elements/TextComponent.swift +++ b/KsApi/lib/HTML Parser/View Elements/TextComponent.swift @@ -9,6 +9,11 @@ public struct TextComponent { enum TextBlockType: String, CaseIterable { case paragraph = "p" case header1 = "h1" + case header2 = "h2" + case header3 = "h3" + case header4 = "h4" + case header5 = "h5" + case header6 = "h6" case unorderedList = "ul" case orderedList = "ol" } @@ -20,6 +25,11 @@ public struct TextComponent { case bulletStart = "li" case bulletEnd = "" case link = "a" - case header = "h1" + case header1 = "h1" + case header2 = "h2" + case header3 = "h3" + case header4 = "h4" + case header5 = "h5" + case header6 = "h6" } } diff --git a/KsApi/lib/HTML Parser/View Elements/ViewElementType.swift b/KsApi/lib/HTML Parser/View Elements/ViewElementType.swift index e383d90ef1..64fbaf6dfd 100644 --- a/KsApi/lib/HTML Parser/View Elements/ViewElementType.swift +++ b/KsApi/lib/HTML Parser/View Elements/ViewElementType.swift @@ -18,6 +18,11 @@ enum ViewElementType: String { self = childElementType case TextComponent.TextBlockType.header1.rawValue, + TextComponent.TextBlockType.header2.rawValue, + TextComponent.TextBlockType.header3.rawValue, + TextComponent.TextBlockType.header4.rawValue, + TextComponent.TextBlockType.header5.rawValue, + TextComponent.TextBlockType.header6.rawValue, TextComponent.TextBlockType.unorderedList.rawValue, TextComponent.TextBlockType.orderedList.rawValue, TextComponent.TextBlockType.paragraph.rawValue: diff --git a/Library/ViewModels/HTML Parser/TextViewElementCellViewModel.swift b/Library/ViewModels/HTML Parser/TextViewElementCellViewModel.swift index 78cb76d465..b6122f9452 100644 --- a/Library/ViewModels/HTML Parser/TextViewElementCellViewModel.swift +++ b/Library/ViewModels/HTML Parser/TextViewElementCellViewModel.swift @@ -52,8 +52,28 @@ private func attributedText(textElement: TextViewElement) -> SignalProducer SignalProducer