Giter Site home page Giter Site logo

git-touch / highlight.dart Goto Github PK

View Code? Open in Web Editor NEW
223.0 223.0 79.0 13.54 MB

Syntax highlighting for Dart and Flutter

Home Page: https://git-touch.github.io/highlight/

License: MIT License

Dart 91.28% JavaScript 5.94% HTML 0.28% Kotlin 0.18% Swift 0.20% Objective-C 0.02% Ruby 2.11%
dart flutter syntax-highlighting

highlight.dart's Introduction

GitTouch

An open-source app for GitHub, GitLab, Bitbucket, Gitea and Gitee(码云), built with Flutter

Download on the App Store Get it on Google Play Get it on F-Droid

Installation

Click badges above to install it from Apple App Store or Google Play.

Android users can also download APK file from release page and install it manually.

Screenshots

Dark screenshotLight screenshot

Supported platforms

#29

✅: Done
🚧: Working in progress
💬: In review

Platform Public service API documentation Status Custom domain
GitHub https://github.com v3(RESTful), v4(GraphQL) 💬
GitLab https://gitlab.com GitLab API v4
BitBucket https://bitbucket.org BitBucket API
Gogs https://try.gogs.io/ Gogs API 🚧
Gitea https://gitea.com/ Gitea API
Gitee https://gitee.com/ Gitee API 💬

Contributing

See CONTRIBUTING.md.

Contributors

License

Apache-2.0 License

highlight.dart's People

Contributors

creativecreatorormaybenot avatar pd4d10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

highlight.dart's Issues

Migrate example to AndroidX

PS C:\Users\tusha\code\flutter\highlight\flutter_highlight\example> flutter run
Launching lib\main.dart on ONEPLUS A5000 in debug mode...
[!] Your app isn't using AndroidX.
    To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY

Syntax highlight not works with unenclosed strings.

Hi, I am trying to implement javascript syntax highlight for TextField with a custom TextEditingController here.

I noticed that the library does not work if there are any unenclosed strings except the last line.

For example, It does not work in:
image

and works in:
image

It leads to an unpleasant result when typing:
GIF 2020-8-2 11-22-25

Could you help me look into this? Thank you!

File Missing

example_map.dart is missing from flutter_highlight_gallery/lib/generated

Number sign (#) breaks java highlighting

For this input:

class MyClass {
}

we get the correct result:

image

Add a number sign:

class MyClass {
}#

and nothing is parsed:

image

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

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

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

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

  const textNumber = '''
class MyClass {
}#
''';
  final resultNumber = highlight.parse(textNumber, language: 'java');
  print(resultNumber.nodes);
}
Output
[Instance of 'Node', Instance of 'Node', Instance of 'Node']
[Instance of 'Node']

List<String> will be trimed in <pre>

Hi,

I had a same Java code wrapped with <pre> tag, like this:

List<Integer> arr = new List<Integer>;

when I display it in flutter with highlight, it will be trimed to:

List arr = new List;

Is there a method to resovle it?
Thanks!

Support Text copy

  • flutter_highlight.dart

Change RichText to SelectableText.rich

@override
  Widget build(BuildContext context) {
   /// ....
    return Container(
      color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor,
      padding: padding,
      child: SelectableText.rich(
        TextSpan(
          style: _textStyle,
          children:
              _convert(highlight.parse(source, language: language).nodes!),
        ),
      ),
    );
  }

Automate porting from JavaScript

I understand that this is a port from https://highlightjs.org

I guess the port was automated to some extent, because language files contain the comment:

// GENERATED CODE - DO NOT MODIFY BY HAND

This package now has quite a number of bugs that are not reproducible with the original Highlight.js, like

Also I can see no progress on older issues.

Can you please share the process of this porting so anyone can fast-forward the changes in Highlight.js? These then can be contributed here or implemented in a fork. This would solve most of the problems.

Or share any hints if the port was manual.

@pd4d10 @shreyas1599

Maintenance status?

What is the current maintenance status of this project? There are many PRs pending, some of them being easy-merges. Tagging author: @pd4d10. Maybe it is time to find new maintainers?

Code issue

I think you could replace this

final _languages = {}.cast<String, Mode>()

with this

final _languages = <String, Mode>{};

Multiline string literal breaks java highlighting

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']

http, ini, pgsql language broken

I found that the syntax I needed was not highlighted in any way. I decided to check the rest of the languages and found more recognition errors.

