Skip to content

Because only Chuck Norris can parse HTML with regular expressions

Notifications You must be signed in to change notification settings

Fantom-Factory/afHtmlParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTML Parser v0.2.8


Written in: Fantom pod: v0.2.8 Licence: ISC

Overview

HTML Parser is a support library that aids Alien-Factory in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.

A valiant effort to parse valid HTML5 documents into XML as defined by W3C HTML Syntax.

Html Parser currently recognises and supports:

Elements:

  • Normal elements: <div></div>
  • Void elements: <br>
  • Self closing elements: <foreignElement />
  • Raw text elements: <script> ... </script>
  • Escapable raw text elements: <textarea> ... </textarea>

Attributes:

  • Empty attributes: <input disabled>
  • Unquoted attributes: <input type=submit>
  • Single quoted attributes:
  • Double quoted attributes: <input type="submit">

Other:

  • XML declarations: <?xml version="1.0" ?>
  • DocTypes: <!DOCTYPE html >
  • Comments: <!-- comment -->
  • CData Sections: <![CDATA[ cdata ]]>
  • Numerical character references: &#160; and &#xA0;> Html Parser because only Chuck Norris can parse HTML with regular expressions.

Install

Install HTML Parser with the Fantom Pod Manager ( FPM ):

C:\> fpm install afHtmlParser

Or install HTML Parser with fanr:

C:\> fanr install -r http://eggbox.fantomfactory.org/fanr/ afHtmlParser

To use in a Fantom project, add a dependency to build.fan:

depends = ["sys 1.0", ..., "afHtmlParser 0.2"]

Documentation

Full API & fandocs are available on the Eggbox - the Fantom Pod Repository.

Quick Start

using afHtmlParser::HtmlParser

class Example {
    Void main() {
        elem := HtmlParser().parseDoc("<input disabled value=wotever>")

        echo(elem.writeToStr)   // --> <input disabled='disabled' value='wotever'/>
    }
}

Usage

1 class -> 1 method -> 1 argument -> 1 return value.

It's pretty self explanatory!

While Html Parser is more lenient than a validator it does NOT attempt to reconstruct documents from the tag soup of badly formatted HTML4 documents.

It's main purpose is to parse well formed HTML5 documents created with Slim into XML so they may be tested by Bounce and Sizzle.

Html Parser uses Pegger because HTML can not be parsed with regular expressions.

About

Because only Chuck Norris can parse HTML with regular expressions

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •