diff --git a/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift b/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift index 753b98c7..f3ad9401 100644 --- a/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift +++ b/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift @@ -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) @@ -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() diff --git a/Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift b/Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift index 1b0e624c..44116421 100644 --- a/Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift +++ b/Tests/MarkdownTests/Visitors/MarkupFormatterTests.swift @@ -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)