line by line parsing (simple change)

Please add line by line parsing ... Below is currently my workaround (I saved the latest continuation and pass it back on the next line parse). The block comments work correctly. But I'm not sure if this is the right way to do this.

index fdab3dc..6cf7c6e 100644
--- a/highlight/lib/src/highlight.dart
+++ b/highlight/lib/src/highlight.dart
@@ -251,7 +251,9 @@ class Highlight {
   /// [autoDetect]: The default value is `false`. Pass `true` to enable language auto detection.
   /// Notice that **this may cause performance issue** because it will try to parse source with
   /// all registered languages and use the most relevant one.
-  Result parse(String source, {String? language, bool autoDetection = false}) {
+  
+  Mode? lastContinuation;
+  Result parse(String source, {String? language, bool autoDetection = false, Mode? continuation}) {
     if (language == null) {
       if (autoDetection) {
         return _parseAuto(source);
@@ -259,7 +261,7 @@ class Highlight {
         throw ArgumentError.notNull('language');
       }
     }
-    return _parse(source, language: language);
+    return _parse(source, language: language, continuation: continuation);
   }
 
   Result _parse(
@@ -369,6 +371,7 @@ class Highlight {
       if (explicit) {
         continuations[top!.subLanguage!.first] = result.top;
       }
+
       return _buildSpan(result.language, result.nodes, noPrefix: true);
     }
 
@@ -378,6 +381,7 @@ class Highlight {
               ? _processSubLanguage()!
               : _processKeywords(),
           currentChildren);
+      lastContinuation = top;
       mode_buffer = '';
     }
 
@@ -404,6 +408,7 @@ class Highlight {
           }
         }
         _startNewMode(new_mode);
+
         return new_mode.returnBegin == true ? 0 : lexeme.length;
       }
 

FormatException: when `language` is null and `autoDetection` is true

source code sample

import 'package:markdown_widget/config/highlight_themes.dart' as theme;

  Widget buildMarkdown() => MarkdownWidget(
        data: data,
        styleConfig: StyleConfig(
          preConfig: PreConfig(
            language: 'java',
            theme: theme.a11yLightTheme
          )
        ),
      );

usage

_convert(hi.highlight.parse(source, language: null, autoDetection: true)

error log

flutter: FormatException: Invalid number (at character 1)

^
flutter: FormatException: Invalid radix-10 number (at character 1)
=
^

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.3 19D76, locale zh-Hans-CN)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.43.1)
[✓] Connected device (1 available)

Add GDScript as language

I wanted to add Godots GDScript to the supported languages. For testing purposes I just copied the python implementation and replaced some keywords and it seems to work fine enough.

As the language files have stated // GENERATED CODE - DO NOT MODIFY BY HAND at the top I came to thinking that those language files are generated somehow. As I couldn't find documenation in how to generate another language I stopped work there.

Are those files somehow generated by converting the available languages from highlight.js? If so there is the 3rd party package highlightjs-gdscript which could be used.

If this is not the way to go then how to add languages to highlight.dart?

Double quotes (") are not escaped

As far as I understand, double quotes (") should be escaped with &quot; in the generated HTML.
<, > and & are correctly escaped.

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
}

Actual output is:

<span class="hljs-built_in">print</span>(<span class="hljs-string">"Hello &lt;&gt; World!"</span>);

Expected output is:

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Hello &lt;&gt; World!&quot;</span>);

NNBD migration

Are there any plans to migrate these packages to non-nullable-by-default?

Using highlighting in Orgro

Hi,

Is it possible to use different code files in Orgro for better viewing?

Where can elaborate steps be seen?

Thanks
Nehal

We forked this package and have fixed many bugs

This project seems abandoned, so we forked it and did the following:

The new package is published as:

  1. https://pub.dev/packages/highlighting
  2. https://pub.dev/packages/flutter_highlighting

We intend to maintain our fork.
See the migration guide: https://github.com/akvelon/dart-highlighting/blob/main/doc/migrating.md

(Posting this here as there seems to be no other way to inform the users of the package who are in need of changes.)

Missing highlights

I'm not sure if it's missing highlights for the Dart language or in general. On the line var foo = Foo();, I would expect Foo to be highlighted.

Screenshot 2023-04-04 at 16 56 35

As well as variable invocation
Screenshot 2023-04-04 at 17 44 47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.