CMarkdownParser
Package | system.utils |
---|---|
Inheritance | class CMarkdownParser » MarkdownExtra_Parser » Markdown_Parser |
Since | 1.0 |
Version | $Id: CMarkdownParser.php 1678 2010-01-07 21:02:00Z qiang.xue $ |
CMarkdownParser is a wrapper of MarkdownExtra_Parser.
CMarkdownParser extends MarkdownExtra_Parser by using Text_Highlighter to highlight code blocks with specific language syntax. In particular, if a code block starts with the following:
You can also specify options to be passed to the syntax highlighter. For example:
For details about the standard markdown syntax, please check the following:
CMarkdownParser extends MarkdownExtra_Parser by using Text_Highlighter to highlight code blocks with specific language syntax. In particular, if a code block starts with the following:
[language]The syntax for the specified language will be used to highlight code block. The languages supported include (case-insensitive): ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL, PHP, PYTHON, RUBY, SQL, XML
You can also specify options to be passed to the syntax highlighter. For example:
[php showLineNumbers=1]which will show line numbers in each line of the code block.
For details about the standard markdown syntax, please check the following:
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
abbr_desciptions | MarkdownExtra_Parser | ||
abbr_word_re | MarkdownExtra_Parser | ||
auto_close_tags_re | MarkdownExtra_Parser | ||
block_gamut | Markdown_Parser | ||
block_tags_re | MarkdownExtra_Parser | ||
clean_tags_re | MarkdownExtra_Parser | ||
contain_span_tags_re | MarkdownExtra_Parser | ||
context_block_tags_re | MarkdownExtra_Parser | ||
document_gamut | Markdown_Parser | ||
em_relist | Markdown_Parser | ||
em_strong_prepared_relist | Markdown_Parser | ||
em_strong_relist | Markdown_Parser | ||
empty_element_suffix | Markdown_Parser | ||
escape_chars | Markdown_Parser | ||
escape_chars_re | Markdown_Parser | ||
fn_backlink_class | MarkdownExtra_Parser | ||
fn_backlink_title | MarkdownExtra_Parser | ||
fn_id_prefix | MarkdownExtra_Parser | ||
fn_link_class | MarkdownExtra_Parser | ||
fn_link_title | MarkdownExtra_Parser | ||
footnote_counter | MarkdownExtra_Parser | ||
footnotes | MarkdownExtra_Parser | ||
footnotes_ordered | MarkdownExtra_Parser | ||
highlightCssClass | string | the css class for the div element containing the code block that is highlighted. | CMarkdownParser |
html_hashes | Markdown_Parser | ||
in_anchor | Markdown_Parser | ||
list_level | Markdown_Parser | ||
nested_brackets_depth | Markdown_Parser | ||
nested_brackets_re | Markdown_Parser | ||
nested_url_parenthesis_depth | Markdown_Parser | ||
nested_url_parenthesis_re | Markdown_Parser | ||
no_entities | Markdown_Parser | ||
no_markup | Markdown_Parser | ||
predef_abbr | MarkdownExtra_Parser | ||
predef_titles | Markdown_Parser | ||
predef_urls | Markdown_Parser | ||
span_gamut | Markdown_Parser | ||
strong_relist | Markdown_Parser | ||
tab_width | Markdown_Parser | ||
titles | Markdown_Parser | ||
urls | Markdown_Parser | ||
utf8_strlen | Markdown_Parser |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | MarkdownExtra_Parser | |
_appendFootnotes_callback() | MarkdownExtra_Parser | |
_detab_callback() | Markdown_Parser | |
_doAbbreviations_callback() | MarkdownExtra_Parser | |
_doAnchors_inline_callback() | Markdown_Parser | |
_doAnchors_reference_callback() | Markdown_Parser | |
_doAutoLinks_email_callback() | Markdown_Parser | |
_doAutoLinks_url_callback() | Markdown_Parser | |
_doBlockQuotes_callback() | Markdown_Parser | |
_doBlockQuotes_callback2() | Markdown_Parser | |
_doCodeBlocks_callback() | Callback function when a code block is matched. | CMarkdownParser |
_doDefLists_callback() | MarkdownExtra_Parser | |
_doFencedCodeBlocks_callback() | Callback function when a fenced code block is matched. | CMarkdownParser |
_doFencedCodeBlocks_newlines() | MarkdownExtra_Parser | |
_doHardBreaks_callback() | Markdown_Parser | |
_doHeaders_attr() | MarkdownExtra_Parser | |
_doHeaders_callback_atx() | MarkdownExtra_Parser | |
_doHeaders_callback_setext() | MarkdownExtra_Parser | |
_doImages_inline_callback() | Markdown_Parser | |
_doImages_reference_callback() | Markdown_Parser | |
_doLists_callback() | Markdown_Parser | |
_doTable_callback() | MarkdownExtra_Parser | |
_doTable_leadingPipe_callback() | MarkdownExtra_Parser | |
_hashHTMLBlocks_callback() | Markdown_Parser | |
_hashHTMLBlocks_inHTML() | MarkdownExtra_Parser | |
_hashHTMLBlocks_inMarkdown() | MarkdownExtra_Parser | |
_initDetab() | Markdown_Parser | |
_processDefListItems_callback_dd() | MarkdownExtra_Parser | |
_processDefListItems_callback_dt() | MarkdownExtra_Parser | |
_processListItems_callback() | Markdown_Parser | |
_stripAbbreviations_callback() | MarkdownExtra_Parser | |
_stripFootnotes_callback() | MarkdownExtra_Parser | |
_stripLinkDefinitions_callback() | Markdown_Parser | |
_unhash_callback() | Markdown_Parser | |
appendFootnotes() | MarkdownExtra_Parser | |
detab() | Markdown_Parser | |
doAbbreviations() | MarkdownExtra_Parser | |
doAnchors() | Markdown_Parser | |
doAutoLinks() | Markdown_Parser | |
doBlockQuotes() | Markdown_Parser | |
doCodeBlocks() | Markdown_Parser | |
doDefLists() | MarkdownExtra_Parser | |
doFencedCodeBlocks() | MarkdownExtra_Parser | |
doFootnotes() | MarkdownExtra_Parser | |
doHardBreaks() | Markdown_Parser | |
doHeaders() | MarkdownExtra_Parser | |
doHorizontalRules() | Markdown_Parser | |
doImages() | Markdown_Parser | |
doItalicsAndBold() | Markdown_Parser | |
doLists() | Markdown_Parser | |
doTables() | MarkdownExtra_Parser | |
encodeAmpsAndAngles() | Markdown_Parser | |
encodeAttribute() | Markdown_Parser | |
encodeEmailAddress() | Markdown_Parser | |
formParagraphs() | MarkdownExtra_Parser | |
getDefaultCssFile() | CMarkdownParser | |
getHiglightConfig() | Generates the config for the highlighter. | CMarkdownParser |
handleSpanToken() | Markdown_Parser | |
hashBlock() | Markdown_Parser | |
hashClean() | MarkdownExtra_Parser | |
hashHTMLBlocks() | MarkdownExtra_Parser | |
hashPart() | Markdown_Parser | |
makeCodeSpan() | Markdown_Parser | |
outdent() | Markdown_Parser | |
parseSpan() | Markdown_Parser | |
prepareItalicsAndBold() | Markdown_Parser | |
processDefListItems() | MarkdownExtra_Parser | |
processListItems() | Markdown_Parser | |
runBasicBlockGamut() | Markdown_Parser | |
runBlockGamut() | Markdown_Parser | |
runSpanGamut() | Markdown_Parser | |
safeTransform() | Transforms the content and purifies the result. | CMarkdownParser |
setup() | MarkdownExtra_Parser | |
stripAbbreviations() | MarkdownExtra_Parser | |
stripFootnotes() | MarkdownExtra_Parser | |
stripLinkDefinitions() | Markdown_Parser | |
teardown() | MarkdownExtra_Parser | |
transform() | Markdown_Parser | |
unhash() | Markdown_Parser |
Protected Methods
Method | Description | Defined By |
---|---|---|
createHighLighter() | Creates a highlighter instance. | CMarkdownParser |
getHighlightTag() | Returns the user-entered highlighting options. | CMarkdownParser |
getInlineOption() | Retrieves the specified configuration. | CMarkdownParser |
highlightCodeBlock() | Highlights the code block. | CMarkdownParser |
Property Details
highlightCssClass
property
public string $highlightCssClass;
the css class for the div element containing the code block that is highlighted. Defaults to 'hl-code'.
Method Details
_doCodeBlocks_callback()
method
public string _doCodeBlocks_callback(array $matches)
| ||
$matches | array | matches |
{return} | string | the highlighted code block |
Callback function when a code block is matched.
_doFencedCodeBlocks_callback()
method
public string _doFencedCodeBlocks_callback(array $matches)
| ||
$matches | array | matches |
{return} | string | the highlighted code block |
Callback function when a fenced code block is matched.
createHighLighter()
method
protected Text_Highlighter createHighLighter(string $options)
| ||
$options | string | the user-entered options |
{return} | Text_Highlighter | the highlighter instance |
Creates a highlighter instance.
getDefaultCssFile()
method
public string getDefaultCssFile()
| ||
{return} | string | the default CSS file that is used to highlight code blocks. |
getHighlightTag()
method
protected string getHighlightTag(string $codeblock)
| ||
$codeblock | string | code block with highlighting options. |
{return} | string | the user-entered highlighting options. Null if no option is entered. |
Returns the user-entered highlighting options.
getHiglightConfig()
method
public array getHiglightConfig(string $options)
| ||
$options | string | user-entered options |
{return} | array | the highlighter config |
Generates the config for the highlighter.
getInlineOption()
method
protected mixed getInlineOption(string $name, string $str, mixed $defaultValue)
| ||
$name | string | the configuration name |
$str | string | the user-entered options |
$defaultValue | mixed | default value if the configuration is not present |
{return} | mixed | the configuration value |
Retrieves the specified configuration.
highlightCodeBlock()
method
protected string highlightCodeBlock(string $codeblock)
| ||
$codeblock | string | the code block |
{return} | string | the highlighted code block. Null if the code block does not need to highlighted |
Highlights the code block.
safeTransform()
method
(available since v1.0.1)
public string safeTransform(string $content)
| ||
$content | string | the markdown content |
{return} | string | the purified HTML content |
Transforms the content and purifies the result. This method calls the transform() method to convert markdown content into HTML content. It then uses CHtmlPurifier to purify the HTML content to avoid XSS attacks.