diff --git a/Classes/Repository/RepositoryCodeBlobViewController.swift b/Classes/Repository/RepositoryCodeBlobViewController.swift index c08e7f21e..1db663c05 100644 --- a/Classes/Repository/RepositoryCodeBlobViewController.swift +++ b/Classes/Repository/RepositoryCodeBlobViewController.swift @@ -126,7 +126,7 @@ final class RepositoryCodeBlobViewController: UIViewController { func handle(text: String) { emptyView.isHidden = true didFetchPayload(text) - codeView.set(code: text, language: path.fileExtension) + codeView.set(code: text) } } diff --git a/Classes/Systems/GithubHighlighting.swift b/Classes/Systems/GithubHighlighting.swift index 47de03508..aed688b04 100644 --- a/Classes/Systems/GithubHighlighting.swift +++ b/Classes/Systems/GithubHighlighting.swift @@ -20,5 +20,8 @@ enum GithubHighlighting { static func highlight(_ code: String, as language: String) -> NSAttributedString? { return shared?.highlight(code, as: language, fastRender: true) } - + + static func highlight(_ code: String) -> NSAttributedString? { + return shared?.highlight(code) + } } diff --git a/Classes/Views/CodeView.swift b/Classes/Views/CodeView.swift index 87bb64e72..896987f58 100644 --- a/Classes/Views/CodeView.swift +++ b/Classes/Views/CodeView.swift @@ -31,23 +31,15 @@ final class CodeView: UITextView { } // MARK: Public API - - func set(code: String) { - set(attributedCode: NSAttributedString( - string: code, - attributes: [ - // match Highlightr size - .font: UIFont(name: "Courier", size: 14)!, - .foregroundColor: Styles.Colors.Gray.dark.color, - ])) - } - - func set(code: String, language: String?) { + func set(code: String, language: String? = nil) { if let language = language, let highlighted = GithubHighlighting.highlight(code, as: language) { set(attributedCode: highlighted) } else { - set(code: code) + // Automatic language detection + if let highlighted = GithubHighlighting.highlight(code) { + set(attributedCode: highlighted) + } } }