Skip to content

Commit

Permalink
Merge pull request #105 from apps-fab/master
Browse files Browse the repository at this point in the history
Highlight.js updated to v11.9.0
  • Loading branch information
raspu authored Jun 18, 2024
2 parents b791f31 + e0dbdad commit fa483d3
Show file tree
Hide file tree
Showing 2 changed files with 3,572 additions and 30 deletions.
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

0 comments on commit fa483d3

Please sign in to comment.