From 17b2ed92c341c21d91cb9bfdd45656c7fd7c7d4d Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 22 Jul 2024 09:38:35 -0700 Subject: [PATCH 1/2] Fallback to `highlightAuto` if highlighting fails Same as #96 but without the CSS changes. Some change in 2.2.0 made this issue resurface. --- Pod/Classes/Highlightr.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/Highlightr.swift b/Pod/Classes/Highlightr.swift index 211e28c..99b8869 100644 --- a/Pod/Classes/Highlightr.swift +++ b/Pod/Classes/Highlightr.swift @@ -111,9 +111,13 @@ open class Highlightr let ret: JSValue? if let languageName = languageName { - ret = hljs.invokeMethod("highlight", withArguments: [code, ["language": languageName, "ignoreIllegals": ignoreIllegals]]) - - + let result: JSValue = hljs.invokeMethod("highlight", withArguments: [languageName, code, ignoreIllegals]) + if result.isUndefined { + // If highlighting failed, use highlightAuto + ret = hljs.invokeMethod("highlightAuto", withArguments: [code]) + } else { + ret = result + } }else { // language auto detection From b4f3b0caa5b356116a6883cf0d79c7199abe464a Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Wed, 24 Jul 2024 07:34:23 -0700 Subject: [PATCH 2/2] Update Highlightr.swift --- Pod/Classes/Highlightr.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/Highlightr.swift b/Pod/Classes/Highlightr.swift index 99b8869..b6e7839 100644 --- a/Pod/Classes/Highlightr.swift +++ b/Pod/Classes/Highlightr.swift @@ -112,7 +112,7 @@ open class Highlightr if let languageName = languageName { let result: JSValue = hljs.invokeMethod("highlight", withArguments: [languageName, code, ignoreIllegals]) - if result.isUndefined { + if result.isUndefined { // If highlighting failed, use highlightAuto ret = hljs.invokeMethod("highlightAuto", withArguments: [code]) } else {