Skip to content

Commit

Permalink
Replace line separator with paragraph separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgulan committed May 16, 2019
1 parent 5396a85 commit 94c3ee0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Source/AST/Visitors/AttributedStringVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension AttributedStringVisitor: Visitor {

public func visit(blockQuote node: BlockQuote) -> NSMutableAttributedString {
let s = visitChildren(of: node).joined
if node.hasSuccessor { s.append(.blankLine) }
if node.hasSuccessor { s.append(.paragraphSeparator) }
styler.style(blockQuote: s)
return s
}
Expand All @@ -59,14 +59,14 @@ extension AttributedStringVisitor: Visitor {
}

let s = items.joined
if node.hasSuccessor { s.append(.blankLine) }
if node.hasSuccessor { s.append(.paragraphSeparator) }
styler.style(list: s)
return s
}

public func visit(item node: Item) -> NSMutableAttributedString {
let s = visitChildren(of: node).joined
if node.hasSuccessor { s.append(.blankLine) }
if node.hasSuccessor { s.append(.paragraphSeparator) }
styler.style(item: s)
return s
}
Expand All @@ -91,20 +91,20 @@ extension AttributedStringVisitor: Visitor {

public func visit(paragraph node: Paragraph) -> NSMutableAttributedString {
let s = visitChildren(of: node).joined
if node.hasSuccessor { s.append(.blankLine) }
if node.hasSuccessor { s.append(.paragraphSeparator) }
styler.style(paragraph: s)
return s
}

public func visit(heading node: Heading) -> NSMutableAttributedString {
let s = visitChildren(of: node).joined
if node.hasSuccessor { s.append(.blankLine) }
if node.hasSuccessor { s.append(.paragraphSeparator) }
styler.style(heading: s, level: node.headingLevel)
return s
}

public func visit(thematicBreak node: ThematicBreak) -> NSMutableAttributedString {
let s = "\n".attributed
let s = String.lineSeparator.attributed
styler.style(thematicBreak: s)
return s
}
Expand All @@ -116,13 +116,13 @@ extension AttributedStringVisitor: Visitor {
}

public func visit(softBreak node: SoftBreak) -> NSMutableAttributedString {
let s = (options.contains(.hardBreaks) ? "\n" : " ").attributed
let s = (options.contains(.hardBreaks) ? String.lineSeparator : " ").attributed
styler.style(softBreak: s)
return s
}

public func visit(lineBreak node: LineBreak) -> NSMutableAttributedString {
let s = "\n".attributed
let s = String.lineSeparator.attributed
styler.style(lineBreak: s)
return s
}
Expand Down Expand Up @@ -185,7 +185,7 @@ private extension String {
}

private extension NSAttributedString {
static var blankLine: NSAttributedString {
static var paragraphSeparator: NSAttributedString {
return "\n".attributed
}
}
Expand All @@ -195,3 +195,9 @@ private extension NSMutableAttributedString {
return "".attributed
}
}
private extension String {
// https://lists.apple.com/archives/Cocoa-dev/2010/Dec/msg00347.html
static var lineSeparator: String {
return "\u{2028}"
}
}

0 comments on commit 94c3ee0

Please sign in to comment.