File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed
Inline Nodes/Inline Containers
Tests/MarkdownTests/Inline Nodes Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
2
This source file is part of the Swift.org open source project
3
3
4
- Copyright (c) 2021 Apple Inc. and the Swift project authors
4
+ Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
5
5
Licensed under Apache License v2.0 with Runtime Library Exception
6
6
7
7
See https://swift.org/LICENSE.txt for license information
@@ -63,6 +63,16 @@ public extension Link {
63
63
}
64
64
}
65
65
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
+
66
76
// MARK: Visitation
67
77
68
78
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 {
819
819
public mutating func visitLink( _ link: Link ) {
820
820
let savedState = state
821
821
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 {
827
824
print ( " < \( destination) > " , for: link)
828
825
} else {
829
826
func printRegularLink( ) {
Original file line number Diff line number Diff line change 1
1
/*
2
2
This source file is part of the Swift.org open source project
3
3
4
- Copyright (c) 2021 Apple Inc. and the Swift project authors
4
+ Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
5
5
Licensed under Apache License v2.0 with Runtime Library Exception
6
6
7
7
See https://swift.org/LICENSE.txt for license information
@@ -34,4 +34,18 @@ class LinkTests: XCTestCase {
34
34
"""
35
35
XCTAssertEqual ( expectedDump, link. debugDescription ( ) )
36
36
}
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
+ }
37
51
}
You can’t perform that action at this time.
0 commit comments