flutter-code-editor icon indicating copy to clipboard operation
flutter-code-editor copied to clipboard

Fix highlight package

Open alexeyinkin opened this issue 3 years ago • 2 comments

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
""";

alexeyinkin avatar Aug 04 '22 13:08 alexeyinkin

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.

alexeyinkin avatar Aug 04 '22 13:08 alexeyinkin

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.

alexeyinkin avatar Aug 04 '22 14:08 alexeyinkin