Skip to content

Commit

Permalink
Merge pull request #1 from nalbion/html_converter
Browse files Browse the repository at this point in the history
Fixed Travis build for HTML Converter
  • Loading branch information
Yom3n authored Dec 18, 2019
2 parents 20728e8 + 1db03aa commit 493e28b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/notus/lib/convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export 'src/convert/markdown.dart';
/// Markdown codec for Notus documents.
const NotusMarkdownCodec notusMarkdown = NotusMarkdownCodec();

const NotusHTMLCodec notusHTML = const NotusHTMLCodec();
const NotusHTMLCodec notusHTML = NotusHTMLCodec();
12 changes: 6 additions & 6 deletions packages/notus/lib/src/convert/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ class _NotusHTMLEncoder extends Converter<Delta, String> {

@override
String convert(Delta input) {
final iterator = new DeltaIterator(input);
final buffer = new StringBuffer();
final lineBuffer = new StringBuffer();
final iterator = DeltaIterator(input);
final buffer = StringBuffer();
final lineBuffer = StringBuffer();
NotusAttribute<String> currentBlockStyle;
NotusStyle currentInlineStyle = new NotusStyle();
NotusStyle currentInlineStyle = NotusStyle();
List<String> currentBlockLines = [];

void _handleBlock(NotusAttribute<String> blockStyle) {
Expand Down Expand Up @@ -222,7 +222,7 @@ class _NotusHTMLEncoder extends Converter<Delta, String> {
}

String _writeLine(String text, NotusStyle style) {
StringBuffer buffer = new StringBuffer();
StringBuffer buffer = StringBuffer();
if (style.contains(NotusAttribute.heading)) {
_writeAttribute(buffer, style.get(NotusAttribute.heading));
}
Expand Down Expand Up @@ -284,7 +284,7 @@ class _NotusHTMLEncoder extends Converter<Delta, String> {
} else if (attribute.key == NotusAttribute.embed.key) {
_writeEmbedTag(buffer, attribute, close: close);
} else {
throw new ArgumentError('Cannot handle $attribute');
throw ArgumentError('Cannot handle $attribute');
}
}

Expand Down
44 changes: 19 additions & 25 deletions packages/notus/test/convert/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ void main() {
test('decode intersecting inline ', () {
final b = NotusAttribute.bold.toJson();
final i = NotusAttribute.italic.toJson();
final bi = new Map<String, dynamic>.from(b);
final bi = Map<String, dynamic>.from(b);
bi.addAll(i);
final delta = new Delta()
final delta = Delta()
..insert('This')
..insert('house', b)
..insert('is a', bi)
Expand All @@ -98,20 +98,20 @@ void main() {

test('decode a tag', () {
final l = NotusAttribute.link.fromString('http://foo.com');
final delta = new Delta()..insert('a tag', l.toJson())..insert("\n");
final delta = Delta()..insert('a tag', l.toJson())..insert("\n");
final html = '<a href="http://foo.com">a tag</a>\n';
final result = notusHTML.decode(html);
expect(result, delta);
});

test('decode br tag', () {
final delta = new Delta()..insert('\n')..insert("\n");
final delta = Delta()..insert('\n')..insert("\n");
final html = '<br>\n';
final result = notusHTML.decode(html);
expect(result, delta);
});
test('decode nested br tag ', () {
final delta = new Delta()..insert('<b>a<br></b>')..insert("\n");
final delta = Delta()..insert('<b>a<br></b>')..insert("\n");
final html = '<b>a<br></b>\n';
final result = notusHTML.decode(html);
expect(result, delta);
Expand Down Expand Up @@ -169,9 +169,7 @@ void main() {
});
test('decode heading styles', () {
runFor(NotusAttribute<int> attribute, String source, String html) {
final delta = new Delta()
..insert(source)
..insert('\n', attribute.toJson());
final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
final result = notusHTML.decode(html);
expect(result, delta);
}
Expand All @@ -184,7 +182,7 @@ void main() {
test('decode heading styles with container attribute', () {
runFor(NotusAttribute<int> attribute, String source, String html) {
final attr = attribute.toJson();
final delta = new Delta()..insert(source)..insert('\n', attr);
final delta = Delta()..insert(source)..insert('\n', attr);
final result = notusHTML.decode(html);
expect(result.toString(), delta.toString());
}
Expand Down Expand Up @@ -220,9 +218,7 @@ void main() {

test('decode singe block', () {
runFor(NotusAttribute<String> attribute, String source, String html) {
final delta = new Delta()
..insert(source)
..insert('\n', attribute.toJson());
final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
final result = notusHTML.decode(html);
expect(result, delta);
}
Expand Down Expand Up @@ -290,9 +286,9 @@ void main() {
test('decode complex intersecting inline ', () {
final b = NotusAttribute.bold.toJson();
final i = NotusAttribute.italic.toJson();
final bi = new Map<String, dynamic>.from(b);
final bia = new Map<String, dynamic>.from(b);
final biaimage = new Map<String, dynamic>.from(b);
final bi = Map<String, dynamic>.from(b);
final bia = Map<String, dynamic>.from(b);
final biaimage = Map<String, dynamic>.from(b);
final l = NotusAttribute.link.fromString('https://github.com').toJson();
bi.addAll(i);
bia.addAll(i);
Expand Down Expand Up @@ -381,7 +377,7 @@ void main() {

test('encode bold italic', () {
runFor(NotusAttribute<bool> attribute, String expected) {
final delta = new Delta()
final delta = Delta()
..insert('This ')
..insert('house', attribute.toJson())
..insert(' is a ')
Expand All @@ -399,10 +395,10 @@ void main() {
test('encode intersecting inline styles', () {
final b = NotusAttribute.bold.toJson();
final i = NotusAttribute.italic.toJson();
final bi = new Map<String, dynamic>.from(b);
final bi = Map<String, dynamic>.from(b);
bi.addAll(i);

final delta = new Delta()
final delta = Delta()
..insert('This ')
..insert('house', b)
..insert(' is a ', bi)
Expand Down Expand Up @@ -480,7 +476,7 @@ void main() {
test('encode normalize inline styles', () {
final b = NotusAttribute.bold.toJson();
final i = NotusAttribute.italic.toJson();
final delta = new Delta()
final delta = Delta()
..insert('This')
..insert(' house ', b)
..insert('is a')
Expand All @@ -494,7 +490,7 @@ void main() {
test('encode links', () {
final b = NotusAttribute.bold.toJson();
final link = NotusAttribute.link.fromString('https://github.com');
final delta = new Delta()
final delta = Delta()
..insert('This')
..insert(' house ', b)
..insert('is a')
Expand All @@ -508,9 +504,7 @@ void main() {

test('encode heading styles', () {
runFor(NotusAttribute<int> attribute, String source, String expected) {
final delta = new Delta()
..insert(source)
..insert('\n', attribute.toJson());
final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
final result = notusHTML.encode(delta);
expect(result, expected);
}
Expand All @@ -522,7 +516,7 @@ void main() {
test('encode heading styles', () {
runFor(NotusAttribute<int> attribute, String source, String expected) {
final attr = attribute.toJson();
final delta = new Delta()..insert(source)..insert('\n', attr);
final delta = Delta()..insert(source)..insert('\n', attr);
final result = notusHTML.encode(delta);
expect(result, expected);
}
Expand Down Expand Up @@ -630,7 +624,7 @@ void main() {
});
test('encode multiline blocks', () {
runFor(NotusAttribute<String> attribute, String source, String expected) {
final delta = new Delta()
final delta = Delta()
..insert(source)
..insert('\n', attribute.toJson())
..insert(source)
Expand Down

0 comments on commit 493e28b

Please sign in to comment.