Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .fvm/flutter_sdk

This file was deleted.

4 changes: 0 additions & 4 deletions .fvm/fvm_config.json

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ migrate_working_dir/
**/doc/api/
.dart_tool/
.packages
build/
build/
10 changes: 10 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
.idea
.pub/
.dart_tool/
.settings/
build/
packages
.packages
pubspec.lock
package-lock.json
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 0.2.0

### Added
- pub.dev setup
- unit tests

### Changed
- Flutter sdk version to 3.24.0
- dependencies to newer
- Highlights library to 1.0.0
- `getHighlights` to `getHighlightsAsync` in plugins

## 0.1.0

### Added
- emphasis (bold) phrase parts
- bold option on selected text in example

## 0.0.1

### Added
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# highlights_plugin

Dart implementation of highlights KMM engine:
Dart implementation of highlights KMP engine:
https://github.com/SnipMeDev/Highlights

<img width="250" src="https://github.com/user-attachments/assets/e28639c1-e1a5-47d2-9a39-d1a3f2973651"/>
<img width="250" src="https://github.com/user-attachments/assets/2a0239b5-bacd-4173-9d8b-697ef37fba05"/>

## Installation
```sh
flutter pub add highlights_plugin
```

## Usage
```dart
final plugin = HighlightsPlugin(debug: true);

// ['kotlin', 'dart', 'swift', 'php', 'java', ...]
final languages = await plugin.getLanguages();
// ['monokai', 'darcula', 'notepad', ...]
final themes = await plugin.getThemes();
// Bold Hello
final emphasis = PhraseLocation(start: 3, length: 8);
// List with ColorHighlight or BoldHighlight
final result = await plugin.getHighlights(
'// Hello, World!',
languages.first,
themes.first,
[emphasis],
);
```

## Features
- 17 supported languages (Kotlin, Dart, Swift, PHP, etc)
- Light / dark mode
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group 'pl.tkadziolka.highlights_plugin'
group 'dev.snipme.highlights_plugin'
version '1.0-SNAPSHOT'

buildscript {
Expand Down Expand Up @@ -26,6 +26,7 @@ apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
namespace 'dev.snipme.highlights_plugin'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.tkadziolka.highlights_plugin">
</manifest>
<manifest package="dev.snipme.highlights_plugin" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.tkadziolka.highlights_plugin
package dev.snipme.highlights_plugin

import dev.snipme.highlights.DefaultHighlightsResultListener
import dev.snipme.highlights.Highlights
Expand All @@ -15,12 +15,7 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** HighlightsPlugin */
class HighlightsPlugin : FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel
private lateinit var highlights: Highlights
private var useDarkMode = false
Expand All @@ -35,8 +30,6 @@ class HighlightsPlugin : FlutterPlugin, MethodCallHandler {
channel.setMethodCallHandler(null)
}

// TODO Implement EventChannel

override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
"getHighlights" -> {
Expand All @@ -49,8 +42,8 @@ class HighlightsPlugin : FlutterPlugin, MethodCallHandler {

highlights.getHighlightsAsync(
object: DefaultHighlightsResultListener() {
override fun onComplete(highlightList: List<CodeHighlight>) {
result.success(highlightList.toJson())
override fun onSuccess(highlights: List<CodeHighlight>) {
result.success(highlights.toJson())
}

override fun onCancel() {
Expand Down Expand Up @@ -81,11 +74,7 @@ class HighlightsPlugin : FlutterPlugin, MethodCallHandler {
theme: SyntaxTheme?,
emphasisLocations: List<PhraseLocation>?,
) {
println("Update instance $code $language $theme $emphasisLocations")

if (highlights.getLanguage() == language && highlights.getTheme() == theme) {
println("Only change code $code")
println("Only change emphasis $emphasisLocations")
code?.let { highlights.setCode(it) }
emphasisLocations?.let { locations -> locations.forEach { highlights.setEmphasis(it) } }
} else {
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "pl.tkadziolka.highlights_plugin_example"
applicationId "dev.snipme.highlights_plugin_example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.tkadziolka.highlights_plugin_example">
package="dev.snipme.highlights_plugin_example">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.tkadziolka.highlights_plugin_example">
package="dev.snipme.highlights_plugin_example">
<application
android:label="highlights_plugin_example"
android:name="${applicationName}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.tkadziolka.highlights_plugin_example
package dev.snipme.highlights_plugin_example

import io.flutter.embedding.android.FlutterActivity

Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.tkadziolka.highlights_plugin_example">
package="dev.snipme.highlights_plugin_example">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/highlights_plugin/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
highlights_plugin: 83710af52e9ce2a08e2f251e9c2cdeda75a80909

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011

COCOAPODS: 1.13.0
23 changes: 16 additions & 7 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -342,7 +342,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -357,6 +357,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6AY68V2B3P;
ENABLE_BITCODE = NO;
Expand All @@ -365,8 +367,9 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.tkadziolka.highlightsPluginExample;
PRODUCT_BUNDLE_IDENTIFIER = dev.snipme.highlightsPluginExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -420,7 +423,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -469,7 +472,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -486,6 +489,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6AY68V2B3P;
ENABLE_BITCODE = NO;
Expand All @@ -494,8 +499,9 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.tkadziolka.highlightsPluginExample;
PRODUCT_BUNDLE_IDENTIFIER = dev.snipme.highlightsPluginExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -509,6 +515,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 6AY68V2B3P;
ENABLE_BITCODE = NO;
Expand All @@ -517,8 +525,9 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = pl.tkadziolka.highlightsPluginExample;
PRODUCT_BUNDLE_IDENTIFIER = dev.snipme.highlightsPluginExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
8 changes: 2 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:flutter/material.dart';
import 'package:highlights_plugin/highlights_plugin.dart';
import 'package:highlights_plugin/model/phrase_location.dart';

// TODO Test code
// TODO Add changelog
void main() {
runApp(const MyApp());
}
Expand Down Expand Up @@ -44,7 +42,6 @@ class _MyAppState extends State<MyApp> {
}

Future<void> _updateHighlights(String code) async {
print('Updating highlights $code');
_code = code;
_highlightsPlugin
.getHighlights(
Expand All @@ -54,7 +51,6 @@ class _MyAppState extends State<MyApp> {
_emphasis,
)
.then((value) {
print('Flutter Highlights $value');
setState(() {
value.sort((a, b) => a.location.start.compareTo(b.location.start));
_highlights = value.map((highlight) => highlight.toString()).toList();
Expand Down Expand Up @@ -206,8 +202,8 @@ class FutureDropdown<T> extends StatelessWidget {
required this.selected,
required this.future,
required this.onChanged,
Key? key,
}) : super(key: key);
super.key,
});

final T? selected;
final Future<List<T>> future;
Expand Down
2 changes: 1 addition & 1 deletion example/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "highlights_plugin_example")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "pl.tkadziolka.highlights_plugin")
set(APPLICATION_ID "dev.snipme.highlights_plugin")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
Expand Down
4 changes: 0 additions & 4 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

#include "generated_plugin_registrant.h"

#include <highlights_plugin/highlights_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) highlights_plugin_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "HighlightsPlugin");
highlights_plugin_register_with_registrar(highlights_plugin_registrar);
}
1 change: 0 additions & 1 deletion example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
highlights_plugin
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
Loading