Skip to main content

module lang::html::IO

rascal-0.40.16

Provides read and write functionality for HTMLElements defined in AST.

Usage

import lang::html::IO;

Dependencies

extend lang::html::AST;
import Content;

data HTMLEscapeMode

data HTMLEscapeMode  
= baseMode()
| extendedMode()
| xhtmlMode()
;

data HTMLSyntax

data HTMLSyntax  
= htmlSyntax()
| xmlSyntax()
;

function readHTMLFile

Parse a HTML file and return an HTMLElement AST.

HTMLElement readHTMLFile(loc file, loc base=file, bool trackOrigins=false, bool includeEndTags=true)

This function uses JSoup's HTML parser which is robust against errors in the HTML, and complete in the sense that it supports all of HTML.

function readHTMLString

Parse a HTML string and return an HTMLElement AST.

HTMLElement readHTMLString(str content, loc base=|http://localhost|, bool trackOrigins=false, bool includeEndTags=true, loc src=|unknown:///|)

This function uses JSoup's HTML parser which is robust against errors in the HTML, and complete in the sense that it supports all of HTML.

function writeHTMLString

Pretty-print the HTMLElement AST to a string.

str writeHTMLString(HTMLElement dom, str charset="UTF-8", HTMLEscapeMode escapeMode = baseMode(), bool outline=false, bool prettyPrint=true, int indentAmount=4, int maxPaddingWidth=30, HTMLSyntax \syntax=htmlSyntax(), bool dropOrigins=true)

This function uses JSoup's DOM functionality to yield a syntactically correct (X)HTML string.

function writeHTMLFile

Pretty-print the HTMLElement AST to a string.

void writeHTMLFile(loc file, HTMLElement dom, str charset="UTF-8", HTMLEscapeMode escapeMode = baseMode(), bool outline=false, bool prettyPrint=true, int indentAmount=4, int maxPaddingWidth=30, HTMLSyntax \syntax=htmlSyntax(), bool dropOrigins=true)

This function uses JSoup's DOM functionality to yield a syntactically correct (X)HTML file.

function serve

Convenience function to visualize an HTMLElement tree in the browser.

Content serve(HTMLElement elem)