Skip to content

Commit

Permalink
Revert "[Feature] Add isAutolink property to Link (#110)"
Browse files Browse the repository at this point in the history
This reverts commit 656cf39.
  • Loading branch information
QuietMisdreavus authored Mar 13, 2023
1 parent 656cf39 commit 6008ef5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
12 changes: 1 addition & 11 deletions Sources/Markdown/Inline Nodes/Inline Containers/Link.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -63,16 +63,6 @@ public extension Link {
}
}

var isAutolink: Bool {
guard let destination,
childCount == 1,
let text = child(at: 0) as? Text,
destination == text.string else {
return false
}
return true
}

// MARK: Visitation

func accept<V: MarkupVisitor>(_ visitor: inout V) -> V.Result {
Expand Down
7 changes: 5 additions & 2 deletions Sources/Markdown/Walker/Walkers/MarkupFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,11 @@ public struct MarkupFormatter: MarkupWalker {
public mutating func visitLink(_ link: Link) {
let savedState = state
if formattingOptions.condenseAutolinks,
link.isAutolink,
let destination = link.destination {
let destination = link.destination,
link.childCount == 1,
let text = link.child(at: 0) as? Text,
// Print autolink-style
destination == text.string {
print("<\(destination)>", for: link)
} else {
func printRegularLink() {
Expand Down
16 changes: 1 addition & 15 deletions Tests/MarkdownTests/Inline Nodes/LinkTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -34,18 +34,4 @@ class LinkTests: XCTestCase {
"""
XCTAssertEqual(expectedDump, link.debugDescription())
}

func testAutoLink() {
let children = [Text("example.com")]
var link = Link(destination: "example.com", children)
let expectedDump = """
Link destination: "example.com"
└─ Text "example.com"
"""
XCTAssertEqual(expectedDump, link.debugDescription())
XCTAssertTrue(link.isAutolink)

link.destination = "test.example.com"
XCTAssertFalse(link.isAutolink)
}
}

0 comments on commit 6008ef5

Please sign in to comment.