PHP Class Markdownify\Converter

Afficher le fichier Open project: pixel418/markdownify Class Usage Examples

Protected Properties

Свойство Type Description
$allowMixedChildren array html block tags that allow inline & block children
$bodyWidth integer wrap output, set to 0 to skip wrapping
$buffer array stores current buffers
$drop array html tags to be dropped (contents will not be parsed!)
$escapeInText array list of chars which have to be escaped in normal text
$footnotes array stores current buffers
$ignore array html tags to be ignored (contents will be parsed)
$indent string current indentation
$isMarkdownable array tags with elements which can be handled by markdown
$keepHTML boolean keep html tags which cannot be converted to markdown
$lastClosedTag string name of last closed tag
$lastWasBlockTag boolean wether last processed node was a block tag or not
$lineBreaks number of line breaks before next inline output
$linkPosition integer position where the link reference will be displayed
$minBodyWidth integer minimum body width
$notConverted array stack with tags which where not converted to html
$output string markdown output
$parser parseHTML html parser object
$skipConversion boolean skip conversion to markdown
$stack array node stack, e.g. for and tags
$wrappableIndents array Markdown indents which could be wrapped

Méthodes publiques

Méthode Description
__construct ( integer $linkPosition = self::LINK_AFTER_CONTENT, integer $bodyWidth = MDFY_BODYWIDTH, boolean $keepHTML = MDFY_KEEPHTML ) : void constructor, set options, setup parser
parseString ( string $html ) : string parse a HTML string
setKeepHTML ( $keepHTML ) : void set keep HTML tags which cannot be converted to markdown
setLinkPosition ( integer $linkPosition ) : void set the position where the link reference will be displayed

Méthodes protégées

Méthode Description
_decode_hex ( array $matches ) : string callback for decode() which converts a hexadecimal entity to UTF-8
_decode_numeric ( array $matches ) : string callback for decode() which converts a numerical entity to UTF-8
buffer ( ) : void buffer next parser output until unbuffer() is called
decode ( $text, $quote_style = ENT_QUOTES ) decode email addresses
fixBlockElementSpacing ( ) Trims whitespace in block-level elements, on the left side.
fixInlineElementSpacing ( ) Moves leading/trailing whitespace from inline elements outside of the element. This is to fix cases like Text, which if converted to ** strong** would be incorrect Markdown.
flushFootnotes ( ) : void output footnotes
flushLinebreaks ( ) : void flush enqued linebreaks
getLinkReference ( array $tag ) : string return formated link reference
getStacked ( string $tagName ) : array get last stacked element of type $tagName
handleHeader ( integer $level ) : void handle header tags (

-

)
handleTagToText ( ) : void handle non Markdownable tags
handleTag_a ( ) : void handle tags
handleTag_a_converter ( array $tag, string $buffer ) : string handle tags conversion
handleTag_a_parser ( ) : void handle tags parsing
handleTag_b ( )
handleTag_blockquote ( ) : void handle
tags
handleTag_br ( ) : void handle
tags
handleTag_code ( ) : void handle tags
handleTag_em ( ) : void handle and tags
handleTag_h1 ( ) : void handle

tags

handleTag_h2 ( ) : void handle

tags

handleTag_h3 ( ) : void handle

tags

handleTag_h4 ( ) : void handle

tags

