### List Item Delimiter Change Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Shows how changing the list delimiter (e.g., from '-' to '+') starts a new list. Includes the resulting HTML output. ```markdown - foo - bar + baz . ``` ```html ``` -------------------------------- ### Ordered List Delimiter Change Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Illustrates how changing the ordered list delimiter (e.g., from '.' to ')') starts a new ordered list. Includes the resulting HTML output. ```markdown 1. foo 2. bar 3) baz . ``` ```html
  1. foo
  2. bar
  1. baz
``` -------------------------------- ### Install markdown-it-py with PIP Source: https://github.com/executablebooks/markdown-it-py/blob/master/README.md Install the markdown-it-py package using pip. Use the `[plugins]` extra to include common plugins. ```bash pip install markdown-it-py[plugins] ``` ```bash pip install markdown-it-py[linkify,plugins] ``` -------------------------------- ### HTML Block Rendering Example 4 Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates an HTML block starting with a closing \`\` tag, followed by a Markdown paragraph. ```markdown *foo* . *foo* ``` -------------------------------- ### Markdown renderer example Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md This example shows how to use the MDRenderer from mdformat to render a token stream back to markdown. ```python from markdown_it import MarkdownIt from mdformat.renderer import MDRenderer md = MarkdownIt("commonmark") source_markdown = """ Here's some *text* 1. a list > a *quote*""" tokens = md.parse(source_markdown) renderer = MDRenderer() options = {} env = {} output_markdown = renderer.render(tokens, options, env) ``` -------------------------------- ### Loading Plugins Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Example of loading front_matter and footnote plugins, and enabling table syntax. ```python from markdown_it import MarkdownIt import mdit_py_plugins from mdit_py_plugins.front_matter import front_matter_plugin from mdit_py_plugins.footnote import footnote_plugin md = ( MarkdownIt() .use(front_matter_plugin) .use(footnote_plugin) .enable('table') ) text = (" --- a: 1 --- a | b - | - 1 | 2 A footnote [^1] [^1]: some details ") print(md.render(text)) ``` -------------------------------- ### Markdown List Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html The equivalent of the AsciiDoc list example, demonstrating Markdown's syntax for nested lists and continuation paragraphs. ```markdown 1. List item one. List item one continued with a second paragraph followed by an Indented block. $ ls *.sh $ mv *.sh ~/tmp List item continued with a third paragraph. 2. List item two continued with an open block. This paragraph is part of the preceding list item. 1. This list is nested and does not require explicit item continuation. This paragraph is part of the preceding list item. 2. List item b. This paragraph belongs to item two of the outer list. ``` -------------------------------- ### Example HTML Tags Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Demonstrates simple and nested HTML tags that are parsed as raw HTML. ```markdown .

``` -------------------------------- ### Install markdown-it-py with Conda Source: https://github.com/executablebooks/markdown-it-py/blob/master/README.md Install the markdown-it-py package using Conda. Specify extras like `linkify-it-py` and `mdit-py-plugins` if needed. ```bash conda install -c conda-forge markdown-it-py ``` ```bash conda install -c conda-forge markdown-it-py linkify-it-py mdit-py-plugins ``` -------------------------------- ### Token Object Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Shows an example of a token object and its properties. ```python tokens[0] ``` -------------------------------- ### HTML Block Rendering Example 3 Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows an HTML block starting with a \`
\` tag and containing Markdown-like syntax. The block is terminated by a blank line. ```markdown
*hello* .
*hello* ``` -------------------------------- ### Basic HTML Block (Type 6) Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Illustrates a basic HTML block of type 6, starting with and ending at a blank line. The content inside the table is rendered as is. ```markdown
hi
okay. .
hi

okay.

