highlight 0.5.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

highlight #

pub

Dart Syntax highlighting library.

If you are looking for Flutter widget, see flutter_highlight.

Usage #

import 'package:highlight/highlight.dart' show highlight;

main() {
  var source = '''main() {
  print("Hello, World!");
}
''';

  var result = highlight.parse(source, language: 'dart');
  var html = result.toHtml();
  print(html); // HTML string
}

Notice that all available languages are registered in the way above. For those desiring more control over what exactly they need, import highlight_core.dart instead and register languages manually:

import 'package:highlight/highlight_core.dart' show highlight;
import 'package:highlight/languages/dart.dart';

main() {
  var source = '''main() {
  print("Hello, World!");
}
''';

  highlight.registerLanguage('dart', dart);

  var result = highlight.parse(source, language: 'dart');
  var html = result.toHtml();
  print(html); // HTML string
}

References #

License #

MIT

0.5.0 #

  • Support GN and Solidity

0.4.1 #

  • Support GraphQL and Vue
  • Add highlight_core.dart

0.4.0 #

  • Add auto detection option
  • Fallback to plaintext if language not registered

0.3.0 #

  • Exports singleton

0.2.0 #

  • Refactor and improve documentation

0.1.0 #

  • First release

0.0.1 #

  • Initial version, created by Stagehand

example/highlight.dart

import 'package:highlight/highlight.dart' show highlight;

main() {
  var source = '''main() {
  print("Hello, World!");
}
''';

  var result = highlight.parse(source, language: 'dart');
  var html = result.toHtml();
  print(html); // HTML string
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  highlight: ^0.5.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:highlight/highlight.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
91
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Dec 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:highlight/highlight.dart.

Health issues and suggestions

Document public APIs. (-0.82 points)

484 out of 487 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/languages/accesslog.dart. (-0.50 points)

Analysis of lib/languages/accesslog.dart reported 1 hint:

line 4 col 8: Unused import: '../src/common_modes.dart'.

Fix lib/languages/clojure-repl.dart. (-0.50 points)

Analysis of lib/languages/clojure-repl.dart reported 1 hint:

line 4 col 8: Unused import: '../src/common_modes.dart'.

Fix lib/languages/csp.dart. (-0.50 points)

Analysis of lib/languages/csp.dart reported 1 hint:

line 4 col 8: Unused import: '../src/common_modes.dart'.

Fix additional 14 files with analysis or formatting issues. (-7 points)

Additional issues in the following files:

  • lib/languages/diff.dart (1 hint)
  • lib/languages/fix.dart (1 hint)
  • lib/languages/http.dart (1 hint)
  • lib/languages/inform7.dart (1 hint)
  • lib/languages/julia-repl.dart (1 hint)
  • lib/languages/leaf.dart (1 hint)
  • lib/languages/markdown.dart (1 hint)
  • lib/languages/mojolicious.dart (1 hint)
  • lib/languages/plaintext.dart (1 hint)
  • lib/languages/shell.dart (1 hint)
  • lib/languages/subunit.dart (1 hint)
  • lib/languages/taggerscript.dart (1 hint)
  • lib/languages/vbscript-html.dart (1 hint)
  • lib/languages/xquery.dart (1 hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
Dev dependencies
path ^1.6.0
pedantic ^1.7.0
test ^1.6.0