feat: import Chinese-localized Buzz source snapshot
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Signed-off-by: cls_宁波本机 <908705107@qq.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:highlight/highlight.dart' show highlight, Node;
|
||||
|
||||
const highlightLightTheme = <String, TextStyle>{
|
||||
'keyword': TextStyle(color: Color(0xFFa626a4)),
|
||||
'built_in': TextStyle(color: Color(0xFF0184bc)),
|
||||
'type': TextStyle(color: Color(0xFF0184bc)),
|
||||
'literal': TextStyle(color: Color(0xFF0184bc)),
|
||||
'number': TextStyle(color: Color(0xFF986801)),
|
||||
'string': TextStyle(color: Color(0xFF50a14f)),
|
||||
'symbol': TextStyle(color: Color(0xFF50a14f)),
|
||||
'comment': TextStyle(color: Color(0xFFa0a1a7), fontStyle: FontStyle.italic),
|
||||
'doctag': TextStyle(color: Color(0xFFa0a1a7), fontStyle: FontStyle.italic),
|
||||
'meta': TextStyle(color: Color(0xFF986801)),
|
||||
'attr': TextStyle(color: Color(0xFF986801)),
|
||||
'attribute': TextStyle(color: Color(0xFF986801)),
|
||||
'title': TextStyle(color: Color(0xFF4078f2)),
|
||||
'title.class_': TextStyle(color: Color(0xFFc18401)),
|
||||
'title.function_': TextStyle(color: Color(0xFF4078f2)),
|
||||
'name': TextStyle(color: Color(0xFFe45649)),
|
||||
'tag': TextStyle(color: Color(0xFFe45649)),
|
||||
'selector-tag': TextStyle(color: Color(0xFFe45649)),
|
||||
'params': TextStyle(color: Color(0xFF383a42)),
|
||||
'variable': TextStyle(color: Color(0xFFe45649)),
|
||||
'subst': TextStyle(color: Color(0xFFe45649)),
|
||||
'section': TextStyle(color: Color(0xFF4078f2)),
|
||||
'bullet': TextStyle(color: Color(0xFF4078f2)),
|
||||
'link': TextStyle(color: Color(0xFF4078f2)),
|
||||
'addition': TextStyle(color: Color(0xFF50a14f)),
|
||||
'deletion': TextStyle(color: Color(0xFFe45649)),
|
||||
};
|
||||
|
||||
const highlightDarkTheme = <String, TextStyle>{
|
||||
'keyword': TextStyle(color: Color(0xFFc678dd)),
|
||||
'built_in': TextStyle(color: Color(0xFF56b6c2)),
|
||||
'type': TextStyle(color: Color(0xFF56b6c2)),
|
||||
'literal': TextStyle(color: Color(0xFF56b6c2)),
|
||||
'number': TextStyle(color: Color(0xFFd19a66)),
|
||||
'string': TextStyle(color: Color(0xFF98c379)),
|
||||
'symbol': TextStyle(color: Color(0xFF98c379)),
|
||||
'comment': TextStyle(color: Color(0xFF5c6370), fontStyle: FontStyle.italic),
|
||||
'doctag': TextStyle(color: Color(0xFF5c6370), fontStyle: FontStyle.italic),
|
||||
'meta': TextStyle(color: Color(0xFFd19a66)),
|
||||
'attr': TextStyle(color: Color(0xFFd19a66)),
|
||||
'attribute': TextStyle(color: Color(0xFFd19a66)),
|
||||
'title': TextStyle(color: Color(0xFF61afef)),
|
||||
'title.class_': TextStyle(color: Color(0xFFe5c07b)),
|
||||
'title.function_': TextStyle(color: Color(0xFF61afef)),
|
||||
'name': TextStyle(color: Color(0xFFe06c75)),
|
||||
'tag': TextStyle(color: Color(0xFFe06c75)),
|
||||
'selector-tag': TextStyle(color: Color(0xFFe06c75)),
|
||||
'params': TextStyle(color: Color(0xFFabb2bf)),
|
||||
'variable': TextStyle(color: Color(0xFFe06c75)),
|
||||
'subst': TextStyle(color: Color(0xFFe06c75)),
|
||||
'section': TextStyle(color: Color(0xFF61afef)),
|
||||
'bullet': TextStyle(color: Color(0xFF61afef)),
|
||||
'link': TextStyle(color: Color(0xFF61afef)),
|
||||
'addition': TextStyle(color: Color(0xFF98c379)),
|
||||
'deletion': TextStyle(color: Color(0xFFe06c75)),
|
||||
};
|
||||
|
||||
List<InlineSpan> highlightCode(
|
||||
String code,
|
||||
String language,
|
||||
Map<String, TextStyle> theme,
|
||||
TextStyle baseStyle,
|
||||
) {
|
||||
try {
|
||||
if (language.isEmpty) return [TextSpan(text: code, style: baseStyle)];
|
||||
final result = highlight.parse(code, language: language);
|
||||
if (result.nodes == null) return [TextSpan(text: code, style: baseStyle)];
|
||||
return buildSpans(result.nodes!, theme, baseStyle);
|
||||
} catch (_) {
|
||||
return [TextSpan(text: code, style: baseStyle)];
|
||||
}
|
||||
}
|
||||
|
||||
List<InlineSpan> buildSpans(
|
||||
List<Node> nodes,
|
||||
Map<String, TextStyle> theme,
|
||||
TextStyle baseStyle, {
|
||||
int maxDepth = 10,
|
||||
}) {
|
||||
final spans = <InlineSpan>[];
|
||||
for (final node in nodes) {
|
||||
if (maxDepth <= 0) {
|
||||
if (node.value != null) {
|
||||
spans.add(TextSpan(text: node.value, style: baseStyle));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (node.children != null && node.children!.isNotEmpty) {
|
||||
final childStyle = node.className != null
|
||||
? baseStyle.merge(theme[node.className])
|
||||
: baseStyle;
|
||||
spans.addAll(
|
||||
buildSpans(node.children!, theme, childStyle, maxDepth: maxDepth - 1),
|
||||
);
|
||||
} else if (node.value != null) {
|
||||
final style = node.className != null
|
||||
? baseStyle.merge(theme[node.className])
|
||||
: baseStyle;
|
||||
spans.add(TextSpan(text: node.value, style: style));
|
||||
}
|
||||
}
|
||||
return spans;
|
||||
}
|
||||
Reference in New Issue
Block a user