highlight.dart icon indicating copy to clipboard operation
highlight.dart copied to clipboard

Multiline string literal breaks java highlighting

Open alexeyinkin opened this issue 2 years ago • 0 comments

For this input:

class MyClass {
  private string str = "abc";
}

we get the correct result:

image

Make this string literal multiline:

class MyClass {
  private string str = """
  abc
  """;
}

and nothing is parsed:

image

Note that language is also null although java is explicitly passed.

This codepen shows that the original highlightjs can handle multiline string literals: https://codepen.io/alexey-inkin/pen/abYYVOj

Code
import 'package:highlight/highlight_core.dart';
import 'package:highlight/languages/java.dart';

void main() {
  highlight.registerLanguage('java', java);

  const text = '''
class MyClass {
  private string str = "abc";
}
''';
  final result = highlight.parse(text, language: 'java');
  print(result.nodes);

  const textMultiline = '''
class MyClass {
  private string str = """
  abc
  """;
}
''';
  final resultMultiline = highlight.parse(textMultiline, language: 'java');
  print(resultMultiline.nodes);
}
Output
[Instance of 'Node', Instance of 'Node', Instance of 'Node', Instance of 'Node', Instance of 'Node', Instance of 'Node', Instance of 'Node']
[Instance of 'Node']

alexeyinkin avatar Aug 04 '22 06:08 alexeyinkin