memspace / zefyr

Soft and gentle rich text editing for Flutter applications.
https://zefyr-editor.gitbook.io
2.22k stars 550 forks source link

How to get entered content as HTML format in iOS / Android app? #186

Open jazzbpn opened 5 years ago

jazzbpn commented 5 years ago

I am trying to get entered content as HTML format from this ZefyrField. If it is possible how?

  `return ZefyrTheme(
  data: theme,
  child: ZefyrField(
    height: 200.0,
    decoration: InputDecoration(labelText: 'Description'),
    controller: _controller,
    focusNode: _focusNode,
    autofocus: true,
    imageDelegate: CustomImageDelegate(),
    physics: ClampingScrollPhysics(),
  ),
);`

_controller.document.toJson() and _controller.document.toString() gives the content in json and string format. But what if want to get that entered content as HTML format?

virskor commented 5 years ago

🙋‍♂️I do need this. Thanks

silviocandido commented 5 years ago

I do need this too, Thanks.

nalbion commented 5 years ago

There's a PR #178 ...and a PR for the PR: https://github.com/Yom3n/zefyr/pull/1

sil-main-coo commented 5 years ago

I had this problem just now. I have found this package: markdown And code:

Delta _delta = _controller.document.toDelta();
String html = markdownToHtml(notusMarkdown.encode(_delta) .toString()); 
print(html);
virskor commented 5 years ago

@sil-main-coo Dose these methods works well? it will help me a lot if so. Thanks

sil-main-coo commented 5 years ago

@sil-main-coo Dose these methods works well? it will help me a lot if so. Thanks

It supports markdown conversion to html. For my project it is very good. Please read the documentation for reference. But if you require more complicated tags, find something else. You can also refer to @nalbion 's pull request above.

nalbion commented 5 years ago

If you want to use the HTML codec in my PR right now, add the following to your pubspec.yaml:

dependency_overrides:
  notus:
    git:
      url: git://github.com/nalbion/zefyr.git
      path: packages/notus

This is how I'm using my Markdown decoder:

_saveNotes() {
    final markdown = notusMarkdown.encode(_notesController.document.toDelta());
    // save the markdown string
  }

  NotusDocument _loadNotes() {
    // load a markdown string
    var markdown = null; // 'This is **Markdown**'

    if (markdown == null) {
      return NotusDocument();
    }

    return NotusDocument.fromDelta(notusMarkdown.decode(markdown));
  }
jazzbpn commented 5 years ago

I had this problem just now. I have found this package: markdown And code:

Delta _delta = _controller.document.toDelta();
String html = markdownToHtml(notusMarkdown.encode(_delta) .toString()); 
print(html);

How to use create notusMaskdown object? Please checkout the screenshot below.

Screen Shot 2019-10-25 at 10 38 50
sil-main-coo commented 5 years ago

I had this problem just now. I have found this package: markdown And code:

Delta _delta = _controller.document.toDelta();
String html = markdownToHtml(notusMarkdown.encode(_delta) .toString()); 
print(html);

How to use create notusMaskdown object? Please checkout the screenshot below.

Screen Shot 2019-10-25 at 10 38 50

Sorry. I wrote missing a package: Notus. And Delta Package if u need

nalbion commented 5 years ago

You need to add import 'package:notus/convert.dart'; and use the HTML codec instead of Markdown

jazzbpn commented 5 years ago

Awesome thanks!!.

Adamgortych commented 5 years ago

Does anyone know how to make it from the other way? How to display html inside zephyr? I'am trying to convert html to Notusdocument

clipsmm commented 4 years ago

You need to add import 'package:notus/convert.dart'; and use the HTML codec instead of Markdown

Do you have any examples?

tiwariritesh1700 commented 4 years ago

Anyone Has complete code for reference

azulmouad commented 3 years ago

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

Delta _delta = _controller.document.toDelta();

          String html = markdown
              .markdownToHtml(notusMarkdown.encode(_delta).toString());

          print(html);
singerdmx commented 3 years ago

What is package:markdown/markdown.dart? BTW, it is also possible to do it at server side. We found a Golang package to do it https://github.com/singerdmx/BulletJournal/commit/16fc1c2b82872a94a69880a711ed46377e9bb2d4