\WPCom_GHF_Markdown_Parser

GitHub-Flavoured Markdown. Inspired by Evan's plugin, but modified.

Summary

Methods
Properties
Constants
__construct()
transform()
codeblock_preserve()
do_codeblock_preserve()
codeblock_restore()
do_codeblock_restore()
unp()
doFencedCodeBlocks()
_doEscapeForHashWithoutSpacing()
_doFencedCodeBlocks_callback()
MarkdownExtra_Parser()
setup()
teardown()
doExtraAttributes()
stripLinkDefinitions()
_stripLinkDefinitions_callback()
hashHTMLBlocks()
_hashHTMLBlocks_inMarkdown()
_hashHTMLBlocks_inHTML()
hashClean()
doAnchors()
_doAnchors_reference_callback()
_doAnchors_inline_callback()
doImages()
_doImages_reference_callback()
_doImages_inline_callback()
doHeaders()
_doHeaders_callback_setext()
_doHeaders_callback_atx()
doTables()
_doTable_leadingPipe_callback()
_doTable_callback()
doDefLists()
_doDefLists_callback()
processDefListItems()
_processDefListItems_callback_dt()
_processDefListItems_callback_dd()
_doFencedCodeBlocks_newlines()
formParagraphs()
stripFootnotes()
_stripFootnotes_callback()
doFootnotes()
appendFootnotes()
_appendFootnotes_callback()
stripAbbreviations()
_stripAbbreviations_callback()
doAbbreviations()
_doAbbreviations_callback()
Markdown_Parser()
_hashHTMLBlocks_callback()
hashPart()
hashBlock()
runBlockGamut()
runBasicBlockGamut()
doHorizontalRules()
runSpanGamut()
doHardBreaks()
_doHardBreaks_callback()
doLists()
_doLists_callback()
processListItems()
_processListItems_callback()
doCodeBlocks()
_doCodeBlocks_callback()
makeCodeSpan()
prepareItalicsAndBold()
doItalicsAndBold()
doBlockQuotes()
_doBlockQuotes_callback()
_doBlockQuotes_callback2()
encodeAttribute()
encodeAmpsAndAngles()
doAutoLinks()
_doAutoLinks_tel_callback()
_doAutoLinks_url_callback()
_doAutoLinks_email_callback()
encodeEmailAddress()
parseSpan()
handleSpanToken()
outdent()
detab()
_detab_callback()
_initDetab()
unhash()
_unhash_callback()
$use_code_shortcode
$preserve_shortcodes
$preserve_latex
$strip_paras
$shortcode_start
$shortcode_end
$fn_id_prefix
$fn_link_title
$fn_backlink_title
$fn_link_class
$fn_backlink_class
$code_class_prefix
$code_attr_on_pre
$predef_abbr
$footnotes
$footnotes_ordered
$footnotes_ref_count
$footnotes_numbers
$abbr_desciptions
$abbr_word_re
$footnote_counter
$id_class_attr_catch_re
$id_class_attr_nocatch_re
$block_tags_re
$context_block_tags_re
$contain_span_tags_re
$clean_tags_re
$auto_close_tags_re
$em_relist
$strong_relist
$em_strong_relist
$empty_element_suffix
$tab_width
$no_markup
$no_entities
$predef_urls
$predef_titles
$nested_brackets_depth
$nested_brackets_re
$nested_url_parenthesis_depth
$nested_url_parenthesis_re
$escape_chars
$escape_chars_re
$urls
$titles
$html_hashes
$in_anchor
$document_gamut
$block_gamut
$span_gamut
$list_level
$em_strong_prepared_relist
$utf8_strlen
WPCOM_GHF_MARDOWN_VERSION
latex_preserve()
shortcode_preserve()
shortcode_restore()
_doRemoveText()
hash_maker()
get_shortcode_regex()
$preserve_text_hash
N/A
No private methods found
No private properties found
N/A

Constants

WPCOM_GHF_MARDOWN_VERSION

WPCOM_GHF_MARDOWN_VERSION

Hooray somewhat arbitrary numbers that are fearful of 1.0.x.

