flutter-code-editor
flutter-code-editor copied to clipboard
Fix highlight package
Java highlighting breaks if # is present anywhere but string literals and comments:
public class MyClass {
}
#
Java highlighting beaks if a multiline string literal is present anywhere with single or double quotes:
public class MyClass {
private string = """
multiline
""";
}
Python highlighting breaks if a block opening line is not terminated with ::
def fn()
Scala highlighting breaks if a multiline string literal is present anywhere:
val str4 = """
multiline
""";
We are using this package for highlighting: https://pub.dev/packages/highlight It is not maintained, and the authors do not respond to issues.
It is a port of a well-maintained JavaScript package: https://highlightjs.org
Maybe we should investigate the automation of porting this from JavaScript and make our own highlighting package.
The impact is that we rely on to-be-hidden service comments for special features like read-only blocks, initially collapsed blocks, and hidden blocks. And we rely on this highlighting package to parse the comments. If some code breaks highlighting, we cannot parse comments, and those features break.
A workaround is made in #28. If highlighting breaks, we fall back to a naive parsing that just searches for // or # depending on the language and considers everything from that sequence to the end of the string a comment. It gives false positives for
string s = "// not a comment";
and so it is unreliable.