File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
Inline Nodes/Inline Containers
Tests/MarkdownTests/Inline Nodes Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change 11/*
22 This source file is part of the Swift.org open source project
33
4- Copyright (c) 2021 Apple Inc. and the Swift project authors
4+ Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
55 Licensed under Apache License v2.0 with Runtime Library Exception
66
77 See https://swift.org/LICENSE.txt for license information
@@ -63,6 +63,16 @@ public extension Link {
6363 }
6464 }
6565
66+ var isAutolink : Bool {
67+ guard let destination,
68+ childCount == 1 ,
69+ let text = child ( at: 0 ) as? Text ,
70+ destination == text. string else {
71+ return false
72+ }
73+ return true
74+ }
75+
6676 // MARK: Visitation
6777
6878 func accept< V: MarkupVisitor > ( _ visitor: inout V ) -> V . Result {
Original file line number Diff line number Diff line change @@ -819,11 +819,8 @@ public struct MarkupFormatter: MarkupWalker {
819819 public mutating func visitLink( _ link: Link ) {
820820 let savedState = state
821821 if formattingOptions. condenseAutolinks,
822- let destination = link. destination,
823- link. childCount == 1 ,
824- let text = link. child ( at: 0 ) as? Text ,
825- // Print autolink-style
826- destination == text. string {
822+ link. isAutolink,
823+ let destination = link. destination {
827824 print ( " < \( destination) > " , for: link)
828825 } else {
829826 func printRegularLink( ) {
Original file line number Diff line number Diff line change 11/*
22 This source file is part of the Swift.org open source project
33
4- Copyright (c) 2021 Apple Inc. and the Swift project authors
4+ Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
55 Licensed under Apache License v2.0 with Runtime Library Exception
66
77 See https://swift.org/LICENSE.txt for license information
@@ -34,4 +34,21 @@ class LinkTests: XCTestCase {
3434 """
3535 XCTAssertEqual ( expectedDump, link. debugDescription ( ) )
3636 }
37+
38+ func testAutoLink( ) {
39+ let children = [ Text ( " example.com " ) ]
40+ var link = Link ( destination: " example.com " , children)
41+ let expectedDump = """
42+ Link destination: " example.com "
43+ └─ Text " example.com "
44+ """
45+ XCTAssertEqual ( expectedDump, link. debugDescription ( ) )
46+ XCTAssertTrue ( link. isAutolink)
47+
48+ link. destination = " test.example.com "
49+ XCTAssertFalse ( link. isAutolink)
50+
51+ link. isAutolink = true
52+ XCTAssertTrue ( link. isAutolink)
53+ }
3754}
You can’t perform that action at this time.
0 commit comments