html2md 0.3.1

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>';
  print(html2md.convert(html));
}

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:

NameDefaultOptions
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.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

example/html2md_example.dart

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

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

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

<h2>Usage</h2>

<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;'));
}</code></pre>

<hr />

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

<ul>
  <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>
</ul>''';
  print(html2md.convert(html));
}

Use this package as a library

1. Depend on it

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


dependencies:
  html2md: ^0.3.1

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/utils.dart. (-1 points)

Analysis of lib/src/utils.dart reported 2 hints:

line 93 col 10: Use contains instead of indexOf

line 97 col 10: Use contains instead of indexOf

Fix lib/src/node.dart. (-0.50 points)

Analysis of lib/src/node.dart reported 1 hint:

line 87 col 12: Use contains instead of indexOf

Fix lib/src/rules.dart. (-0.50 points)

Analysis of lib/src/rules.dart reported 1 hint:

line 289 col 14: Use contains instead of indexOf

Format lib/src/converter.dart.

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

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (html).

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
html ^0.13.3 0.13.4+2 0.14.0+2
path ^1.4.1 1.6.2
Transitive dependencies
charcode 1.1.2
csslib 0.15.0 0.16.1
source_span 1.5.5
term_glyph 1.1.0
utf 0.9.0+5
Dev dependencies
test ^1.3.0

Admin