패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.5

vsc_quill_delta_to_html

강력한 Quill Delta에서 HTML로 변환하는 도구입니다. 이는 인기 있는 quill-delta-to-html Typescript/Javascript 패키지를 Dart로 완전히 이식한 것입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
12.4만
좋아요
50
Pub 점수
140

패키지 설치

flutter pub add vsc_quill_delta_to_html

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Quill Delta 형식을 깨끗한 HTML로 원활하게 변환할 수 있는 강력한 Dart 구현체인 quill-delta-to-html 컨버터입니다. 인기 있는 TypeScript/JavaScript 라이브러리에서 완전히 포팅된 것으로, Flutter 플랫폼 간에 풍부한 텍스트 콘텐츠를 일관되게 렌더링합니다. 에디터, 콘텐츠 관리 시스템 또는 출판 도구와 같이 서식 있는 텍스트 출력에 정밀한 제어가 필요한 애플리케이션에 적합합니다. 이 패키지는 Android, iOS, Web, macOS, Windows 및 Linux를 포함한 모든 주요 플랫폼을 지원합니다.

사용 사례

  • Quill 편집기 콘텐츠를 HTML로 변환하는 방법
  • 웹 뷰에서 리치 텍스트 렌더링
  • CMS 또는 게시 워크플로우와의 통합
  • 앱에서 사용자 입력으로부터 HTML 생성하기
  • 다중 플랫폼의 풍부한 텍스트 표시 지원

주요 기능

  • quill-delta-to-html의 완전한 포트
  • 모든 Quill Delta 작업을 지원합니다
  • 크로스 플랫폼 호환성
  • 깨끗하고 의미 있는 HTML 출력
  • Flutter 앱과의 간편한 통합

적합한 대상

  • Quill 편집기를 사용하는 플러터 앱
  • 콘텐츠 전달 시스템
  • 리치 텍스트 렌더링이 필요합니다
  • 웹 및 모바일 하이브리드 애플리케이션
  • JavaScript Quill에서 이전하는 개발자

고려 사항

  • Quill Delta 형식에 대한 이해가 필요합니다
  • HTML 출력을 위해 추가 스타일링이 필요할 수 있습니다
  • 실시간 협업에 적합하지 않습니다
  • 변환에 한정됨, 편집 불가
  • 표현을 위해 외부 CSS에 의존합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

VSC Quill Delta to HTML Converter

Converts Quill's Delta format to HTML (insert ops only) with properly nested lists. It has full support for Quill operations - including images, videos, formulas, tables, and mentions. Conversion can be performed in vanilla Dart (i.e., server-side or CLI) or in Flutter.

This is a complete port of the popular quill-delta-to-html Typescript/Javascript package to Dart.

This converter can convert to HTML for a number of purposes, not the least of which is for generating HTML-based emails. It makes a great pairing with Flutter Quill.

You can try a live demo of the conversion by running the example Flutter app.

Quickstart

To get started, add this package to your pubspec.yaml dependencies.

Usage

import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart';

void main() {
  final deltaOps = [
    {'insert': 'Hello\n'},
    {
      'insert': 'This is colorful',
      'attributes': {'color': '#f00'}
    }
  ];

  final converter = QuillDeltaToHtmlConverter(
    ops,
    ConverterOptions.forEmail(),
  );

  final html = converter.convert();
  print(html);
}

Configuration

QuillDeltaToHtmlConverter accepts a few configuration (ConverterOptions, OpConverterOptions, and OpAttributeSanitizerOptions) options as shown below:

Option Type Default Description
converterOptions.paragraphTag string 'p' Custom tag to wrap inline html elements
converterOptions.encodeHtml boolean true If true, <, >, /, ', ", & characters in content will be encoded.
converterOptions.classPrefix string 'ql' A css class name to prefix class generating styles such as size, font, etc.
converterOptions.inlineStylesFlag boolean false If true, use inline styles instead of classes.
converterOptions.inlineStyles InlineStyles null If non-null, use inline styles instead of classes. See Rendering Inline Styles section below for usage.
multiLineBlockquote boolean true Instead of rendering multiple blockquote elements for quotes that are consecutive and have same styles(align, indent, and direction), it renders them into only one
multiLineHeader boolean true Same deal as multiLineBlockquote for headers
multiLineCodeblock boolean true Same deal as multiLineBlockquote for code-blocks
multiLineParagraph boolean true Set to false to generate a new paragraph tag after each enter press (new line)
multiLineCustomBlock boolean true Same deal as multiLineBlockquote for custom blocks.
bulletListTag string 'ul' Tag for unordered bullet lists.
orderedListTag string 'ol' Tag for ordered/numbered lists.
converterOptions.linkRel string none generated Specifies a value to put on the rel attr on all links. This can be overridden by an individual link op by specifying the rel attribute in the respective op's attributes
converterOptions.linkTarget string '_blank' Specifies target for all links; use '' (empty string) to not generate target attribute. This can be overridden by an individual link op by specifiying the target with a value in the respective op's attributes.
converterOptions.allowBackgroundClasses boolean false If true, css classes will be added for background attr
sanitizerOptions.urlSanitizer String? Function(String url) null A function that is called once per url in the ops (image, video, link) for you to do custom sanitization. If your function returns a string, it is assumed that you sanitized the url and no further sanitization will be done by the library; when anything other than a string is returned (e.g. undefined), it is assumed that no sanitization has been done and the library's own function will be used to clean up the url
sanitizerOptions.allow8DigitHexColors boolean false If true, hex colors in #AARRGGBB format are allowed in the ops
converterOptions.customTag String? Function(String format, DeltaInsertOp op) null Callback allows to provide custom html tag for some format
converterOptions.customTagAttributes Map<String, String>? Function(DeltaInsertOp op) null Allows custom html tag attributes for the given op
converterOptions.customCssClasses List<String>? Function(DeltaInsertOp op) null Allows custom CSS classes for the given op
converterOptions.customCssStyles List<String>? Function(DeltaInsertOp op) null Allows custom CSS styles attributes for the given op

