Skip to content

Html converter #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions packages/notus/example/main.dart
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:notus/convert.dart';
import 'package:notus/notus.dart';

void main() {
@@ -21,6 +22,9 @@ void main() {
print(change);
});

final a = NotusHTMLCodec().encode(doc.toDelta());
print(a);

// Dispose resources allocated by this document, e.g. closes "changes" stream.
// After document is closed it cannot be modified.
doc.close();
4 changes: 4 additions & 0 deletions packages/notus/lib/convert.dart
Original file line number Diff line number Diff line change
@@ -5,9 +5,13 @@
/// Provides codecs to convert Notus documents to other formats.
library notus.convert;

import 'src/convert/html.dart';
import 'src/convert/markdown.dart';

export 'src/convert/html.dart';
export 'src/convert/markdown.dart';

/// Markdown codec for Notus documents.
const NotusMarkdownCodec notusMarkdown = NotusMarkdownCodec();

const NotusHTMLCodec notusHTML = NotusHTMLCodec();
734 changes: 734 additions & 0 deletions packages/notus/lib/src/convert/html.dart

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/notus/lib/src/document/attributes.dart
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ abstract class NotusAttributeBuilder<T> implements NotusAttributeKey<T> {

final String key;
final NotusAttributeScope scope;

NotusAttribute<T> get unset => NotusAttribute<T>._(key, scope, null);
NotusAttribute<T> withValue(T value) =>
NotusAttribute<T>._(key, scope, value);
@@ -333,6 +334,7 @@ class _ItalicAttribute extends NotusAttribute<bool> {
/// [NotusAttribute.link] instead.
class LinkAttributeBuilder extends NotusAttributeBuilder<String> {
static const _kLink = 'a';

const LinkAttributeBuilder._() : super._(_kLink, NotusAttributeScope.inline);

/// Creates a link attribute with specified link [value].
@@ -346,6 +348,7 @@ class LinkAttributeBuilder extends NotusAttributeBuilder<String> {
/// [NotusAttribute.heading] instead.
class HeadingAttributeBuilder extends NotusAttributeBuilder<int> {
static const _kHeading = 'heading';

const HeadingAttributeBuilder._()
: super._(_kHeading, NotusAttributeScope.line);

@@ -365,6 +368,7 @@ class HeadingAttributeBuilder extends NotusAttributeBuilder<int> {
/// [NotusAttribute.block] instead.
class BlockAttributeBuilder extends NotusAttributeBuilder<String> {
static const _kBlock = 'block';

const BlockAttributeBuilder._() : super._(_kBlock, NotusAttributeScope.line);

/// Formats a block of lines as a bullet list.
668 changes: 668 additions & 0 deletions packages/notus/test/convert/html_test.dart

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/zefyr/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ dependencies:
zefyr:
path: ../

dependency_overrides:
notus:
path: ../../notus
#dependency_overrides:
# notus:
# path: ../../notus

dev_dependencies:
flutter_test:
6 changes: 3 additions & 3 deletions packages/zefyr/lib/src/widgets/controller.dart
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ class ZefyrController extends ChangeNotifier {
/// and that has not been applied yet.
/// It gets reseted after each format action within the [document].
NotusStyle get toggledStyles => _toggledStyles;
NotusStyle _toggledStyles = new NotusStyle();
NotusStyle _toggledStyles = NotusStyle();

/// Updates selection with specified [value].
///
@@ -127,15 +127,15 @@ class ZefyrController extends ChangeNotifier {
delta.length == 2 &&
delta[1].isInsert) {
// Apply it.
Delta retainDelta = new Delta()
Delta retainDelta = Delta()
..retain(index)
..retain(1, toggledStyles.toJson());
document.compose(retainDelta, ChangeSource.local);
}
}

// Always reset it after any user action, even if it has not been applied.
_toggledStyles = new NotusStyle();
_toggledStyles = NotusStyle();

if (selection != null) {
if (delta == null) {
2 changes: 1 addition & 1 deletion packages/zefyr/lib/src/widgets/toolbar.dart
Original file line number Diff line number Diff line change
@@ -259,7 +259,7 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
buildButton(context, ZefyrToolbarAction.quote),
buildButton(context, ZefyrToolbarAction.code),
buildButton(context, ZefyrToolbarAction.horizontalRule),
if (editor.imageDelegate != null) ImageButton(),
editor.imageDelegate != null ? ImageButton() : Container(),
];
return buttons;
}
4 changes: 2 additions & 2 deletions packages/zefyr/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@ author: Anatoly Pulyaevskiy <anatoly.pulyaevskiy@gmail.com>
homepage: https://github.com/memspace/zefyr

environment:
sdk: '>=2.2.2 <3.0.0'
sdk: '>=2.1.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
collection: ^1.14.6
url_launcher: ^5.0.0
quill_delta: ^1.0.0-dev.1.0
notus: ^0.1.0
notus: ^0.1.4
meta: ^1.1.0
quiver_hashcode: ^2.0.0

6 changes: 3 additions & 3 deletions packages/zefyr/test/widgets/controller_test.dart
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ void main() {

expect(
controller.document.toDelta(),
new Delta()
Delta()
..insert('Won')
..insert('B', NotusAttribute.bold.toJson())
..insert('rds')
@@ -129,7 +129,7 @@ void main() {
expect(notified, isTrue);
expect(
controller.document.toDelta(),
new Delta()
Delta()
..insert('W')
..insert('B', NotusAttribute.bold.toJson())
..insert('uords')
@@ -163,7 +163,7 @@ void main() {
});

test('getSelectionStyle with toggled style', () {
var selection = new TextSelection.collapsed(offset: 3);
var selection = TextSelection.collapsed(offset: 3);
controller.replaceText(0, 0, 'Words', selection: selection);
controller.formatText(3, 0, NotusAttribute.bold);