``` -------------------------------- ### Ordered list with zero start number Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates that an ordered list can start with '0'. ```markdown 0. ok ``` -------------------------------- ### Empty List Item at Start of List Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html A list can start with an empty list item. ```markdown * . ``` -------------------------------- ### Install pre-commit for code style enforcement Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/contributing.md Installs the pre-commit package to ensure code style is met before commits are submitted. ```shell >> cd markdown-it-py >> pre-commit install ``` -------------------------------- ### HTML Block Rendering Example 2 Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Illustrates a basic HTML block starting with \`\` and containing indented content. The block is followed by a Markdown paragraph. ```markdown
hi
okay. . table> hi

okay.

``` -------------------------------- ### Creating a Markdown-It Plugin Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Example of a plugin function that receives a MarkdownIt instance and options. It demonstrates how to add new parsing rules and render rules. ```python def my_plugin(md: MarkdownIt, **options): """My custom plugin.""" # Add rules md.block.ruler.before("fence", "my_block_rule", my_block_rule) md.inline.ruler.after("emphasis", "my_inline_rule", my_inline_rule) # Add render rules md.add_render_rule("my_token_type", render_my_token) ``` -------------------------------- ### Creating a Syntax Tree Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Example of converting a token stream into a syntax tree, collapsing opening/closing tokens and containing children. ```python from markdown_it.tree import SyntaxTreeNode md = MarkdownIt("commonmark") tokens = md.parse(""" # Header Here's some text and an image ![title](image.png) 1. a **list** > a *quote*""") node = SyntaxTreeNode(tokens) print(node.pretty(indent=2, show_text=True)) ``` -------------------------------- ### URI Autolink Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates a basic URI autolink. Ensure the URI is enclosed in angle brackets. ```markdown .

http://foo.bar.baz

``` -------------------------------- ### Nonentities Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Displays examples of strings that are not recognized as valid entity or numeric character references, including incomplete references and undefined entities. ```html   &x; &#; &#x; � &#abcdef0; &ThisIsNotDefined; &hi?; . ``` ```html

&nbsp &x; &#; &#x; � &#abcdef0; &ThisIsNotDefined; &hi?;

``` -------------------------------- ### Plugins supporting multiple render types Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md This example shows how plugins can support multiple render types using the '__output__' attribute. ```python from markdown_it.renderer import RendererHTML class MyRenderer1(RendererHTML): __output__ = "html1" class MyRenderer2(RendererHTML): __output__ = "html2" def plugin(md): def render_em_open1(self, tokens, idx, options, env): return '' def render_em_open2(self, tokens, idx, options, env): return '' md.add_render_rule("em_open", render_em_open1, fmt="html1") md.add_render_rule("em_open", render_em_open2, fmt="html2") md = MarkdownIt("commonmark", renderer_cls=MyRenderer1).use(plugin) print(md.render("*a*")) md = MarkdownIt("commonmark", renderer_cls=MyRenderer2).use(plugin) print(md.render("*a*")) ``` -------------------------------- ### Tab Expansion Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/rawtabs.md Demonstrates how markdown-it-py handles tab characters. Ensure tabs are not replaced with spaces for correct rendering. ```text 1 4444 22 333 333 22 4444 1 ``` ```text tab-indented line space-indented line tab-indented line ``` ```text a lot of spaces in between here ``` ```text a lot of tabs in between here ``` -------------------------------- ### AsciiDoc List Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html An example of a complex list structure in AsciiDoc, including nested lists and continuation paragraphs. ```asciidoc 1. List item one. + List item one continued with a second paragraph followed by an Indented block. + ................. $ ls *.sh $ mv *.sh ~/tmp ................. + List item continued with a third paragraph. 2. List item two continued with an open block. + -- This paragraph is part of the preceding list item. a. This list is nested and does not require explicit item continuation. + This paragraph is part of the preceding list item. b. List item b. This paragraph belongs to item two of the outer list. -- ``` -------------------------------- ### Subclassing the renderer Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md This example demonstrates subclassing the RendererHTML class to add custom rendering logic. ```python from markdown_it.renderer import RendererHTML class MyRenderer(RendererHTML): def em_open(self, tokens, idx, options, env): return '' md = MarkdownIt("commonmark", renderer_cls=MyRenderer) md.render("*a*") ``` -------------------------------- ### Type Annotation Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Example of using complete type annotations for function signatures as per project best practices. Ensure mypy is used for strict type checking. ```python from __future__ import annotations from typing import Sequence def parse_blocks( state: StateBlock, start_line: int, end_line: int, silent: bool = False ) -> bool: """Parse block-level content. :param state: The parser state object :param start_line: Starting line number :param end_line: Ending line number :param silent: If True, only validate without generating tokens :return: True if parsing succeeded """ ... ``` -------------------------------- ### Run all tests with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Execute all defined test suites using Tox. Ensure Tox is installed and configured. ```bash tox ``` -------------------------------- ### AsciiDoc List Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Example of a complex list structure in AsciiDoc, including nested lists and indented blocks. ```asciidoc 1. List item one. + List item one continued with a second paragraph followed by an Indented block. + ................. $ ls *.sh $ mv *.sh ~\/tmp ................. + List item continued with a third paragraph. 2. List item two continued with an open block. + -- This paragraph is part of the preceding list item. a. This list is nested and does not require explicit item continuation. + This paragraph is part of the preceding list item. b. List item b. This paragraph belongs to item two of the outer list. -- ``` -------------------------------- ### HTML Output for Four-Space Rule Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows the HTML output generated by the four-space rule for the preceding Markdown example, highlighting the separation of list items and paragraphs. ```html
  • foo

