HTML 콘텐츠를 마크다운 형식으로 변환하는 플러터/다트 패키지로, CommonMark 표준, 기본 테이블 렌더링 및 사용자 정의 변환 규칙을 지원합니다. 콘텐츠 에디터, 문서 도구, 블로그 플랫폼 등과 같이 풍부한 HTML 텍스트를 깔끔하고 읽기 쉬운 마크다운으로 변환해야 하는 애플리케이션에 적합합니다. 이 라이브러리는 Android, iOS, 웹, macOS, Windows, Linux 등 모든 주요 플랫폼에서 호환되며, 크로스플랫폼 개발에 매우 유연합니다. 확장성 덕분에 특정 사용 사례에 맞는 사용자 정의 파싱 로직을 정의할 수 있습니다.
import'package:html2md/html2md.dart'as html2md;
import'package:flutter_markdown/flutter_markdown.dart';
build(BuildContext context) {
// Caution!// This is not best practice, you should not call convert in build// and the converted markdown should put in state.var html = '<h1>HTML2MD Demo</h1>';
var markdown = html2md.convert(html);
returnMarkdown(data: markdown);
}
Config
You can config convert style by passing styleOptions to convert, elements that should be ignored also can be set with ignore. If you want to customize element converting, use custom rules!
Want to customize element converting? Write your rules!
Rule fields explaination
finalString name; // unique rule namefinalList<String>? filters; // simple element name filters, e.g. ['aside']finalFilterFn? filterFn; // function for building complex element filter logicfinalReplacement? replacement; // function for doing the replacingfinalAppend? append; // function for appending content
Rule example - Convert the onebox section of discourse post to a link