Properties

$use_code_shortcode

$use_code_shortcode : boolean

Use a [code] shortcode when encountering a fenced code block

Type

boolean

$preserve_shortcodes

$preserve_shortcodes : boolean

Preserve shortcodes, untouched by Markdown.

This requires use within a WordPress installation.

Type

boolean

$preserve_latex

$preserve_latex

Preserve the legacy $latex your-latex-code-here$ style LaTeX markup

$strip_paras

$strip_paras : boolean

Strip paragraphs from the output. This is the right default for WordPress, which generally wants to create its own paragraphs with `wpautop`

Type

boolean

$shortcode_start

$shortcode_start

$shortcode_end

$shortcode_end

$fn_id_prefix

$fn_id_prefix

$fn_link_title

$fn_link_title

$fn_backlink_title

$fn_backlink_title

$fn_link_class

$fn_link_class

$fn_backlink_class

$fn_backlink_class

$code_class_prefix

$code_class_prefix

$code_attr_on_pre

$code_attr_on_pre

$predef_abbr

$predef_abbr

$footnotes

$footnotes

$footnotes_ordered

$footnotes_ordered

$footnotes_ref_count

$footnotes_ref_count

$footnotes_numbers

$footnotes_numbers

$abbr_desciptions

$abbr_desciptions

$abbr_word_re

$abbr_word_re

$footnote_counter

$footnote_counter

$id_class_attr_catch_re

$id_class_attr_catch_re

$id_class_attr_nocatch_re

$id_class_attr_nocatch_re

$block_tags_re

$block_tags_re

$context_block_tags_re

$context_block_tags_re

$contain_span_tags_re

$contain_span_tags_re

$clean_tags_re

$clean_tags_re

$auto_close_tags_re

$auto_close_tags_re

$em_relist

$em_relist

$strong_relist

$strong_relist

$em_strong_relist

$em_strong_relist

$empty_element_suffix

$empty_element_suffix

$tab_width

$tab_width

$no_markup

$no_markup

$no_entities

$no_entities

$predef_urls

$predef_urls

$predef_titles

$predef_titles

$nested_brackets_depth

$nested_brackets_depth

$nested_brackets_re

$nested_brackets_re

$nested_url_parenthesis_depth

$nested_url_parenthesis_depth

$nested_url_parenthesis_re

$nested_url_parenthesis_re

$escape_chars

$escape_chars

$escape_chars_re

$escape_chars_re

$urls

$urls

$titles

$titles

$html_hashes

$html_hashes

$in_anchor

$in_anchor

$document_gamut

$document_gamut

$block_gamut

$block_gamut

$span_gamut

$span_gamut

$list_level

$list_level

$em_strong_prepared_relist

$em_strong_prepared_relist

$utf8_strlen

$utf8_strlen

$preserve_text_hash

$preserve_text_hash

Methods

__construct()

__construct()

Set environment defaults based on presence of key functions/classes.

transform()

transform( $text)

Parameters

$text

codeblock_preserve()

codeblock_preserve(string $text) : string

Preserve code block contents by HTML encoding them. Useful before getting to KSES stripping.

Parameters

string $text

Markdown/HTML content

Returns

string —

Markdown/HTML content with escaped code blocks

do_codeblock_preserve()

do_codeblock_preserve(array $matches) : string

Regex callback for code block preservation.

Parameters

array $matches

Regex matches

Returns

string —

Codeblock with escaped interior

codeblock_restore()

codeblock_restore(string $text) : string

Restore previously preserved (i.e. escaped) code block contents.

Parameters

string $text

Markdown/HTML content with escaped code blocks

Returns

string —

Markdown/HTML content

do_codeblock_restore()

do_codeblock_restore(array $matches) : string

Regex callback for code block restoration (unescaping).

Parameters

array $matches

Regex matches

Returns

string —

Codeblock with unescaped interior

unp()

unp(string $text) : string

Remove bare <p> elements. <p>s with attributes will be preserved.

Parameters

string $text

HTML content

Returns

string —

-less content

doFencedCodeBlocks()

doFencedCodeBlocks( $text)

