convert function

String convert(
  1. Object input, {
  2. String? rootTag,
  3. String? imageBaseUrl,
  4. Map<String, String>? styleOptions,
  5. List<String>? ignore,
  6. List<Rule>? rules,
})

Convert input to markdown text.

The input can be an html string or a dom.Node. The root tag which should be converted can be set with rootTag. The image base url can be set with imageBaseUrl. Style options can be set with styleOptions.

The default and available style options:

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

Elements list in ignore would be ingored.

The rules parameter can be used to customize element processing.

Implementation

String convert(
  Object input, {
  String? rootTag,
  String? imageBaseUrl,
  Map<String, String>? styleOptions,
  List<String>? ignore,
  List<Rule>? rules,
}) {
  if (imageBaseUrl != null && imageBaseUrl.isNotEmpty) {
    _customOptions['imageBaseUrl'] = imageBaseUrl;
  }
  updateStyleOptions(styleOptions);
  if (ignore != null && ignore.isNotEmpty) {
    Rule.addIgnore(ignore);
  }
  if (rules != null && rules.isNotEmpty) {
    Rule.addRules(rules);
  }
  final output = _process(Node.root(input, rootTag: rootTag));
  return _postProcess(output);
}