Indent attribute is consider block but may have null value

pull/162/head
Xin Yao 4 years ago
parent e4cf28d054
commit 4c5f72826c
  1. 32
      lib/models/documents/attribute.dart
  2. 3
      lib/models/documents/style.dart

@ -1,3 +1,5 @@
import 'dart:collection';
import 'package:quiver/core.dart';
enum AttributeScope {
@ -14,7 +16,7 @@ class Attribute<T> {
final AttributeScope scope;
final T value;
static final Map<String, Attribute> _registry = {
static final Map<String, Attribute> _registry = LinkedHashMap.of({
Attribute.bold.key: Attribute.bold,
Attribute.italic.key: Attribute.italic,
Attribute.underline.key: Attribute.underline,
@ -26,16 +28,16 @@ class Attribute<T> {
Attribute.background.key: Attribute.background,
Attribute.placeholder.key: Attribute.placeholder,
Attribute.header.key: Attribute.header,
Attribute.indent.key: Attribute.indent,
Attribute.align.key: Attribute.align,
Attribute.list.key: Attribute.list,
Attribute.codeBlock.key: Attribute.codeBlock,
Attribute.blockQuote.key: Attribute.blockQuote,
Attribute.indent.key: Attribute.indent,
Attribute.width.key: Attribute.width,
Attribute.height.key: Attribute.height,
Attribute.style.key: Attribute.style,
Attribute.token.key: Attribute.token,
};
});
static final BoldAttribute bold = BoldAttribute();
@ -88,22 +90,22 @@ class Attribute<T> {
Attribute.placeholder.key,
};
static final Set<String> blockKeys = {
static final Set<String> blockKeys = LinkedHashSet.of({
Attribute.header.key,
Attribute.indent.key,
Attribute.align.key,
Attribute.list.key,
Attribute.codeBlock.key,
Attribute.blockQuote.key,
};
Attribute.indent.key,
});
static final Set<String> blockKeysExceptHeader = {
static final Set<String> blockKeysExceptHeader = LinkedHashSet.of({
Attribute.list.key,
Attribute.indent.key,
Attribute.align.key,
Attribute.codeBlock.key,
Attribute.blockQuote.key,
};
Attribute.indent.key,
});
static Attribute<int?> get h1 => HeaderAttribute(level: 1);
@ -172,6 +174,18 @@ class Attribute<T> {
return attribute;
}
static int getRegistryOrder(Attribute attribute) {
var order = 0;
for (final attr in _registry.values) {
if (attr.key == attribute.key) {
break;
}
order++;
}
return order;
}
static Attribute clone(Attribute origin, dynamic value) {
return Attribute(origin.key, origin.scope, value);
}

@ -30,7 +30,8 @@ class Style {
Iterable<String> get keys => _attributes.keys;
Iterable<Attribute> get values => _attributes.values;
Iterable<Attribute> get values => _attributes.values.sorted(
(a, b) => Attribute.getRegistryOrder(a) - Attribute.getRegistryOrder(b));
Map<String, Attribute> get attributes => _attributes;

Loading…
Cancel
Save