Parameters

$text

_doEscapeForHashWithoutSpacing()

_doEscapeForHashWithoutSpacing(array $m) : string

Callback for pre-processing start of line hashes to slyly escape headings that don't have a leading space

Parameters

array $m

preg_match matches

Returns

string —

possibly escaped start of line hash

_doFencedCodeBlocks_callback()

_doFencedCodeBlocks_callback( $matches)

Parameters

$matches

MarkdownExtra_Parser()

MarkdownExtra_Parser()

setup()

setup()

teardown()

teardown()

doExtraAttributes()

doExtraAttributes( $tag_name,  $attr)

Parameters

$tag_name
$attr

stripLinkDefinitions()

stripLinkDefinitions( $text)

Parameters

$text

_stripLinkDefinitions_callback()

_stripLinkDefinitions_callback( $matches)

Parameters

$matches

hashHTMLBlocks()

hashHTMLBlocks( $text)

Parameters

$text

_hashHTMLBlocks_inMarkdown()

_hashHTMLBlocks_inMarkdown( $text,  $indent,  $enclosing_tag_re,  $span)

Parameters

$text
$indent
$enclosing_tag_re
$span

_hashHTMLBlocks_inHTML()

_hashHTMLBlocks_inHTML( $text,  $hash_method,  $md_attr)

Parameters

$text
$hash_method
$md_attr

hashClean()

hashClean( $text)

Parameters

$text

doAnchors()

doAnchors( $text)

Parameters

$text

_doAnchors_reference_callback()

_doAnchors_reference_callback( $matches)

Parameters

$matches

_doAnchors_inline_callback()

_doAnchors_inline_callback( $matches)

Parameters

$matches

doImages()

doImages( $text)

Parameters

$text

_doImages_reference_callback()

_doImages_reference_callback( $matches)

Parameters

$matches

_doImages_inline_callback()

_doImages_inline_callback( $matches)

Parameters

$matches

doHeaders()

doHeaders( $text)

Parameters

$text

_doHeaders_callback_setext()

_doHeaders_callback_setext( $matches)

Parameters

$matches

_doHeaders_callback_atx()

_doHeaders_callback_atx( $matches)

Parameters

$matches

doTables()

doTables( $text)

Parameters

$text

_doTable_leadingPipe_callback()

_doTable_leadingPipe_callback( $matches)

Parameters

$matches

_doTable_callback()

_doTable_callback( $matches)

Parameters

$matches

doDefLists()

doDefLists( $text)

Parameters

$text

_doDefLists_callback()

_doDefLists_callback( $matches)

Parameters

$matches

processDefListItems()

processDefListItems( $list_str)

Parameters

$list_str

_processDefListItems_callback_dt()

_processDefListItems_callback_dt( $matches)

Parameters

$matches

_processDefListItems_callback_dd()

_processDefListItems_callback_dd( $matches)

Parameters

$matches

_doFencedCodeBlocks_newlines()

_doFencedCodeBlocks_newlines( $matches)

Parameters

$matches

formParagraphs()

formParagraphs( $text)

Parameters

$text

stripFootnotes()

stripFootnotes( $text)

Parameters

$text

_stripFootnotes_callback()

_stripFootnotes_callback( $matches)

Parameters

$matches

doFootnotes()

doFootnotes( $text)

Parameters

$text

appendFootnotes()

appendFootnotes( $text)

Parameters

$text

_appendFootnotes_callback()

_appendFootnotes_callback( $matches)

Parameters

$matches

stripAbbreviations()

stripAbbreviations( $text)

Parameters

$text

_stripAbbreviations_callback()

_stripAbbreviations_callback( $matches)

Parameters

$matches

doAbbreviations()

doAbbreviations( $text)

Parameters

$text

_doAbbreviations_callback()

_doAbbreviations_callback( $matches)

Parameters

$matches

Markdown_Parser()

Markdown_Parser()

_hashHTMLBlocks_callback()

_hashHTMLBlocks_callback( $matches)

Parameters

$matches

hashPart()

hashPart( $text,  $boundary)

Parameters

