Skip to content

Commit 0df5dc4

Browse files
committed
[Feat] add support <hr> tag
1 parent 5b1a6c5 commit 0df5dc4

File tree

8 files changed

+13
-3
lines changed

8 files changed

+13
-3
lines changed

Sources/ZMarkupParser/Core/Markup/Markups/HorizontalLineMarkup.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import Foundation
99

1010
final class HorizontalLineMarkup: Markup {
1111
let style: MarkupStyle?
12+
let dashLength: Int
1213

1314
var parentMarkup: Markup? = nil
1415
var childMarkups: [Markup] = []
1516

16-
init(style: MarkupStyle?) {
17+
init(dashLength: Int, style: MarkupStyle?) {
18+
self.dashLength = dashLength
1719
self.style = style
1820
}
1921

Sources/ZMarkupParser/Core/Processor/MarkupNSAttributedStringVisitor.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct MarkupNSAttributedStringVisitor: MarkupVisitor {
3535
}
3636

3737
func visit(_ markup: HorizontalLineMarkup) -> Result {
38+
markup.appendChild(markup: BreakLineMarkup())
39+
markup.appendChild(markup: RawStringMarkup(attributedString: NSAttributedString(string: String(repeating: "-", count: markup.dashLength))))
40+
markup.prependChild(markup: BreakLineMarkup())
3841
return collectAttributedString(markup)
3942
}
4043

Sources/ZMarkupParser/HTML/HTMLTag/HTMLTagNames/HR_HTMLTagName.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import Foundation
99

1010
public struct HR_HTMLTagName: HTMLTagName {
1111
public let string: String = WC3HTMLTagName.hr.rawValue
12+
public let dashLength: Int
13+
init(dashLength: Int = 7) {
14+
self.dashLength = dashLength
15+
}
1216

1317
public func accept<V>(_ visitor: V) -> V.Result where V : HTMLTagNameVisitor {
1418
return visitor.visit(self)

Sources/ZMarkupParser/HTML/Processor/HTMLTagNameToHTMLMarkupVisitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct HTMLTagNameToMarkupVisitor: HTMLTagNameVisitor {
4040
}
4141

4242
func visit(_ tagName: HR_HTMLTagName) -> Result {
43-
return HorizontalLineMarkup(style: style)
43+
return HorizontalLineMarkup(dashLength: tagName.dashLength, style: style)
4444
}
4545

4646
func visit(_ tagName: I_HTMLTagName) -> Result {

Tests/ZMarkupParserSnapshotTests/ZMarkupParserSnapshotTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class ZHTMLToNSAttributedStringSnapshotTests: XCTestCase {
1313
<li><a href="https://zhgchg.li">German design hair remover</a>|<strong>500</strong> yuan practical gift like this</li>
1414
<li><a href="https://zhgchg.li">Drink cup</a>|Fund-raising and praise exceeded 10 million</li>
1515
</ol>
16+
<hr/>
1617
<p>Before 12/26, place an order and draw a round-trip ticket for two to Japan!</p>
1718
你好你好<span style="background-color:red">你好你好</span>你好你好 <br />
1819
안녕하세요안녕하세<span style="color:red">요안녕하세</span>요안녕하세요안녕하세요안녕하세요 <br />

ZMarkupParser.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ZMarkupParser"
3-
s.version = "1.0.6"
3+
s.version = "1.0.8"
44
s.summary = "ZMediumToMarkdown lets you download Medium post and convert it to markdown format easily."
55
s.homepage = "https://github.com/ZhgChgLi/ZMediumToMarkdown"
66
s.license = { :type => "MIT", :file => "LICENSE" }

0 commit comments

Comments
 (0)