bar

  • baz
``` -------------------------------- ### Markdown List Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Equivalent complex list structure in Markdown, demonstrating its readability compared to AsciiDoc. ```markdown 1. List item one. List item one continued with a second paragraph followed by an Indented block. $ ls *.sh $ mv *.sh ~\/tmp List item continued with a third paragraph. 2. List item two continued with an open block. This paragraph is part of the preceding list item. 1. This list is nested and does not require explicit item continuation. This paragraph is part of the preceding list item. 2. List item b. This paragraph belongs to item two of the outer list. ``` -------------------------------- ### Markdown Triple Delimiter Examples Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Examples of how triple asterisks and underscores are used for strong emphasis and nested emphasis in Markdown. ```markdown ***strong emph*** ***strong** in emph* ***emph* in strong** **in strong *emph*** *in emph **strong*** ``` -------------------------------- ### Processing Instruction Example (Type 3) Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Demonstrates a processing instruction, such as a PHP tag. Content following the instruction is parsed as CommonMark. ```php echo '>'; ``` ```markdown ' ?> okay . ' ?>

okay

``` -------------------------------- ### Code Block with Info String (Ruby) Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Provides an example of a code block with an info string specifying the language as Ruby. ```ruby ```ruby def foo(x) return 3 end ``` .
def foo(x)
  return 3
