Overview

A library for Dart developers.

Simple tag-based document parser. It is not about HTML parsing. You can use whatever tags you want.

Available types of tags:

  • Self closing tags: <tag attributes/>
  • Block tags: <tag attributes> Body

Attributes types:

  • bool:
  • with value:

Methods

parse(String source) - parsing source string of tags into a list of Tag objects. html(List<Tag> tags) - converting a list of Tag objects into a correct HTML body.

Usage

A simple usage example:

import 'package:tagser/tagser.dart';

main() {
  var tagser = new Tagser();
  var source = '<line show/><hello> Hello bro </hello><br />';
  
  var tags =  tagser.parse(source);
  var html = tagser.html(tags);
  
  print(html); //prints: <line show="true"></line><hello> Hello bro </hello><br></br>
}

Notes

  • Tag names are case sensitive. Open and close tags in block tag declaration should have the same spelling. It can be changed by passing "ignoreCase": true as option to Tagser
  • Attribute names are case sensitive: attribute A and attribute a are not the same

Restrictions

  • All self closing tags should have slash before closing bracket. Using <br> tag without slash will cause an error.
  • No spaces allowed between open bracket and tag name: < tag /> - will cause an error
  • No spaces allowed between slash and close bracket : <tag / > - will cause an error
  • No spaces allowed in attribute declaration:
  • <tag A = 'value' /> - error
  • <tag A= 'value' /> - error
  • <tag A ='value' /> - error

Options

You can pass options to the Tagser constructor or set them with setOption() method.

Available options:

  • ignoreCase - enables or disables case ignoring of opening and closing tag; false by default

Libraries

tagser