Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Lib #105

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,582 changes: 3,565 additions & 17 deletions Pod/Assets/Highlighter/highlight.min.js

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions Pod/Classes/Highlightr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ open class Highlightr
{
let jsContext = JSContext()!
let window = JSValue(newObjectIn: jsContext)
jsContext.setObject(window, forKeyedSubscript: "window" as NSString)

#if SWIFT_PACKAGE
let bundle = Bundle.module
Expand All @@ -66,14 +65,8 @@ open class Highlightr

let hgJs = try! String.init(contentsOfFile: hgPath)
let value = jsContext.evaluateScript(hgJs)
if value?.toBool() != true
{
return nil
}
guard let hljs = window?.objectForKeyedSubscript("hljs") else
{
return nil
}
guard let hljs = jsContext.objectForKeyedSubscript("hljs") else { return nil }

self.hljs = hljs

guard setTheme(to: "pojoaque") else
Expand Down Expand Up @@ -115,18 +108,19 @@ open class Highlightr
*/
open func highlight(_ code: String, as languageName: String? = nil, fastRender: Bool = true) -> NSAttributedString?
{
let ret: JSValue
let ret: JSValue?
if let languageName = languageName
{
ret = hljs.invokeMethod("highlight", withArguments: [languageName, code, ignoreIllegals])
ret = hljs.invokeMethod("highlight", withArguments: [code, ["language": languageName, "ignoreIllegals": ignoreIllegals]])


}else
{
// language auto detection
ret = hljs.invokeMethod("highlightAuto", withArguments: [code])
}

let res = ret.objectForKeyedSubscript("value")
guard var string = res!.toString() else
guard let res = ret?.objectForKeyedSubscript("value"), var string = res.toString() else
{
return nil
}
Expand Down