Giter VIP home page Giter VIP logo

markdown_quill's Introduction

Markdown Quill

build workflow codecov pub package

๐Ÿ˜ป Contributions are always welcomed โค๏ธ

Provides converters to convert from markdown to quill (Delta) format and vice versa.

Usage

Simple

import 'package:markdown/markdown.dart' as md;
import 'package:markdown_quill/markdown_quill.dart';

// Configure the markdown parser
final mdDocument = md.Document(encodeHtml: false);

final mdToDelta = MarkdownToDelta(markdownDocument: mdDocument);

final deltaToMd = DeltaToMarkdown();

const markdown = '''
# Test
Hello
> Testing

This is an `inline code`

and this is 
``
code block
``
''';

final delta = mdToDelta.convert(markdown);

final markdownAgain = deltaToMd.convert(delta);

Customized

import 'package:flutter_quill/flutter_quill.dart';
import 'package:markdown/markdown.dart' as md;
import 'package:markdown_quill/markdown_quill.dart';

// Configure the markdown parser
final mdDocument = md.Document(
  encodeHtml: false,
  extensionSet: md.ExtensionSet.gitHubFlavored,

  // you can add custom syntax.
  blockSyntaxes: [const EmbeddableTableSyntax()],
);

final mdToDelta = MarkdownToDelta(
  markdownDocument: mdDocument,

  // you can add custom attributes based on tags
  customElementToBlockAttribute: {
    'h4': (element) => [HeaderAttribute(level: 4)],
  },
  // custom embed
  customElementToEmbeddable: {
    EmbeddableTable.tableType: EmbeddableTable.fromMdSyntax,
  },
);

final deltaToMd = DeltaToMarkdown(
    customEmbedHandlers: {
      EmbeddableTable.tableType: EmbeddableTable.toMdSyntax,
    },
);



const markdown = '''
Hi, this is a test of markdown_quill.

| Syntax      | Description | Test Text     |
| :---        |    :----:   |          ---: |
| Header      | Title       | Here's this   |
| Paragraph   | Text        | And more      |

# H1
ok
# H2
# H3
done
# H4
''';


final delta = mdToDelta.convert(markdown);

final markdownAgain = deltaToMd.convert(delta);

Limitation

Image

Currently this convertor doesn't support image alts, only image src will be retained

Block attributes exclusivity

flutter_quill block attributes have restrictions on how they can be combined.

These block attributes are exclusive and cannot be combined:

  • Header
  • List
  • Code Block
  • Block Quote

if the input markdown is:

> # Foo
> bar
> baz

it will be treated as

> Foo
> bar
> baz

TODO

  • Improve the output of DeltaToMarkdown

markdown_quill's People

Contributors

abaddon-88 avatar allenxuxu avatar tarekkma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.