Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from pkrll/master
Browse files Browse the repository at this point in the history
Add support for macOS
  • Loading branch information
andr-ec authored Mar 23, 2020
2 parents 4b4313e + f979c72 commit 7990337
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/MDText/MDText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import SwiftUI
import Combine
#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif

protocol MarkdownRule {
var id: String { get }
Expand Down Expand Up @@ -58,7 +62,11 @@ struct MDViewGroup: Identifiable {
func onLinkTap(urlStr: String) {
print(urlStr)
guard let url = URL(string: urlStr) else { return }
UIApplication.shared.open(url, options: [:])
#if os(iOS)
UIApplication.shared.openURL(url, options: [:])
#elseif os(macOS)
NSWorkspace.shared.open(url)
#endif
}
}

Expand Down Expand Up @@ -223,7 +231,11 @@ final class MDTextVM: ObservableObject {
func replaceLInk(for textGroup: MDTextGroup) -> AnyView {
return Button(action: {
guard let url = URL(string: textGroup.string) else { return }
UIApplication.shared.open(url, options: [:])
#if os(iOS)
UIApplication.shared.openURL(url, options: [:])
#elseif os(macOS)
NSWorkspace.shared.open(url)
#endif
}, label: {textGroup.text})
.ereaseToAnyView()
//
Expand Down

0 comments on commit 7990337

Please sign in to comment.