Skip to content

Commit

Permalink
apply new line break logic to inline attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Mar 29, 2023
1 parent 90f7dd5 commit b638502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Markdown/Walker/Walkers/MarkupFormatter.swift
Expand Up @@ -1138,7 +1138,7 @@ public struct MarkupFormatter: MarkupWalker {
public mutating func visitInlineAttributes(_ attributes: InlineAttributes) {
let savedState = state
func printInlineAttributes() {
print("[", for: attributes)
print("^[", for: attributes)
descendInto(attributes)
print("](", for: attributes)
print(attributes.attributes, for: attributes)
Expand All @@ -1152,7 +1152,7 @@ public struct MarkupFormatter: MarkupWalker {
// gets into the realm of JSON formatting which might be out of scope of
// this formatter. Therefore if exceeded, prefer to print it on the next
// line to give as much opportunity to keep the attributes on one line.
if attributes.indexInParent > 0 && (isOverPreferredLineLimit || state.lineNumber > savedState.lineNumber) {
if attributes.indexInParent > 0 && (isOverPreferredLineLimit || state.effectiveLineNumber > savedState.effectiveLineNumber) {
restoreState(to: savedState)
queueNewline()
printInlineAttributes()
Expand Down
18 changes: 18 additions & 0 deletions Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift
Expand Up @@ -744,6 +744,24 @@ class MarkupFormatterSimpleRoundTripTests: XCTestCase {
checkCharacterEquivalence(for: source)
}

func testRoundTripHardBreakWithInlineAttribute() {
let source = """
This is some text.\(" ")
^[This is some attributed text.](rainbow: 'extreme')
"""
checkRoundTrip(for: source)
checkCharacterEquivalence(for: source)
}

func testRoundTripSoftBreakWithInlineAttribute() {
let source = """
This is some text.
^[This is some attributed text.](rainbow: 'extreme')
"""
checkRoundTrip(for: source)
checkCharacterEquivalence(for: source)
}

/// Why not?
func testRoundTripReadMe() throws {
let readMeURL = URL(fileURLWithPath: #file)
Expand Down

0 comments on commit b638502

Please sign in to comment.