A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pub.dev/documentation/github/latest/browser_helper/../browser_helper/renderMarkdown.html below:

renderMarkdown function - browser_helper library

renderMarkdown function

Renders Markdown in HTML using the GitHub API

TODO: Remove the requirement of indent and auto-detect it.

github is the GitHub instance to use. selector is the selector to use to find markdown elements. indent is the indent that needs to be stripped out.

Implementation
void renderMarkdown(GitHub github, String selector, {int indent = 4}) {
  final elements = document.querySelectorAll(selector);

  elements.removeWhere((Element it) => it.attributes.containsKey('rendered'));

  for (final e in elements) {
    final txt = e.text!;

    final md = txt.split('\n').map((it) {
      return it.length >= indent ? it.substring(indent) : it;
    }).join('\n');

    github.misc.renderMarkdown(md).then((html) {
      e.hidden = false;
      e.setAttribute('rendered', '');
      e.classes.add('markdown-body');
      e.setInnerHtml(html, treeSanitizer: NodeTreeSanitizer.trusted);
    });
  }
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4