PHP Class Falcon_Converter, Falcon

Mostra file Open project: rmccue/Falcon Class Usage Examples

Protected Properties

Property Type Description
$document DOMDocument This may be needed to export an element as HTML
$html string HTML fragment
$links array List of URLs in the document
$list_stack array -1 represents an unordered list, while all other integers represent the current index of the ordered list
$text string Textual representation of the HTML

Public Methods

Method Description
__construct ( string $html ) Constructor
convert ( ) : string Convert HTML into a textual representation
silence_errors ( integer $num, string $str ) No-op error handler for libxml

Protected Methods

Method Description
blockquote ( DOMElement $element ) : string Parse blockquote elements into a string
generate_links ( )
get_text ( DOMNode $node ) : string Convert a node to text
heading ( DOMElement $element ) : string Parse heading elements into a string
indent ( string $text ) : string Indent a section of text
parse_children ( DOMNode $list ) : string Parse a node's children
parse_element ( DOMElement $element ) : string Parse an element into text
preprocess ( string $html ) : string Preprocess HTML
table ( DOMElement $element ) : string Parse table elements into a string
table_row ( DOMElement $element ) : array Parse a table row element
table_section ( DOMElement $element ) : array Parse a table section element
wrap ( string $str ) : string Wrap a string to a certain number of characters

Method Details

__construct() public method

Constructor
public __construct ( string $html )
$html string HTML fragment to convert

blockquote() protected method

Parse blockquote elements into a string
protected blockquote ( DOMElement $element ) : string
$element DOMElement Blockquote element
return string Text representation

convert() public method

Convert HTML into a textual representation
public convert ( ) : string
return string Text representation

get_text() protected method

Handles the various types of DOM nodes
protected get_text ( DOMNode $node ) : string
$node DOMNode Node to convert
return string Text representation

heading() protected method

Handles H1-H6, with special handling for H1 and H2
protected heading ( DOMElement $element ) : string
$element DOMElement Heading element
return string Text representation

indent() protected method

Indent a section of text
protected indent ( string $text ) : string
$text string Text to indent
return string Indented text

parse_children() protected method

Parse a node's children
protected parse_children ( DOMNode $list ) : string
$list DOMNode Node to parse
return string Text representation of the node's children

parse_element() protected method

This is a huge glorified switch statement, which is the easiest way to handle giant numbers of elements like this. Some elements have their handlers split off into separate methods.
protected parse_element ( DOMElement $element ) : string
$element DOMElement Element to parse
return string Text representation of the element

preprocess() protected method

Sanitizes the HTML for use with DOMDocument, including giving it a DOCTYPE, which forces standards mode
protected preprocess ( string $html ) : string
$html string HTML fragment
return string Processed HTML document

silence_errors() public static method

No-op error handler for libxml
public static silence_errors ( integer $num, string $str )
$num integer Error type
$str string Error message

table() protected method

Parse table elements into a string
protected table ( DOMElement $element ) : string
$element DOMElement Table element
return string Text representation

table_row() protected method

Parse a table row element
protected table_row ( DOMElement $element ) : array
$element DOMElement TR element
return array Cells in the row

table_section() protected method

Parse a table section element
protected table_section ( DOMElement $element ) : array
$element DOMElement THEAD or TBODY element
return array Rows in the section

wrap() protected method

Has special handling for some text elements (blockquotes and tables)
protected wrap ( string $str ) : string
$str string Text to wrap
return string Word-wrapped text

Property Details

$document protected_oe property

This may be needed to export an element as HTML
protected DOMDocument $document
return DOMDocument

$html protected_oe property

HTML fragment
protected string $html
return string

$list_stack protected_oe property

-1 represents an unordered list, while all other integers represent the current index of the ordered list
protected array $list_stack
return array

$text protected_oe property

Textual representation of the HTML
protected string $text
return string