handleTag_h5 ( ) : void handle
tags
handleTag_h6 ( ) : void handle
tags
handleTag_hr ( ) : void handle
tags
handleTag_i ( )
handleTag_img ( ) : void handle tags
handleTag_li ( ) : void handle
  • tags
  • handleTag_ol ( ) : void handle
      tags
    handleTag_p ( ) : void handle

    tags

    handleTag_pre ( ) : void handle
     tags    
    handleTag_strong ( ) : void handle and tags
    handleTag_ul ( ) : void handle
      tags
    handleText ( ) : void handle plain text
    hasParent ( string $tagName ) : boolean check if current node has a $tagName as parent (somewhere, not only the direct parent)
    indent ( string $str, boolean $output = true ) : void indent next output (start tag) or unindent (end tag)
    isMarkdownable ( ) : boolean check if current tag can be converted to Markdown
    out ( string $put, boolean $nowrap = false ) : void append string to the correct var, either directly to $this->output or to the current buffers
    parent ( ) : string get tagName of direct parent tag
    parse ( ) : void iterate through the nodes and decide what we shall do with the current node
    resetState ( ) Resetting the state forces the instance to behave as a fresh instance.
    setLineBreaks ( integer $number ) : void set number of line breaks before next start tag
    stack ( ) : void add current node to the stack this only stores the attributes
    strlen ( string $str ) : integer UTF-8 strlen()
    unbuffer ( ) : string end current buffer and return buffered output
    unichr ( $dec ) : string UTF-8 chr() which supports numeric entities
    unstack ( ) : array remove current tag from stack
    wordwrap ( string $str, $width, $break, $cut = false ) : string wordwrap for utf8 encoded strings

    Method Details

    __construct() public méthode

    constructor, set options, setup parser
    public __construct ( integer $linkPosition = self::LINK_AFTER_CONTENT, integer $bodyWidth = MDFY_BODYWIDTH, boolean $keepHTML = MDFY_KEEPHTML ) : void
    $linkPosition integer define the position of links
    $bodyWidth integer whether or not to wrap the output to the given width defaults to false
    $keepHTML boolean whether to keep non markdownable HTML or to discard it defaults to true (HTML will be kept)
    Résultat void

    _decode_hex() protected méthode

    callback for decode() which converts a hexadecimal entity to UTF-8
    protected _decode_hex ( array $matches ) : string
    $matches array
    Résultat string UTF-8 encoded

    _decode_numeric() protected méthode

    callback for decode() which converts a numerical entity to UTF-8
    protected _decode_numeric ( array $matches ) : string
    $matches array
    Résultat string UTF-8 encoded

    buffer() protected méthode

    buffer next parser output until unbuffer() is called
    protected buffer ( ) : void
    Résultat void

    decode() protected méthode

    decode email addresses
    protected decode ( $text, $quote_style = ENT_QUOTES )

    fixBlockElementSpacing() protected méthode

    Trims whitespace in block-level elements, on the left side.
    protected fixBlockElementSpacing ( )

    fixInlineElementSpacing() protected méthode

    Examples: * leading: Text becomes Text * trailing: Text becomes Text
    protected fixInlineElementSpacing ( )

    flushFootnotes() protected méthode

    output footnotes
    protected flushFootnotes ( ) : void
    Résultat void

    flushLinebreaks() protected méthode

    flush enqued linebreaks
    protected flushLinebreaks ( ) : void
    Résultat void

    getLinkReference() protected méthode

    return formated link reference
    protected getLinkReference ( array $tag ) : string
    $tag array
    Résultat string link reference

    getStacked() protected méthode

    get last stacked element of type $tagName
    protected getStacked ( string $tagName ) : array
    $tagName string
    Résultat array

    handleHeader() protected méthode

    handle header tags (

    -

    )
    protected handleHeader ( integer $level ) : void
    $level integer 1-6
    Résultat void

    handleTagToText() protected méthode

    handle non Markdownable tags
    protected handleTagToText ( ) : void
    Résultat void

    handleTag_blockquote() protected méthode

    handle
    tags
    protected handleTag_blockquote ( ) : void
    Résultat void

    handleTag_br() protected méthode

    handle
    tags
    protected handleTag_br ( ) : void
    Résultat void

    handleTag_code() protected méthode

    handle tags
    protected handleTag_code ( ) : void
    Résultat void

    handleTag_em() protected méthode

    handle and tags
    protected handleTag_em ( ) : void
    Résultat void

    handleTag_h1() protected méthode

    handle

    tags

    protected handleTag_h1 ( ) : void
    Résultat void

    handleTag_h2() protected méthode

    handle

    tags

    protected handleTag_h2 ( ) : void
    Résultat void

    handleTag_h3() protected méthode

    handle

    tags

    protected handleTag_h3 ( ) : void
    Résultat void

    handleTag_h4() protected méthode

    handle

    tags

    protected handleTag_h4 ( ) : void
    Résultat void

    handleTag_h5() protected méthode

    handle
    tags
    protected handleTag_h5 ( ) : void
    Résultat void

    handleTag_h6() protected méthode

    handle
    tags
    protected handleTag_h6 ( ) : void
    Résultat void

    handleTag_hr() protected méthode

    handle
    tags
    protected handleTag_hr ( ) : void
    Résultat void

    handleTag_i() protected méthode

    protected handleTag_i ( )

    handleTag_img() protected méthode

    handle tags
    protected handleTag_img ( ) : void
    Résultat void

    handleTag_li() protected méthode

    handle
  • tags
  • protected handleTag_li ( ) : void
    Résultat void

    handleTag_ol() protected méthode

    handle
      tags
    protected handleTag_ol ( ) : void
    Résultat void

    handleTag_p() protected méthode

    handle

    tags

    protected handleTag_p ( ) : void
    Résultat void

    handleTag_pre() protected méthode

    handle
     tags        
    protected handleTag_pre ( ) : void
    Résultat void

    handleTag_strong() protected méthode

    handle and tags
    protected handleTag_strong ( ) : void
    Résultat void

    handleTag_ul() protected méthode

    handle
      tags
    protected handleTag_ul ( ) : void
    Résultat void

    handleText() protected méthode

    handle plain text
    protected handleText ( ) : void
    Résultat void

    hasParent() protected méthode

    check if current node has a $tagName as parent (somewhere, not only the direct parent)
    protected hasParent ( string $tagName ) : boolean
    $tagName string
    Résultat boolean

    indent() protected méthode

    indent next output (start tag) or unindent (end tag)
    protected indent ( string $str, boolean $output = true ) : void
    $str string indentation
    $output boolean add indendation to output
    Résultat void

    isMarkdownable() protected méthode

    check if current tag can be converted to Markdown
    protected isMarkdownable ( ) : boolean
    Résultat boolean

    out() protected méthode

    append string to the correct var, either directly to $this->output or to the current buffers
    protected out ( string $put, boolean $nowrap = false ) : void
    $put string
    $nowrap boolean
    Résultat void

    parent() protected méthode

    get tagName of direct parent tag
    protected parent ( ) : string
    Résultat string $tagName

    parse() protected méthode

    iterate through the nodes and decide what we shall do with the current node
    protected parse ( ) : void
    Résultat void

    parseString() public méthode

    parse a HTML string
    public parseString ( string $html ) : string
    $html string
    Résultat string markdown formatted

    resetState() protected méthode

    Ideal for running within a loop where you want to maintain a single instance.
    protected resetState ( )

    setKeepHTML() public méthode

    set keep HTML tags which cannot be converted to markdown
    public setKeepHTML ( $keepHTML ) : void
    Résultat void

    setLineBreaks() protected méthode

    set number of line breaks before next start tag
    protected setLineBreaks ( integer $number ) : void
    $number integer
    Résultat void

    setLinkPosition() public méthode

    set the position where the link reference will be displayed
    public setLinkPosition ( integer $linkPosition ) : void
    $linkPosition integer
    Résultat void

    stack() protected méthode

    add current node to the stack this only stores the attributes
    protected stack ( ) : void
    Résultat void

    strlen() protected méthode

    UTF-8 strlen()
    protected strlen ( string $str ) : integer
    $str string
    Résultat integer

    unbuffer() protected méthode

    end current buffer and return buffered output
    protected unbuffer ( ) : string
    Résultat string

    unichr() protected méthode

    UTF-8 chr() which supports numeric entities
    protected unichr ( $dec ) : string
    Résultat string UTF-8 encoded

    unstack() protected méthode

    remove current tag from stack
    protected unstack ( ) : array
    Résultat array

    wordwrap() protected méthode

    wordwrap for utf8 encoded strings
    protected wordwrap ( string $str, $width, $break, $cut = false ) : string
    $str string
    Résultat string

    Property Details

    $allowMixedChildren protected_oe property

    html block tags that allow inline & block children
    protected array $allowMixedChildren
    Résultat array

    $bodyWidth protected_oe property

    wrap output, set to 0 to skip wrapping
    protected int $bodyWidth
    Résultat integer

    $buffer protected_oe property

    stores current buffers
    protected array $buffer
    Résultat array

    $drop protected_oe property

    html tags to be dropped (contents will not be parsed!)
    protected array $drop
    Résultat array

    $escapeInText protected_oe property

    list of chars which have to be escaped in normal text
    protected array $escapeInText
    Résultat array

    $footnotes protected_oe property

    stores current buffers
    protected array $footnotes
    Résultat array

    $ignore protected_oe property

    html tags to be ignored (contents will be parsed)
    protected array $ignore
    Résultat array

    $indent protected_oe property

    current indentation
    protected string $indent
    Résultat string

    $isMarkdownable protected_oe property

    tags with elements which can be handled by markdown
    protected array $isMarkdownable
    Résultat array

    $keepHTML protected_oe property

    keep html tags which cannot be converted to markdown
    protected bool $keepHTML
    Résultat boolean

    $lastClosedTag protected_oe property

    name of last closed tag
    protected string $lastClosedTag
    Résultat string

    $lastWasBlockTag protected_oe property

    wether last processed node was a block tag or not
    protected bool $lastWasBlockTag
    Résultat boolean

    $lineBreaks protected_oe property

    number of line breaks before next inline output
    protected $lineBreaks

    $linkPosition protected_oe property

    position where the link reference will be displayed
    protected int $linkPosition
    Résultat integer

    $minBodyWidth protected_oe property

    minimum body width
    protected int $minBodyWidth
    Résultat integer

    $notConverted protected_oe property

    stack with tags which where not converted to html
    protected array $notConverted
    Résultat array

    $output protected_oe property

    markdown output
    protected string $output
    Résultat string

    $parser protected_oe property

    html parser object
    protected parseHTML $parser
    Résultat parseHTML

    $skipConversion protected_oe property

    skip conversion to markdown
    protected bool $skipConversion
    Résultat boolean

    $stack protected_oe property

    node stack, e.g. for and tags
    protected array $stack
    Résultat array
    Markdown indents which could be wrapped
    protected array $wrappableIndents
    Résultat array