Rendering Quill Formats

You can customize the rendering of Quill formats by registering render callbacks before calling the convert() method.

There is a beforeRender and an afterRender callback. They are called multiple times before and after rendering each group. A group is one of:

  • continuous sets of inline elements
  • a video element
  • list elements
  • block elements (header, code-block, blockquote, align, indent, and direction)

beforeRender event is called with raw operation objects for you to generate and return your own html. If you return null, the system will return its own generated html.

afterRender event is called with generated html for you to inspect, maybe make some changes, and return your modified or original html.

converter.beforeRender = (GroupType groupType, TDataGroup data) {
    // ... generate your own html 
    // return your html
};

converter.afterRender = (GroupType groupType, String htmlString) {
    // modify if you wish
    // return the html
};

html = converter.convert();

Following shows the parameter formats for beforeRender event:

groupType data
video VideoItem
block BlockGroup
list ListGroup
inline-group InlineGroup

Rendering Inline Styles

If you are rendering to HTML that you intend to include in an email, using classes and a style sheet are not recommended, as not all browsers support style sheets. vsc_quill_delta_to_html supports rendering inline styles instead. The easiest way to enable this is to pass the option inlineStylesFlag: true.

You can customize styles by passing an object to inlineStyles instead:

inlineStyles: InlineStyles({
  'font': InlineStyleType(
      fn: (value, _) => defaultInlineFonts[value] ?? 'font-family:$value'),
  'size': InlineStyleType(map: {
    'small': 'font-size: 0.75em',
    'large': 'font-size: 1.5em',
    'huge': 'font-size: 2.5em',
  }),
  'indent': InlineStyleType(fn: (value, op) {
    final indentSize = (double.tryParse(value) ?? double.nan) * 3;
    final side = op.attributes['direction'] == 'rtl' ? 'right' : 'left';
    return 'padding-$side:${indentSize}em';
  }),
  'direction': InlineStyleType(fn: (value, op) {
    if (value == 'rtl') {
      final textAlign =
      isTruthy(op.attributes['align']) ? '' : '; text-align:inherit';
      return ('direction:rtl$textAlign');
    } else {
      return null;
    }
  }),
  'list': InlineStyleType(map: {
    'checked': "list-style-type:'\\2611';padding-left: 0.5em;",
    'unchecked': "list-style-type:'\\2610';padding-left: 0.5em;",
  }),
});

Keys to this object are the names of attributes from Quill. The values are either a simple lookup table (like in the list example above) used to map values to styles, or a fn(value, op) which returns a style string.

Rendering Custom Blot Formats

You need to tell system how to render your custom blot by registering a renderer callback function to renderCustomWith method before calling the convert() method.

If you would like your custom blot to be rendered as a block (not inside another block or grouped as part of inlines), then add renderAsBlock: true to its attributes.

Example:

final ops = [
    {insert: {'my-blot': {id: 2, text: 'xyz'}}, attributes: {renderAsBlock: true|false}}
];

let converter = new QuillDeltaToHtmlConverter(ops);

// customOp is your custom blot op
// contextOp is the block op that wraps this op, if any. 
// If, for example, your custom blot is located inside a list item,
// then contextOp would provide that op. 
converter.renderCustomWith = (DeltaInsertOp customOp, DeltaInsertOp? contextOp) {
    if (customOp.insert.type == 'my-blot') {
        return '<span>Some custom blot</span>';
    } else {
        return 'Unmanaged custom blot!';
    }
});

html = converter.convert();

customOp object will have the following format:

{
    insert: {
        type: string //whatever you specified as key for insert, in above example: 'my-blot'
        value: any // value for the custom blot  
    }, 
    attributes: {
        // ... any attributes custom blot may have
    }
}

Advanced Custom Rendering Using Grouped Ops

If you want to do the full rendering yourself, you can do so by getting the processed & grouped ops.

final groupedOps = converter.getGroupedOps();

Each element in groupedOps array will be an instance of the following types: InlineGroup, VideoItem, BlockGroup, ListGroup, ListItem, BlotBlock.

BlotBlock represents custom blots with renderAsBlock:true property pair in its attributes

카테고리

의존성

의존성 목록 3 개

소스 저장소

이 패키지를 사용하는 프로젝트