end
``` -------------------------------- ### Replacing images with Vimeo iframes Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md This example replaces image rendering with Vimeo iframe embedding for specific URLs. ```python import re from markdown_it import MarkdownIt vimeoRE = re.compile(r'^https?: o//www\.)?vimeo\.com/(\d+)(|/)$') def render_vimeo(self, tokens, idx, options, env): token = tokens[idx] if vimeoRE.match(token.attrs["src"]): ident = vimeoRE.match(token.attrs["src"])[2] return ('
' + ' ' + '
') return self.image(tokens, idx, options, env) md = MarkdownIt("commonmark") md.add_render_rule("image", render_vimeo) print(md.render("![](https://www.vimeo.com/123)")) ``` -------------------------------- ### Markdown Emphasis Precedence Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Example to test precedence rules between emphasis and strong emphasis markers. ```markdown *foo *bar* baz* ``` -------------------------------- ### Self-Closing Style Tag Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Example of a style tag where the start and end tags are on the same line, followed by Markdown text. ```html *foo* ``` ```html

foo

``` -------------------------------- ### Get all available parsing rules Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Retrieves and pretty-prints all available parsing rules for the MarkdownIt parser. ```python pprint(md.get_all_rules()) ``` -------------------------------- ### Build documentation (clean) with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Perform a clean build of the project documentation using the 'docs-clean' Tox environment. This ensures no stale artifacts affect the build. ```bash tox -e docs-clean ``` -------------------------------- ### Markdown to HTML: Basic List Item Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Demonstrates how a markdown list item with a paragraph, indented code, and a block quote is converted to HTML. ```markdown ```````````````````````````````` example A paragraph with two lines. indented code > A block quote. . ``` ```html

A paragraph with two lines.

indented code

A block quote.

``` -------------------------------- ### Build documentation (incremental) with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Perform an incremental build of the project documentation using the 'docs-update' Tox environment. This is faster for iterative documentation changes. ```bash tox -e docs-update ``` -------------------------------- ### Comment Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Illustrates how HTML comments are parsed. Content following a comment block is treated as CommonMark. ```markdown *bar* *baz* . *bar*

baz

``` -------------------------------- ### Tilde Code Fence Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Illustrates the use of tilde characters for code fences, including those with internal spaces. ```markdown ~~~~~~ aaa ~~~ ~~ . ``` ```html
aaa
~~~ ~~
``` -------------------------------- ### HTML Declaration Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows a basic HTML DOCTYPE declaration as an example of an HTML block. ```html ``` ```html ``` -------------------------------- ### Left-Flanking Delimiter Run Examples Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Illustrates delimiter runs that are left-flanking but not right-flanking, showing various combinations of asterisks, underscores, and surrounding characters. ```markdown ***abc _abc **"abc" _"abc" ``` -------------------------------- ### Empty HTML Elements Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Shows examples of empty HTML elements with self-closing syntax. ```markdown .

``` -------------------------------- ### Creating a Token Manually Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Illustrates how to create a Token object manually and compare it with an existing token. ```python from markdown_it.token import Token token = Token("paragraph_open", "p", 1, block=True, map=[1, 2]) token == tokens[0] ``` -------------------------------- ### Right-Flanking Delimiter Run Examples Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Illustrates delimiter runs that are right-flanking but not left-flanking, showing various combinations of asterisks, underscores, and surrounding characters. ```markdown abc*** abc_ "abc"** "abc"_ ``` -------------------------------- ### Autolink with Made-up Scheme Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md An example of an autolink with a completely made-up scheme, demonstrating flexibility in scheme definition. ```markdown .

made-up-scheme://foo,bar

``` -------------------------------- ### HTML Block: Processing Instruction Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Defines the start and end conditions for HTML blocks starting with **(**foo)

``` -------------------------------- ### Markdown List Item Wrapping Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Example illustrating list items that might be wrapped in paragraph tags. ```markdown 1. one 2. two 3. three ``` -------------------------------- ### HTML Block: Comment Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Defines the start and end conditions for HTML blocks starting with okay .

okay

``` -------------------------------- ### Invalid Ordered List Start Number (10 Digits) Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md An ordered list with a start number of ten digits is not parsed as a list and is rendered as plain text. ```markdown 1234567890. not ok ``` ```html

1234567890. not ok

``` -------------------------------- ### Render Basic Code Block Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md A simple example of a standard markdown code block. It shows basic text rendering within the code block. ```markdown foo bar ``` -------------------------------- ### Command-line Usage for markdown-it-py Source: https://github.com/executablebooks/markdown-it-py/blob/master/README.md Render markdown to HTML from the command line. Supports reading from standard input or specified files, and provides help and version flags. ```console usage: markdown-it [-h] [-v] [--stdin|filenames [filenames ...]] Parse one or more markdown files, convert each to HTML, and print to stdout positional arguments: --stdin read source Markdown file from standard input filenames specify an optional list of files to convert optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit Interactive: $ markdown-it markdown-it-py [version 0.0.0] (interactive) Type Ctrl-D to complete input, or Ctrl-C to exit. >>> # Example ... > markdown *input* ...

Example

markdown input

Batch: $ markdown-it README.md README.footer.md > index.html ``` -------------------------------- ### List Interrupting Paragraph - Potential Unintended List Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Shows a scenario where a numeral '1' starting a line within a paragraph can be interpreted as the start of a list, interrupting the paragraph. This highlights a potential for unintended list parsing. ```markdown The number of windows in my house is 1. The number of doors is 6. . ``` ```html

The number of windows in my house is

  1. The number of doors is 6.
``` -------------------------------- ### HTML Block with Non-Standard Tag Start Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md The initial tag in an HTML block does not need to be a valid HTML tag, as long as it begins like one. ```html
  • one
  • two

    ``` -------------------------------- ### Basic Open Tags Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates the parsing of simple HTML open tags with various tag names. ```markdown .

    ``` -------------------------------- ### Run tests with plugins using Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Execute tests that include plugin support by targeting the appropriate Tox environment. This verifies integration with extensions. ```bash tox -e py311-plugins ``` -------------------------------- ### HTML Output for Nested List Item Indentation Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md The HTML output for the nested list item example, illustrating how blockquotes and ordered list items are structured. ```html
    1. one

      two

    ``` -------------------------------- ### Hexadecimal Numeric Character References Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Illustrates hexadecimal numeric character references, parsed as their corresponding Unicode characters using hexadecimal notation. ```html " ആ ಫ . ``` ```html

    " ആ ಫ

    ``` -------------------------------- ### Autolink Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md When angle brackets enclose a URL-like string without backticks, it is parsed as an autolink. ```markdown ` ``` -------------------------------- ### List as First Block in List Item Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Demonstrates how a list can be the initial content within a list item, creating a nested list structure. ```markdown - - foo ``` ```html
      • foo
    ``` -------------------------------- ### Single tilde with punctuation Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/strikethrough_single_tilde.md Example of a single tilde followed by punctuation. ```markdown ~foo~bar ``` ```html

    foobar

    ``` -------------------------------- ### Run Markdown Spec Tests Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Use this command to run conformance tests against a Markdown program using the spec file. ```bash python test/spec_tests.py --spec spec.txt --program PROGRAM ``` -------------------------------- ### Mixed single and double Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/strikethrough_single_tilde.md Example of mixing single and double tildes. ```markdown ~single~ and ~~double~~ ``` ```html

    single and double

    ``` -------------------------------- ### Invalid checkbox syntax Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/tasklists.md Examples of syntax that do not render as task list items. ```markdown - [ ] not a todo - [ x] not a todo - [x ] not a todo ``` -------------------------------- ### Reproduce Crash Failures with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/fuzz/README.md Use this command to set up a local Python environment with markdown-it-py and Atheris, then run a minimized testcase to reproduce a crash identified by OSS-Fuzz. ```bash tox -e fuzz path/to/testcase ``` -------------------------------- ### HTML Comment Block Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Example of a multi-line HTML comment block and its corresponding rendered output. ```html okay ``` ```html

    okay

    ``` -------------------------------- ### Load and use external plugins Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/plugins.md Illustrates how to load and use external plugins from the 'mdit-py-plugins' package using the use() method. ```python from markdown_it import MarkdownIt from mdit_py_plugins import plugin1, plugin2 md = MarkdownIt().use(plugin1, keyword=value).use(plugin2, keyword=value) html_string = md.render("some *Markdown*") ``` -------------------------------- ### Enable specific rules and render markdown Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Enables the 'list' and 'emphasis' rules and then renders a markdown string. ```python md.enable(["list", "emphasis"]) md.render("- __*emphasise this*__") ``` -------------------------------- ### Thematic Breaks in Markdown Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Demonstrates how consecutive thematic breaks are rendered. Requires no special setup. ```markdown --- --- ``` ```html

    ``` -------------------------------- ### HTML Block with Malformed Tag Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Even malformed tags that start like valid tags are preserved. ```html
    .

    </a href="foo">

    ``` -------------------------------- ### Build documentation with strict checks Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/contributing.md Performs a clean build of the documentation with strict HTML validation. ```shell >> cd markdown-it-py/docs >> make clean >> make html-strict ``` -------------------------------- ### Closing HTML Tags Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Provides examples of valid closing HTML tags, including those with optional whitespace. ```markdown
    .

    ``` -------------------------------- ### Parsing to Token Stream Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Demonstrates parsing markdown text into a flat token stream and inspecting token types and nesting. ```python md = MarkdownIt("commonmark") tokens = md.parse(""" Here's some *text* 1. a list > a *quote*""") [(t.type, t.nesting) for t in tokens] ``` -------------------------------- ### Empty Code Block Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md An example of an empty code block. This can be used to test parser behavior with no content. ```plaintext ``` -------------------------------- ### Pre Tag Example (Type 1) Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Demonstrates a
     tag, which is a special content tag. These blocks end at the first line containing a corresponding end tag, allowing blank lines within.
    
    ```haskell
    import Text.HTML.TagSoup
    
    main :: IO ()
    main = print $ parseTags tags
    ```
    
    ```markdown
    
    
    import Text.HTML.TagSoup
    
    main :: IO ()
    main = print $ parseTags tags
    
    okay .
    
    import Text.HTML.TagSoup
    
    main :: IO ()
    main = print $ parseTags tags
    

    okay

    ``` -------------------------------- ### Ruby Function Definition Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md A basic Ruby function definition. This is often used for examples within markdown. ```ruby def foo(x) return 3 end ``` -------------------------------- ### Render simple markdown text Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Creates a MarkdownIt instance and renders a simple string with emphasis. ```python md = MarkdownIt() md.render("some *text*") ``` -------------------------------- ### Render Horizontal Rule Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md Shows the markdown syntax for a horizontal rule. This example uses tabs between asterisks. ```markdown * * * ``` -------------------------------- ### List Item Indentation Example 1 Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows a simple bullet list item with content 'one' and subsequent content 'two' on a new line, demonstrating basic indentation rules. ```markdown - one two ``` -------------------------------- ### Example of List Item Content Parsing Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates how a paragraph with two lines, indented code, and a block quote are parsed as content within a list item. ```markdown A paragraph with two lines. indented code > A block quote. ``` -------------------------------- ### Run profiler with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Execute the project within a profiling environment using Tox. This helps in identifying performance bottlenecks in the code. ```bash tox -e profile ``` -------------------------------- ### HTML Block with Standalone Tag Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md To start an HTML block with a non-block-level tag, the tag must be complete and on its own line. ```html *bar* ``` -------------------------------- ### Run package comparison benchmarks with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Execute benchmarks that compare the performance of markdown-it-py against other Markdown parsers using the specified Tox environment. ```bash tox -e py311-bench-packages ``` -------------------------------- ### Import necessary modules Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Imports the pprint module for pretty-printing and the MarkdownIt class from the markdown_it library. ```python from pprint import pprint from markdown_it import MarkdownIt ``` -------------------------------- ### Inline Token Children Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Example showing that an 'inline' type token contains other tokens as children. ```python tokens[1] ``` -------------------------------- ### Override parser options Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/using.md Creates a MarkdownIt instance with the 'zero' preset and overrides the 'maxNesting' option. ```python md = MarkdownIt("zero", {"maxNesting": 99}) md.options ``` -------------------------------- ### Invalid Link Formats Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Examples of bracketed text that are not recognized as links due to improper matching of angle brackets. ```markdown [a]( ``` ```markdown [a](c) ``` ```html

    [a](<b)c [a](<b)c> [a](<b>c)

    ``` -------------------------------- ### Nested Emphasis Variant Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Shows another example of nested emphasis where '_foo _bar_ baz_' is parsed correctly. ```markdown _foo _bar_ baz_ .

    foo bar baz

    ``` -------------------------------- ### Nested Emphasis Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/benchmarking/samples/spec.md Illustrates nested emphasis where '*(**foo**)*' is correctly parsed as italic containing bold text. ```markdown *(**foo**) .

    (foo)

    ``` -------------------------------- ### Run tests with tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/contributing.md Runs tests in multiple isolated environments using tox. ```shell >> cd markdown-it-py >> tox -p ``` -------------------------------- ### Style Tag Example (Type 1) Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Demonstrates a okay .

    okay

    ``` -------------------------------- ### JavaScript Code Block Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md A JavaScript code block demonstrating DOM manipulation. Useful for client-side scripting examples. ```javascript // JavaScript example document.getElementById("demo").innerHTML = "Hello JavaScript!"; ``` -------------------------------- ### Entity in Quoted Link Attribute Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows an example of an entity reference within a quoted attribute of a Markdown link. ```markdown [a](url "tit") .

    [a](url "tit")

    ``` -------------------------------- ### Undefined Entity Reference Example Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Shows that entity references not present in the HTML5 named entities list are not recognized. ```html &MadeUpEntity; . ``` ```html

    &MadeUpEntity;

    ``` -------------------------------- ### Basic Tip Alert Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/alerts.md Demonstrates the syntax for a basic tip alert using the [!TIP] marker. ```markdown > [!TIP] > This is a tip. ``` -------------------------------- ### Markdown List Item with Heading Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Example of a list item containing a section heading, which may not be allowed by all parsers. ```markdown - # Heading ``` -------------------------------- ### Basic Parsing Test Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md A basic test case for markdown-it-py demonstrating rendering of a heading and a paragraph. Asserts the presence of corresponding HTML tags in the output. ```python import pytest from markdown_it import MarkdownIt def test_basic_parsing(): md = MarkdownIt() result = md.render("# Heading\n\nParagraph") assert "

    Heading

    " in result assert "

    Paragraph

    " in result ``` -------------------------------- ### Customizing Link Rendering Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md This Python code demonstrates how to customize the rendering of link elements by adding attributes like 'target' and 'rel' to 'link_open' tokens. ```python from markdown_it import MarkdownIt def render_custom_link(self, tokens, idx, options, env): tokens[idx].attrSet("target", "_blank") tokens[idx].attrSet("rel", "noopener noreferrer") return self.renderToken(tokens, idx, options, env) md = MarkdownIt() md.add_render_rule("link_open", render_custom_link) ``` -------------------------------- ### HTML Block Rendering Example 1 Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates an HTML block containing a \`
    \` tag within a \`\` structure. The HTML block is terminated by a blank line, and subsequent content is parsed as Markdown.
    
    ```markdown
    
    **Hello**,
    
    _world_.
    
    . table>
    **Hello**,
    

    world.

    ``` -------------------------------- ### Autolink with Host and Port Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md Demonstrates an autolink that specifies a hostname and port number. ```markdown .

    localhost:5001/foo

    ``` -------------------------------- ### List Item with Indented Paragraph Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/test_spec/test_file.html Demonstrates how indentation is handled when a list item's content starts with an indented paragraph. ```markdown - foo bar ``` -------------------------------- ### Run a specific test file with Tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/AGENTS.md Execute tests from a particular file within the test suite by providing the file path to Tox. This speeds up focused testing. ```bash tox -- tests/test_api/test_main.py ``` -------------------------------- ### Invalid Email Autolink with Backslash Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_cmark_spec/spec.md An example of an email address with a backslash escape, which is not processed and results in the literal characters being displayed. ```markdown .

    <foo+@bar.example.com>

    ``` -------------------------------- ### Run benchmarking tests with tox Source: https://github.com/executablebooks/markdown-it-py/blob/master/docs/contributing.md Executes benchmarking tests using tox and pytest-benchmark. ```shell >> cd markdown-it-py tox -e py310-bench-packages -- --benchmark-min-rounds 50 ``` -------------------------------- ### Render Simple Lists Source: https://github.com/executablebooks/markdown-it-py/blob/master/tests/test_port/fixtures/commonmark_spec.md Handles basic unordered lists with single and multiple items. ```markdown -one 2.two ``` ```markdown - foo bar ``` ```markdown - Foo bar baz ``` ```markdown - foo bar ``` ```markdown - foo - bar ``` ```markdown - foo bar ``` ```markdown - foo - - bar ``` ```markdown - foo - - bar ``` ```markdown * ```