### Install Parsedown PHP Library via Composer Source: https://github.com/erusev/parsedown/blob/master/README.md This snippet demonstrates the standard way to install the Parsedown Markdown parser using Composer. Running this command adds Parsedown as a dependency to your PHP project, making it available for use. ```bash composer require erusev/parsedown ``` -------------------------------- ### Basic Inline Markdown Link Source: https://github.com/erusev/parsedown/blob/master/test/data/text_reference.html Demonstrates a standard inline Markdown link with a simple label and URL, representing the most common link syntax. ```Markdown [reference link](http://example.com) ``` -------------------------------- ### Bold Markdown Formatting Source: https://github.com/erusev/parsedown/blob/master/test/data/markup_consecutive_two_lines.html Presents text formatted with bold markdown syntax using double asterisks. This example verifies Parsedown's ability to correctly interpret and render bold text. ```Markdown **Markdown** ``` -------------------------------- ### Standard Markdown Link Syntax Source: https://github.com/erusev/parsedown/blob/master/test/data/inline_link.html Demonstrates the basic syntax for creating a hyperlink in Markdown, where the clickable text is enclosed in square brackets followed immediately by the URL in parentheses. ```Markdown [link](http://example.com) ``` -------------------------------- ### Literal Escaped Reference-Style String Source: https://github.com/erusev/parsedown/blob/master/test/data/text_reference.html An example of text that resembles a reference-style link but is escaped with backslashes, ensuring it is rendered as literal text and not parsed as a link. ```Markdown \[one\]\[404\] with no definition ``` -------------------------------- ### Markdown Inline Code Span Syntax Examples Source: https://github.com/erusev/parsedown/blob/master/test/data/code_span.md Illustrates different ways to define inline code spans in Markdown, including simple phrases, single backticks, and content containing backticks, using various backtick delimiters. ```plaintext code span ``` ```plaintext this is also a codespan ``` ```plaintext and look at this one! ``` ```plaintext ` ``` ```plaintext `foo` ``` ```plaintext sth `` sth ``` -------------------------------- ### Markdown Link with Image and Additional Text Source: https://github.com/erusev/parsedown/blob/master/test/data/inline_link.html Illustrates a Markdown link where the clickable area includes both an image and additional descriptive text, allowing for more complex link content. ```Markdown  and text](http://example.com) ``` -------------------------------- ### Markdown Link Enclosed in Parentheses Source: https://github.com/erusev/parsedown/blob/master/test/data/inline_link.html Illustrates a Markdown link that is itself wrapped within parentheses as part of the surrounding text, demonstrating how Markdown handles such contextual formatting. ```Markdown ([link](/index.php)) in parentheses ``` -------------------------------- ### Inline Markdown Link with Trailing Text Source: https://github.com/erusev/parsedown/blob/master/test/data/text_reference.html Shows an inline link immediately followed by additional descriptive text on the same line, testing parser separation. ```Markdown [one](http://example.com) with a semantic name ``` -------------------------------- ### Single-line Partial Markdown Source: https://github.com/erusev/parsedown/blob/master/test/data/markup_consecutive_two_lines.html Demonstrates how Parsedown handles text that might appear to be multi-line but is provided as a single line of input. This example shows a simple phrase without special formatting. ```Markdown and partial markup on two lines. ``` -------------------------------- ### PHP Fenced Code Block Example Source: https://github.com/erusev/parsedown/blob/master/test/data/fenced_code_block.md Demonstrates a basic PHP fenced code block with a variable assignment and output, as parsed by Parsedown. ```php Aura Project ``` -------------------------------- ### Create Horizontal Rule in Markdown Source: https://github.com/erusev/parsedown/blob/master/test/data/setext_header.md Provides an example of creating a horizontal rule in Markdown using three or more hyphens. This element is used to visually separate content sections. ```Markdown ------------ ``` -------------------------------- ### Markdown Single Column Table with Trailing Pipe Source: https://github.com/erusev/parsedown/blob/master/test/data/simple_table.md Demonstrates a single-column Markdown table where the header separator includes a trailing pipe (|). This syntax is often supported and does not invalidate the table. ```Markdown header 1 -------| cell 1.1 cell 2.1 ``` -------------------------------- ### Convert Markdown Document to HTML with Parsedown Source: https://github.com/erusev/parsedown/blob/master/README.md This example shows how to instantiate the Parsedown class and use its `text()` method to convert a full Markdown string into its corresponding HTML representation. The output includes block-level HTML elements like paragraphs. ```php $Parsedown = new Parsedown(); echo $Parsedown->text('Hello _Parsedown_!'); # prints:
Hello Parsedown!
``` -------------------------------- ### Demonstrate JavaScript URI XSS in Markdown Links Source: https://github.com/erusev/parsedown/blob/master/test/data/xss_bad_url.html These snippets show various ways to inject JavaScript code into Markdown links using the 'javascript:' URI scheme. Variations include URL-encoded colons and commented-out slashes, which parsers might misinterpret, leading to Cross-Site Scripting (XSS) vulnerabilities. ```Markdown [xss](javascript%3Aalert(1)) ``` ```Markdown [xss](javascript%3A//alert(1)) ``` ```Markdown [xss](javascript:alert(1)) ``` -------------------------------- ### Markdown Table with Left-Aligned Column Source: https://github.com/erusev/parsedown/blob/master/test/data/simple_table.md Illustrates a Markdown table where the first column is explicitly left-aligned using a colon (:) at the beginning of its header separator. Other columns remain default (usually left or center depending on parser). ```Markdown header 1 | header 2 :------- | -------- cell 1.1 | cell 1.2 cell 2.1 | cell 2.2 ``` -------------------------------- ### Demonstrate Data URI (HTML/JS) XSS in Markdown Links Source: https://github.com/erusev/parsedown/blob/master/test/data/xss_bad_url.html These snippets utilize 'data:' URIs to embed base64-encoded HTML content, including JavaScript, directly into Markdown links. This technique bypasses traditional URL filtering by containing the malicious payload within the URI itself, potentially leading to XSS. ```Markdown [xss](data%3Atext/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==) ``` ```Markdown [xss](data%3A//text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==) ``` ```Markdown [xss](data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==) ``` -------------------------------- ### Markdown: Complex Strong and Emphasis Combination Source: https://github.com/erusev/parsedown/blob/master/test/data/em_strong.html Presents a complex Markdown string with initial bold text, followed by nested emphasis within bold, and then more bold text. The entire string is bold, with the middle part also italic. ```Markdown **strong _em strong_ strong** ``` -------------------------------- ### Markdown: Nested Emphasis with Adjacent Strong Source: https://github.com/erusev/parsedown/blob/master/test/data/em_strong.html Shows a phrase where emphasis is nested within strong, followed by additional bold text outside the emphasis but still within the outer strong tag. The first part is bold and italic, the second part is only bold. ```Markdown **_em strong_ strong** ``` -------------------------------- ### Markdown Table Syntax Not Parsed Due to Context Source: https://github.com/erusev/parsedown/blob/master/test/data/simple_table.md Highlights a scenario where valid Markdown table syntax is not parsed as a table. This occurs because the table structure immediately follows text without a blank line, making it part of the preceding paragraph rather than a distinct block element. ```Markdown header 1 | header 2 -------- | -------- cell 1.1 | cell 1.2 cell 2.1 | cell 2.2 ``` -------------------------------- ### PHP: Basic String Variable and Output Source: https://github.com/erusev/parsedown/blob/master/test/data/tab-indented_code_block.md This PHP snippet initializes a string variable `$message` with 'Hello World!' and then prints its content to the standard output using `echo`. It also demonstrates printing a second string directly after a blank line. ```php line('Hello _Parsedown_!'); # prints: Hello Parsedown! ``` -------------------------------- ### Markdown Code Block with Escaped Characters Source: https://github.com/erusev/parsedown/blob/master/test/data/escaping.md Demonstrates that content within a Markdown code block (typically indented by four spaces) is treated literally, and special characters are not interpreted as Markdown syntax for formatting. ```Markdown escaped \*emphasis\* in a code block ``` -------------------------------- ### Enable Safe Mode for Untrusted Markdown Input in Parsedown Source: https://github.com/erusev/parsedown/blob/master/README.md This code activates Parsedown's safe mode, which is crucial when processing untrusted user-generated Markdown. It helps mitigate XSS risks by escaping user-input within HTML and sanitizing scripting vectors introduced by Markdown syntax. ```php $Parsedown->setSafeMode(true); ``` -------------------------------- ### C# Code Block with Special Character Identifier Source: https://github.com/erusev/parsedown/blob/master/test/data/fenced_code_block.md Demonstrates a C# code block where the language identifier includes a special character, showing Parsedown's handling of such identifiers. ```c# echo 'language identifier with non words'; ``` -------------------------------- ### Escape HTML Markup in Parsedown Output for Trusted Input Source: https://github.com/erusev/parsedown/blob/master/README.md This snippet configures Parsedown to escape all HTML markup present in the input, rendering it as plain text in the output. This method is suitable for trusted input where you want to display raw HTML literally, but it does not provide XSS protection for untrusted input. ```php $Parsedown->setMarkupEscaped(true); ``` -------------------------------- ### Markdown Inline Code Span with Escaped Characters Source: https://github.com/erusev/parsedown/blob/master/test/data/escaping.md Illustrates how special characters like asterisks are preserved within an inline code span in Markdown, preventing them from being interpreted as emphasis markers by the parser. ```Markdown `escaped \*emphasis\* in a code span` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.