PHP Class WPCom_GHF_Markdown_Parser, jetpack

Inheritance: extends MarkdownExtra_Parser
ファイルを表示 Open project: automattic/jetpack Class Usage Examples

Public Properties

Property Type Description
$preserve_inline_code_blocks boolean Preserve single-line blocks.
$preserve_latex Preserve the legacy $latex your-latex-code-here$ style LaTeX markup
$preserve_shortcodes boolean This requires use within a WordPress installation.
$shortcode_end
$shortcode_start Will run through sprintf - you can supply your own syntax if you want
$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
$use_code_shortcode boolean Use a [code] shortcode when encountering a fenced code block

Protected Properties

Property Type Description
$preserve_text_hash Stores shortcodes we remove and then replace

Public Methods

Method Description
__construct ( ) Set environment defaults based on presence of key functions/classes.
_doEscapeForHashWithoutSpacing ( array $m ) : string Callback for pre-processing start of line hashes to slyly escape headings that don't have a leading space
_doFencedCodeBlocks_callback ( $matches ) Overload to support Viper's [code] shortcode. Because awesome.
codeblock_preserve ( string $text ) : string Preserve code block contents by HTML encoding them. Useful before getting to KSES stripping.
codeblock_restore ( string $text ) : string Restore previously preserved (i.e. escaped) code block contents.
doFencedCodeBlocks ( $text ) Overload to support ```-fenced code blocks for pre-Markdown Extra 1.2.8 https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks
do_codeblock_preserve ( array $matches ) : string Regex callback for code block preservation.
do_codeblock_restore ( array $matches ) : string Regex callback for code block restoration (unescaping).
do_single_line_code_preserve ( array $matches ) : string Regex callback for inline code presevation
single_line_code_preserve ( string $text ) : string Prevents blocks like __this__ from turning into this
transform ( string $text ) : string Overload to specify heading styles only if the hash has space(s) after it. This is actually in keeping with the documentation and eases the semantic overload of the hash character.
unp ( string $text ) : string Remove bare

elements.

s with attributes will be preserved.

Protected Methods

Method Description
_doRemoveText ( array $m ) : string Regex callback for text preservation
do_restore ( string $text ) : string Restores any text preserved by $this->hash_block()
get_shortcode_regex ( ) : string A regex of all shortcodes currently registered by the current WordPress installation
hash_block ( string $text ) : string Call this to store a text block for later restoration.
hash_maker ( string $hash ) : string Less glamorous than the Keymaker
latex_preserve ( string $text ) : string Called to preserve legacy LaTeX like $latex some-latex-text $
restore_leading_hash ( string $text ) : string Since we escape unspaced #Headings, put things back later.
shortcode_preserve ( string $text ) : string Called to preserve WP shortcodes from being formatted by Markdown in any way.

Method Details

__construct() public method

Set environment defaults based on presence of key functions/classes.
public __construct ( )

_doEscapeForHashWithoutSpacing() public method

Callback for pre-processing start of line hashes to slyly escape headings that don't have a leading space
public _doEscapeForHashWithoutSpacing ( array $m ) : string
$m array preg_match matches
return string possibly escaped start of line hash

_doFencedCodeBlocks_callback() public method

Overload to support Viper's [code] shortcode. Because awesome.
public _doFencedCodeBlocks_callback ( $matches )

_doRemoveText() protected method

Regex callback for text preservation
protected _doRemoveText ( array $m ) : string
$m array Regex $matches array
return string A placeholder that will later be replaced by the original text

codeblock_preserve() public method

Preserve code block contents by HTML encoding them. Useful before getting to KSES stripping.
public codeblock_preserve ( string $text ) : string
$text string Markdown/HTML content
return string Markdown/HTML content with escaped code blocks

codeblock_restore() public method

Restore previously preserved (i.e. escaped) code block contents.
public codeblock_restore ( string $text ) : string
$text string Markdown/HTML content with escaped code blocks
return string Markdown/HTML content

doFencedCodeBlocks() public method

Overload to support ```-fenced code blocks for pre-Markdown Extra 1.2.8 https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks
public doFencedCodeBlocks ( $text )

do_codeblock_preserve() public method

Regex callback for code block preservation.
public do_codeblock_preserve ( array $matches ) : string
$matches array Regex matches
return string Codeblock with escaped interior

do_codeblock_restore() public method

Regex callback for code block restoration (unescaping).
public do_codeblock_restore ( array $matches ) : string
$matches array Regex matches
return string Codeblock with unescaped interior

do_restore() protected method

Restores any text preserved by $this->hash_block()
protected do_restore ( string $text ) : string
$text string Text that may have hashed preservation placeholders
return string Text with hashed preseravtion placeholders replaced by original text

do_single_line_code_preserve() public method

Regex callback for inline code presevation
public do_single_line_code_preserve ( array $matches ) : string
$matches array Regex matches
return string Hashed content for later restoration

get_shortcode_regex() protected method

A regex of all shortcodes currently registered by the current WordPress installation
protected get_shortcode_regex ( ) : string
return string A regex for grabbing shortcodes.

hash_block() protected method

Call this to store a text block for later restoration.
protected hash_block ( string $text ) : string
$text string Text to preserve for later
return string Placeholder that will be swapped out later for the original text

hash_maker() protected method

Less glamorous than the Keymaker
protected hash_maker ( string $hash ) : string
$hash string An md5 hash
return string A placeholder hash

latex_preserve() protected method

Called to preserve legacy LaTeX like $latex some-latex-text $
protected latex_preserve ( string $text ) : string
$text string Text in which to preserve LaTeX
return string Text with LaTeX replaced by a hash that will be restored later

restore_leading_hash() protected method

Since we escape unspaced #Headings, put things back later.
protected restore_leading_hash ( string $text ) : string
$text string text with a leading escaped hash
return string text with leading hashes unescaped

shortcode_preserve() protected method

Called to preserve WP shortcodes from being formatted by Markdown in any way.
protected shortcode_preserve ( string $text ) : string
$text string Text in which to preserve shortcodes
return string Text with shortcodes replaced by a hash that will be restored later

single_line_code_preserve() public method

Prevents blocks like __this__ from turning into this
public single_line_code_preserve ( string $text ) : string
$text string Text that may need preserving
return string Text that was preserved if needed

transform() public method

#Will Not Produce a Heading 1 # This Will Produce a Heading 1
public transform ( string $text ) : string
$text string Markdown text
return string HTML-transformed text

unp() public method

Remove bare

elements.

s with attributes will be preserved.

public unp ( string $text ) : string
$text string HTML content
return string

-less content

Property Details

$preserve_inline_code_blocks public_oe property

Preserve single-line blocks.
public bool $preserve_inline_code_blocks
return boolean

$preserve_latex public_oe property

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

$preserve_shortcodes public_oe property

This requires use within a WordPress installation.
public bool $preserve_shortcodes
return boolean

$preserve_text_hash protected_oe property

Stores shortcodes we remove and then replace
protected $preserve_text_hash

$shortcode_end public_oe property

public $shortcode_end

$shortcode_start public_oe property

Will run through sprintf - you can supply your own syntax if you want
public $shortcode_start

$strip_paras public_oe property

Strip paragraphs from the output. This is the right default for WordPress, which generally wants to create its own paragraphs with wpautop
public bool $strip_paras
return boolean

$use_code_shortcode public_oe property

Use a [code] shortcode when encountering a fenced code block
public bool $use_code_shortcode
return boolean