ConvertsMarkdownToPlainText
in package
Converts Markdown to plain text.
Table of Contents
Constants
- ATX_HEADERS = ['/^(\n)?\s{0,}#{1,6}\s+| {0,}(\n)?\s{0,}#{0,} {0,}(\n)?\s{0,}$/m' => '$1$2$3']
- BLOCKQUOTES = ['/^\s{0,3}>\s?/' => '']
- CODE_BLOCKS = ['/(`{3,})(.*?)\1/m' => '$2']
- DOUBLE_EMPHASIS = self::EMPHASIS
- Emphasis (repeat the line to remove double emphasis)
- EMPHASIS = ['/([\*_]{1,3})(\S.*?\S{0,1})\1/' => '$2']
- FENCED_CODEBLOCKS = ['/`{3}.*\n/' => '', '/`{3}/' => '']
- FOOTNOTES = ['/\[\^.+?\](\: .*?$)?/' => '']
- HORIZONTAL_RULES = ['/^(-\s*?|\*\s*?|_\s*?){3,}\s*/m' => '']
- HTML_TAGS = ['/<[^>]*>/' => '']
- IMAGES = ['/\!\[(.*?)\][\[\(].*?[\]\)]/' => '$1']
- INLINE_CODE = ['/`(.+?)`/' => '$1']
- INLINE_LINKS = ['/\[(.*?)\][\[\(].*?[\]\)]/' => '$1']
- REFERENCE_LINKS = ['/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/' => '']
- REPEATED_NEWLINES = ['/\n{2,}/' => "\n\n"]
- Replace two or more newlines with exactly two
- SETEXT_HEADERS = ['/\n={2,}/' => "\n"]
- STRIKETHROUGH = ['/~~/' => '']
- TILDE_FENCED_CODEBLOCKS = ['/~{3}.*\n/' => '', '/~{3}/' => '']
Properties
- $markdown : string
Methods
- __construct() : mixed
- execute() : string
- Regex based on https://github.com/stiang/remove-markdown, licensed under MIT.
- applyRegexTransformations() : string
- applyStringTransformations() : string
- removeBlockquotes() : string
- removeTables() : string
- trimWhitespace() : string
Constants
ATX_HEADERS
protected
mixed
ATX_HEADERS
= ['/^(\n)?\s{0,}#{1,6}\s+| {0,}(\n)?\s{0,}#{0,} {0,}(\n)?\s{0,}$/m' => '$1$2$3']
BLOCKQUOTES
protected
mixed
BLOCKQUOTES
= ['/^\s{0,3}>\s?/' => '']
CODE_BLOCKS
protected
mixed
CODE_BLOCKS
= ['/(`{3,})(.*?)\1/m' => '$2']
DOUBLE_EMPHASIS
Emphasis (repeat the line to remove double emphasis)
protected
mixed
DOUBLE_EMPHASIS
= self::EMPHASIS
EMPHASIS
protected
mixed
EMPHASIS
= ['/([\*_]{1,3})(\S.*?\S{0,1})\1/' => '$2']
FENCED_CODEBLOCKS
protected
mixed
FENCED_CODEBLOCKS
= ['/`{3}.*\n/' => '', '/`{3}/' => '']
FOOTNOTES
protected
mixed
FOOTNOTES
= ['/\[\^.+?\](\: .*?$)?/' => '']
HORIZONTAL_RULES
protected
mixed
HORIZONTAL_RULES
= ['/^(-\s*?|\*\s*?|_\s*?){3,}\s*/m' => '']
HTML_TAGS
protected
mixed
HTML_TAGS
= ['/<[^>]*>/' => '']
IMAGES
protected
mixed
IMAGES
= ['/\!\[(.*?)\][\[\(].*?[\]\)]/' => '$1']
INLINE_CODE
protected
mixed
INLINE_CODE
= ['/`(.+?)`/' => '$1']
INLINE_LINKS
protected
mixed
INLINE_LINKS
= ['/\[(.*?)\][\[\(].*?[\]\)]/' => '$1']
REFERENCE_LINKS
protected
mixed
REFERENCE_LINKS
= ['/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/' => '']
REPEATED_NEWLINES
Replace two or more newlines with exactly two
protected
mixed
REPEATED_NEWLINES
= ['/\n{2,}/' => "\n\n"]
SETEXT_HEADERS
protected
mixed
SETEXT_HEADERS
= ['/\n={2,}/' => "\n"]
STRIKETHROUGH
protected
mixed
STRIKETHROUGH
= ['/~~/' => '']
TILDE_FENCED_CODEBLOCKS
protected
mixed
TILDE_FENCED_CODEBLOCKS
= ['/~{3}.*\n/' => '', '/~{3}/' => '']
Properties
$markdown
protected
string
$markdown
Methods
__construct()
public
__construct(string $markdown) : mixed
Parameters
- $markdown : string
execute()
Regex based on https://github.com/stiang/remove-markdown, licensed under MIT.
public
execute() : string
Return values
stringapplyRegexTransformations()
protected
applyRegexTransformations(string $markdown) : string
Parameters
- $markdown : string
Return values
stringapplyStringTransformations()
protected
applyStringTransformations(string $markdown) : string
Parameters
- $markdown : string
Return values
stringremoveBlockquotes()
protected
removeBlockquotes(string $contents) : string
Parameters
- $contents : string
Return values
stringremoveTables()
protected
removeTables(string $contents) : string
Parameters
- $contents : string
Return values
stringtrimWhitespace()
protected
trimWhitespace(string $contents) : string
Parameters
- $contents : string