You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see this code in CodeAttributedString of Highlightr. It has a non-nil check for language else it doesn't proceed and hence doesn't highlight nor auto-detect the language. Is this expected?
func highlight(_ range: NSRange)
{
if(language == nil)
{
return;
}
if let highlightDelegate = highlightDelegate
{
let shouldHighlight : Bool? = highlightDelegate.shouldHighlight?(range)
if(shouldHighlight != nil && !shouldHighlight!)
{
return;
}
}
let string = (self.string as NSString)
let line = string.substring(with: range)
DispatchQueue.global().async
{
let tmpStrg = self.highlightr.highlight(line, as: self.language!)
DispatchQueue.main.async(execute: {
//Checks to see if this highlighting is still valid.
if((range.location + range.length) > self.stringStorage.length)
{
self.highlightDelegate?.didHighlight?(range, success: false)
return;
}
if(tmpStrg?.string != self.stringStorage.attributedSubstring(from: range).string)
{
self.highlightDelegate?.didHighlight?(range, success: false)
return;
}
self.beginEditing()
tmpStrg?.enumerateAttributes(in: NSMakeRange(0, (tmpStrg?.length)!), options: [], using: { (attrs, locRange, stop) in
var fixedRange = NSMakeRange(range.location+locRange.location, locRange.length)
fixedRange.length = (fixedRange.location + fixedRange.length < string.length) ? fixedRange.length : string.length-fixedRange.location
fixedRange.length = (fixedRange.length >= 0) ? fixedRange.length : 0
self.stringStorage.setAttributes(attrs, range: fixedRange)
})
self.endEditing()
self.edited(TextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
self.highlightDelegate?.didHighlight?(range, success: true)
})
}
}
The text was updated successfully, but these errors were encountered:
I wouldn't say it is intentional (rather a missing feature), but it can't highlight if it doesn't know what language to apply.
And I don't know how to detect a language, does Highlightr have sth for this?
The initializer for CodeEditor says that Highlightr will auto-detect the language if one is not provided.
/**
* Configures a read-only CodeEditor View with the given parameters.
*
* - Parameters:
* - source: A String that holds the source code to be displayed.
* - language: Optionally set a language (e.g. `.swift`), otherwise
* Highlight.js will attempt to detect the language.
* - theme: The name of the theme to use, defaults to "pojoaque".
* - fontSize: On macOS this Binding can be used to persist the size of
* the font in use. At runtime this is combined with the
* theme to produce the full font information. (optional)
* - flags: Configure whether the text is selectable
* (defaults to both).
* - indentStyle: Optionally insert a configurable amount of spaces if the
* user hits "tab".
* - autoPairs: A mapping of open/close characters, where the close
* characters are automatically injected when the user enters
* the opening character. For example: `[ "{": "}" ]` would
* automatically insert the closing "}" if the user enters
* "{". If no value is given, the default mapping for the
* language is used.
* - inset: The editor can be inset in the scroll view. Defaults to
* 8/8.
*/
Hello,
I see this code in
CodeAttributedString
ofHighlightr
. It has a non-nil check forlanguage
else it doesn't proceed and hence doesn't highlight nor auto-detect the language. Is this expected?The text was updated successfully, but these errors were encountered: