From 6008ef55f152ec00b1ec26d505e3f3de2fb400b3 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Mon, 13 Mar 2023 15:17:04 -0600 Subject: [PATCH] Revert "[Feature] Add isAutolink property to Link (#110)" This reverts commit 656cf39c4da2c16813fdcc642c02f796dcfd29fd. --- .../Inline Nodes/Inline Containers/Link.swift | 12 +----------- .../Walker/Walkers/MarkupFormatter.swift | 7 +++++-- Tests/MarkdownTests/Inline Nodes/LinkTests.swift | 16 +--------------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/Sources/Markdown/Inline Nodes/Inline Containers/Link.swift b/Sources/Markdown/Inline Nodes/Inline Containers/Link.swift index 78a27f83..54ae3d8f 100644 --- a/Sources/Markdown/Inline Nodes/Inline Containers/Link.swift +++ b/Sources/Markdown/Inline Nodes/Inline Containers/Link.swift @@ -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 @@ -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(_ visitor: inout V) -> V.Result { diff --git a/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift b/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift index bae1bdbf..37103454 100644 --- a/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift +++ b/Sources/Markdown/Walker/Walkers/MarkupFormatter.swift @@ -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() { diff --git a/Tests/MarkdownTests/Inline Nodes/LinkTests.swift b/Tests/MarkdownTests/Inline Nodes/LinkTests.swift index aeeca9be..895b66af 100644 --- a/Tests/MarkdownTests/Inline Nodes/LinkTests.swift +++ b/Tests/MarkdownTests/Inline Nodes/LinkTests.swift @@ -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 @@ -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) - } }