html2md 0.3.2

html2md #

Build status

Convert html to markdown in Dart. A simplify version of node's turndown.

Usage #

A simple usage example:

import 'package:html2md/html2md.dart' as html2md;

main() {
  var html = '<h1>HTML2MD Demo</h1>';

Config #

You can config convert style by passing styleOptions to convert, elements that should be ignored also can be set with ignore:

html2md.convert(html, styleOptions: { 'headingStyle': 'atx' }, ignore: ['script']);

The default and available style options:

headingStyle"setext""setext", "atx"
hr"* * *""* * *", "- - -", "_ _ _"
bulletListMarker"*""*", "-", "_"
codeBlockStyle"indented""indented", "fenced"
fence"```""```", "~~~"
emDelimiter"_""_", "*"
strongDelimiter"**""**", "__"
linkStyle"inlined""inlined", "referenced"
linkReferenceStyle"full""full", "collapsed", "shortcut"

Test #

pub run test

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

Created from templates made available by Stagehand under a BSD-style license.

Changelog #

0.3.2 #

  • Update analysis_options.yaml
  • Cleanup source code
  • Bump dependencies

0.3.1 #

  • fix fenced codeBlockStyle problem when codeblock has no className

0.3.0 #

  • Add ignore list

0.2.1 #

  • Fix dependency error

0.2.0 #

  • Fix the multiple child issue of indentedCodeBlock rule
  • Support Dart 2

0.1.7 #

  • Ignore invalid style options

0.1.6 #

  • Remove noscript element and cleanup
  • Fix pre node
  • Update test

0.1.5 #

  • Add named optional parameter 'styleOptions' to convert

0.1.4 #

  • Remove the incorrect default value for 'rootTag'

0.1.3 #

  • Fix for crash in Dart 2

0.1.2 #

  • Fix 'rootTag' issue

0.1.1 #

  • Add named optional parameter 'rootTag' to convert
  • Add named optional parameter 'imageBaseUrl' to convert

0.1.0 #

  • Cleanup
  • Publish 0.1.0

0.0.1 #

  • Initial version


import 'package:html2md/html2md.dart' as html2md;

main() {
  String html = '''<h1>HTML2MD Demo</h1>

<p>This demonstrates <a href="">html2md</a> – an HTML to Markdown converter in Dart.</p>


<pre><code class="language-dart">import 'package:html2md/html2md.dart' as html2md;
void main() {
  print(html2md.convert('&lt;h1&gt;Hello world&lt;/h1&gt;'));

<hr />

<p>It aims to be <a href="">CommonMark</a> compliant, and includes options to style the output. These options include:</p>

  <li>headingStyle (setext or atx)</li>
  <li>horizontalRule (*, -, or _)</li>
  <li>bullet (*, -, or +)</li>
  <li>codeBlockStyle (indented or fenced)</li>
  <li>fence (` or ~)</li>
  <li>emDelimiter (_ or *)</li>
  <li>strongDelimiter (** or __)</li>
  <li>linkStyle (inlined or referenced)</li>
  <li>linkReferenceStyle (full, collapsed, or shortcut)</li>

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  html2md: ^0.3.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:html2md/html2md.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:html2md/html2md.dart.

Health suggestions

Format lib/src/converter.dart.

Run dartfmt to format lib/src/converter.dart.

Format lib/src/utils.dart.

Run dartfmt to format lib/src/utils.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
html ^0.14.0+2 0.14.0+2
path ^1.6.4 1.6.4
Transitive dependencies
charcode 1.1.2
csslib 0.16.1
source_span 1.5.5
term_glyph 1.1.0
Dev dependencies
test ^1.3.0