$text
$boundary

hashBlock()

hashBlock( $text)

Parameters

$text

runBlockGamut()

runBlockGamut( $text)

Parameters

$text

runBasicBlockGamut()

runBasicBlockGamut( $text)

Parameters

$text

doHorizontalRules()

doHorizontalRules( $text)

Parameters

$text

runSpanGamut()

runSpanGamut( $text)

Parameters

$text

doHardBreaks()

doHardBreaks( $text)

Parameters

$text

_doHardBreaks_callback()

_doHardBreaks_callback( $matches)

Parameters

$matches

doLists()

doLists( $text)

Parameters

$text

_doLists_callback()

_doLists_callback( $matches)

Parameters

$matches

processListItems()

processListItems( $list_str,  $marker_any_re)

Parameters

$list_str
$marker_any_re

_processListItems_callback()

_processListItems_callback( $matches)

Parameters

$matches

doCodeBlocks()

doCodeBlocks( $text)

Parameters

$text

_doCodeBlocks_callback()

_doCodeBlocks_callback( $matches)

Parameters

$matches

makeCodeSpan()

makeCodeSpan( $code)

Parameters

$code

prepareItalicsAndBold()

prepareItalicsAndBold()

doItalicsAndBold()

doItalicsAndBold( $text)

Parameters

$text

doBlockQuotes()

doBlockQuotes( $text)

Parameters

$text

_doBlockQuotes_callback()

_doBlockQuotes_callback( $matches)

Parameters

$matches

_doBlockQuotes_callback2()

_doBlockQuotes_callback2( $matches)

Parameters

$matches

encodeAttribute()

encodeAttribute( $text)

Parameters

$text

encodeAmpsAndAngles()

encodeAmpsAndAngles( $text)

Parameters

$text

doAutoLinks()

doAutoLinks( $text)

Parameters

$text

_doAutoLinks_tel_callback()

_doAutoLinks_tel_callback( $matches)

Parameters

$matches

_doAutoLinks_url_callback()

_doAutoLinks_url_callback( $matches)

Parameters

$matches

_doAutoLinks_email_callback()

_doAutoLinks_email_callback( $matches)

Parameters

$matches

encodeEmailAddress()

encodeEmailAddress( $addr)

Parameters

$addr

parseSpan()

parseSpan( $str)

Parameters

$str

handleSpanToken()

handleSpanToken( $token,  $str)

Parameters

$token
$str

outdent()

outdent( $text)

Parameters

$text

detab()

detab( $text)

Parameters

$text

_detab_callback()

_detab_callback( $matches)

Parameters

$matches

_initDetab()

_initDetab()

unhash()

unhash( $text)

Parameters

$text

_unhash_callback()

_unhash_callback( $matches)

Parameters

$matches

latex_preserve()

latex_preserve(string $text) : string

Called to preserve legacy LaTeX like $latex some-latex-text $

Parameters

string $text

Text in which to preserve LaTeX

Returns

string —

Text with LaTeX replaced by a hash that will be restored later

shortcode_preserve()

shortcode_preserve(string $text) : string

Called to preserve WP shortcodes from being formatted by Markdown in any way.

Parameters

string $text

Text in which to preserve shortcodes

Returns

string —

Text with shortcodes replaced by a hash that will be restored later

shortcode_restore()

shortcode_restore(string $text) : string

Restores any text preserved by $this->latex_preserve() or $this->shortcode_preserve()

Parameters

string $text

Text that may have hashed preservation placeholders

Returns

string —

Text with hashed preseravtion placeholders replaced by original text

_doRemoveText()

_doRemoveText(array $m) : string

Regex callback for text preservation

Parameters

array $m

Regex $matches array

Returns

string —

A placeholder that will later be replaced by the original text

hash_maker()

hash_maker(string $hash) : string

Less glamorous than the Keymaker

Parameters

string $hash

An md5 hash

Returns

string —

A placeholder hash

get_shortcode_regex()

get_shortcode_regex() : string

A regex of all shortcodes currently registered by the current WordPress installation

Returns

string —

A regex for grabbing shortcodes.