### Install mistletoe from source Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Clone the repository and install mistletoe in editable mode for development. ```sh git clone https://github.com/miyuchina/mistletoe.git cd mistletoe pip3 install -e . ``` -------------------------------- ### Install Package Locally Source: https://github.com/miyuchina/mistletoe/blob/master/cutting-a-release.md After uploading, verify the release by installing the package locally using pip. ```bash python -m pip install mistletoe ``` -------------------------------- ### Install and Upgrade Build Tool Source: https://github.com/miyuchina/mistletoe/blob/master/cutting-a-release.md Use this command to install or upgrade the build tool for creating distribution archives. ```bash python -m pip install --upgrade build ``` -------------------------------- ### Install mistletoe with pip Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Install the mistletoe package using pip for Python 3.5 and above. ```sh pip3 install mistletoe ``` -------------------------------- ### Markdown Input Example Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Example markdown content used to demonstrate AST parsing. ```markdown # Heading 1 text # Heading 2 [link](https://www.example.com) ``` -------------------------------- ### Install Node Dependencies Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Installs all necessary Node.js dependencies for building and testing jQuery. Run this before other build or test commands. ```bash npm install ``` -------------------------------- ### Verify Grunt Installation Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Check if the Grunt CLI is installed correctly by displaying its version. ```bash grunt -V ``` -------------------------------- ### Install and Upgrade Twine Source: https://github.com/miyuchina/mistletoe/blob/master/cutting-a-release.md Use this command to install or upgrade Twine, a tool for uploading Python packages. ```bash python -m pip install --upgrade twine ``` -------------------------------- ### Inline Link Example Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates creating an inline link with a URL and an optional title. ```markdown This is [an example](http://example.com/ "Title") inline link. ``` ```markdown [This link](http://example.net/) has no title attribute. ``` ```markdown See my [About](/about/) page for details. ``` -------------------------------- ### Horizontal Rule Examples Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Provides examples of creating horizontal rules using hyphens, asterisks, or underscores. ```markdown * * * ``` ```markdown *** ``` ```markdown ***** ``` ```markdown - - - ``` ```markdown --------------------------------------- ``` -------------------------------- ### AST JSON Output Example Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md The JSON representation of the Abstract Syntax Tree generated from the example markdown input. ```json { "type": "Document", "footnotes": {}, "line_number": 1, "children": [ { "type": "Heading", "line_number": 1, "level": 1, "children": [ { "type": "RawText", "content": "Heading 1" } ] }, { "type": "Paragraph", "line_number": 3, "children": [ { "type": "RawText", "content": "text" } ] }, { "type": "Heading", "line_number": 5, "level": 1, "children": [ { "type": "RawText", "content": "Heading 2" } ] }, { "type": "Paragraph", "line_number": 7, "children": [ { "type": "Link", "target": "https://www.example.com", "title": "", "children": [ { "type": "RawText", "content": "link" } ] } ] } ] } ``` -------------------------------- ### Log File Example Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/basic_blocks.md A sample log file snippet showing timestamped entries and indentation. Useful for understanding log file formats. ```log 2020-07-05 10:20:55 ... 2020-07-05 10:20:56 ... ... 2020-07-05 10:21:03 ... ``` -------------------------------- ### Install Grunt CLI Globally Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Install the Grunt command-line interface globally to manage custom builds and development tasks for jQuery. ```bash npm install -g grunt-cli ``` -------------------------------- ### Java Hello World Program Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/basic_blocks.md A standard Java program to print 'Hello World!' to the console. This is a common starting point for Java development. ```java public class Main { public static void main(String[] args) { System.out.println("Hello World!"); } } ``` -------------------------------- ### Execute Shell Command with Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Example of executing a shell command that processes Markdown. Ensure the script path and input are correctly handled. ```php return shell_exec("echo $input | $markdown_script"); ``` -------------------------------- ### Indented Code Block Example Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Shows how indentation is handled in code blocks. One level of indentation is removed from each line. ```applescript tell application "Foo" beep end tell ``` -------------------------------- ### CommonMark Example: Emphasis and Strong Emphasis Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md Demonstrates a CommonMark spec example where asterisks are used for emphasis and strong emphasis. This snippet shows the expected HTML output for a specific Markdown input. ```markdown ***foo** bar* ``` ```html

foo bar

``` -------------------------------- ### Atx-Style Headers Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use 1-6 hash characters at the start of a line for Atx-style headers. Optionally, closing hashes can be added for cosmetic purposes. ```markdown # This is an H1 ``` ```markdown ## This is an H2 ``` ```markdown ###### This is an H6 ``` ```markdown # This is an H1 # ``` ```markdown ## This is an H2 ## ``` ```markdown ### This is an H3 ###### ``` -------------------------------- ### Clone jQuery Repository Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Use this command to get a local copy of the jQuery source code from GitHub. ```bash git clone git://github.com/jquery/jquery.git ``` -------------------------------- ### Watch for Changes and Auto-Build Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Starts a watch process that automatically rebuilds jQuery whenever source files are modified. Essential for development workflows. ```bash grunt watch ``` -------------------------------- ### CommonMark Example: Code Span Precedence Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md Shows a CommonMark example where a code span has higher precedence than emphasis. This snippet illustrates the correct parsing of mixed inline elements. ```markdown *foo `bar* baz` ``` ```html

*foo bar* baz

``` -------------------------------- ### Mistune's Parsing of Code Span Precedence Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md Demonstrates how mistune parses the same Markdown input as the previous example, showing its different handling of precedence between code spans and emphasis. ```html

foo `bar baz`

``` -------------------------------- ### Pre-formatted Code Block Syntax Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Example of a pre-formatted code block in Markdown. Lines are interpreted literally and wrapped in `
` and `` tags. Indent each line by at least 4 spaces or 1 tab.

```markdown
    This is a code block.
```

--------------------------------

### Ordered List Syntax (Arbitrary Numbers)

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Shows that Markdown generates the same HTML output for ordered lists regardless of the numbers used in the source. It's recommended to start with '1' for clarity.

```markdown
3. Bird
1. McHale
8. Parish
```

--------------------------------

### QUnit Test Methods

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md

Provides essential methods for controlling the execution flow of QUnit tests. 'expect' sets the number of assertions, while 'stop' and 'start' manage asynchronous test execution.

```javascript
expect( numAssertions );
stop();
start();
```

--------------------------------

### Define a Basic Custom Span Token

Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md

Subclass SpanToken to create a new inline token type. No setup is required initially.

```python
from mistletoe.span_token import SpanToken

class GithubWiki(SpanToken):
    pass
```

--------------------------------

### Multi-line List Item with Hanging Indent

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Example of a list item with multiple lines, using hanging indents for readability. Markdown preserves the formatting.

```markdown
*   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
    viverra nec, fringilla in, laoreet vitae, risus.
*   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
    Suspendisse id sem consectetuer libero luctus adipiscing.
```

--------------------------------

### List Item with Multiple Paragraphs

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Example of a list item containing two paragraphs. Subsequent paragraphs must be indented by 4 spaces or one tab.

```markdown
1.  This is a list item with two paragraphs. Lorem ipsum dolor
    sit amet, consectetuer adipiscing elit. Aliquam hendrerit
    mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
    sit amet velit.

2.  Suspendisse id sem consectetuer libero luctus adipiscing.
```

--------------------------------

### Exclude Modules from jQuery Build

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md

Use the `grunt custom` command with a hyphenated list of module paths to exclude them from the build. For example, to exclude the AJAX and CSS modules.

```bash
grunt custom:-ajax,-css
```

--------------------------------

### Fire Native DOM Event with jQuery

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md

Use this function to trigger a native DOM event on an element selected by jQuery. Ensure the element is accessed via its index [0] to get the native DOM node.

```javascript
fireNative( node, eventType )
```

```javascript
fireNative( jQuery("#elem")[0], "click" );
```

--------------------------------

### Build Distribution Archives

Source: https://github.com/miyuchina/mistletoe/blob/master/cutting-a-release.md

Execute this command to build the sdist and Wheel files in the 'dist/' folder.

```bash
python -m build
```

--------------------------------

### Build jQuery with npm

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md

Navigate into the cloned directory and run the npm build script to create a distributable version of jQuery.

```bash
cd jquery && npm run build
```

--------------------------------

### Run Benchmarks with PyPy

Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md

Execute the benchmark script using PyPy to compare the performance of mistune and mistletoe. This highlights performance improvements when using PyPy.

```sh
pypy3 test/benchmark.py mistune mistletoe
Test document: test/samples/syntax.md
Test iterations: 1000
Running tests with mistune, mistletoe...
========================================
mistune: 9.720779
mistletoe: 21.984181399999997
# run with PyPy 3.7-v7.3.7 on MS Windows 10
```

--------------------------------

### Transpile Markdown to HTML via CLI

Source: https://github.com/miyuchina/mistletoe/blob/master/README.md

Use the mistletoe command-line utility to transpile a Markdown file to HTML and output to stdout.

```sh
mistletoe foo.md
```

--------------------------------

### Unordered List Syntax (Plus)

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Demonstrates the use of plus signs for creating unordered lists in Markdown. This is equivalent to using asterisk or hyphen markers.

```markdown
+   Red
+   Green
+   Blue
```

--------------------------------

### Unordered List Syntax (Asterisk)

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Demonstrates the use of asterisks for creating unordered lists in Markdown. This is equivalent to using plus or hyphen markers.

```markdown
*   Red
*   Green
*   Blue
```

--------------------------------

### Unordered List Syntax (Hyphen)

Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md

Demonstrates the use of hyphens for creating unordered lists in Markdown. This is equivalent to using asterisk or plus markers.

```markdown
-   Red
-   Green
-   Blue
```

--------------------------------

### Run Markdown Parser Benchmarks

Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md

Execute the benchmark script to compare parsing speeds of different Markdown libraries. Results are displayed in seconds.

```sh
python test/benchmark.py  # all results in seconds
Test document: test/samples/syntax.md
Test iterations: 1000
Running tests with markdown, mistune, commonmark, mistletoe...
==============================================================
markdown: 24.732995399739593   # v3.6 from Mar 14, 2024
mistune: 15.494156199973077    # v3.0.2 from Sep 30, 2023
commonmark: 22.344279299955815 # v0.9.1 from Oct 04, 2019
mistletoe: 20.372425000183284  # v1.4.0 from Jul 14, 2024
# run with Python 3.11.9 on MS Windows 10
```

--------------------------------

### Implement Custom Renderer Method

Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md

Define a render method named 'render_TOKENNAME' (e.g., 'render_github_wiki') to specify how the custom token should be converted to HTML. Use 'escape_url' for safety.

```python
from mistletoe.html_renderer import HtmlRenderer, escape_url

class GithubWikiRenderer(HtmlRenderer):
    def __init__(self):
        super().__init__(GithubWiki)

    def render_github_wiki(self, token):
        template = '{inner}'
        target = escape_url(token.target)
        inner = self.render_inner(token)
        return template.format(target=target, inner=inner)
```

--------------------------------

### Upload Distribution Archives to PyPi

Source: https://github.com/miyuchina/mistletoe/blob/master/cutting-a-release.md

This command uploads the built distribution archives to the Python Package Index (PyPi). Ensure you authenticate with your PyPi token.

```bash
python -m twine upload dist/*
```

--------------------------------

### Save Transpiled HTML to File via CLI

Source: https://github.com/miyuchina/mistletoe/blob/master/README.md

Redirect the HTML output from the mistletoe command-line utility to a file.

```sh
mistletoe foo.md > out.html
```

--------------------------------

### Use Custom Renderer via CLI

Source: https://github.com/miyuchina/mistletoe/blob/master/README.md

Specify a custom renderer, such as LaTeXRenderer, using the --renderer flag with the mistletoe command-line utility.

```sh
mistletoe foo.md --renderer mistletoe.latex_renderer.LaTeXRenderer
```

--------------------------------

### Mistletoe Interactive Mode (HTML Output)

Source: https://github.com/miyuchina/mistletoe/blob/master/README.md

Enter mistletoe's interactive mode by running 'mistletoe' without arguments. Type Markdown input and press Ctrl-D to see the HTML output. Use Ctrl-C to exit.

```html
mistletoe [version 0.7.2] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
>>> some **bold** text
... and some *italics*
...

some bold text and some italics

>>> ``` -------------------------------- ### Basic Unordered List Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/lists.md Demonstrates a simple unordered list with nested items. Use asterisks or hyphens for list items. ```markdown * fruit * apple * orange * Note: Orange is also a color. * lemon ``` -------------------------------- ### Create a Custom HTML Renderer Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Subclass HtmlRenderer and pass the custom token class to the superclass constructor to enable rendering for the new token type. ```python from mistletoe.html_renderer import HtmlRenderer class GithubWikiRenderer(HtmlRenderer): def __init__(self): super().__init__(GithubWiki) ``` -------------------------------- ### View Available Grunt Tasks Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Display a help message listing all available Grunt tasks for jQuery Core development. ```bash grunt -help ``` -------------------------------- ### Basic Markdown to HTML Rendering Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Render a Markdown file to HTML using mistletoe's default settings. This requires opening the file and passing the file handle to the markdown function. ```python import mistletoe with open('foo.md', 'r') as fin: rendered = mistletoe.markdown(fin) ``` -------------------------------- ### Setext-Style Headers Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Create Setext-style headers by underlining text with equal signs for H1 or dashes for H2. Any number of these characters will work. ```markdown This is an H1 ============== ``` ```markdown This is an H2 ------------- ``` -------------------------------- ### Build jQuery with Grunt Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Run the Grunt command in the jQuery directory to build a full version of the library, similar to 'npm run build'. ```bash grunt ``` -------------------------------- ### Configure Permanent Copy Destination Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Sets up a permanent destination for built jQuery files by creating a '.destination.json' file in the 'dist/' directory. This automates copying build artifacts to a specified location. ```json { "/Absolute/path/to/other/destination": true } ``` -------------------------------- ### Build jQuery and Copy to Special Location Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Builds the jQuery project and then copies the built files to a specified custom directory. Useful for integrating with other projects or for testing in different environments. ```bash grunt && grunt dist:/path/to/special/location/ ``` -------------------------------- ### Create Custom jQuery Build (Multiple Exclusions) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Creates a custom build of jQuery by excluding a specific list of modules. This allows for fine-grained control over the final jQuery package size and features. ```bash grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-event/alias,-offset,-wrap ``` -------------------------------- ### Mistletoe Interactive Mode with LaTeX Renderer Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Use mistletoe's interactive mode with a specified renderer, like LaTeXRenderer. Input Markdown and press Ctrl-D to see the rendered output. Use Ctrl-C to exit. ```latex mistletoe [version 0.7.2] (interactive) Type Ctrl-D to complete input, or Ctrl-C to exit. Using renderer: LaTeXRenderer >>> some **bold** text ... and some *italics* ... \documentclass{article} \begin{document} some \textbf{bold} text and some \textit{italics} \end{document} >>> ``` -------------------------------- ### Implicit Link Name Shortcut Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates the implicit link name shortcut where the link text is used as the identifier. ```markdown [Google][] ``` ```markdown [Google]: http://google.com/ ``` ```markdown Visit [Daring Fireball][] for more information. ``` -------------------------------- ### Reference-Style Link Definition Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Shows how to define reference-style links using an identifier and a URL, with an optional title. ```markdown This is [an example][id] reference-style link. ``` ```markdown This is [an example] [id] reference-style link. ``` ```markdown [id]: http://example.com/ "Optional Title Here" ``` ```markdown [foo]: http://example.com/ 'Optional Title Here' ``` ```markdown [foo]: http://example.com/ (Optional Title Here) ``` ```markdown [id]: "Optional Title Here" ``` ```markdown [id]: http://example.com/longish/path/to/resource/here "Optional Title Here" ``` ```markdown [link text][a] ``` ```markdown [link text][A] ``` -------------------------------- ### Ordered List Syntax (Non-Sequential) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates that Markdown ignores source numbering for ordered lists, producing consistent HTML output. Using sequential numbers is optional. ```markdown 1. Bird 1. McHale 1. Parish ``` -------------------------------- ### Basic Blockquote Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use email-style `>` characters at the beginning of lines for blockquotes. Hard wrapping text and prefixing each line with `>` is recommended for clarity. ```markdown > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse > id sem consectetuer libero luctus adipiscing. ``` -------------------------------- ### Markdown to LaTeX Rendering Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Render a Markdown file to LaTeX by specifying the LaTeXRenderer. Ensure the LaTeXRenderer is imported. ```python import mistletoe from mistletoe.latex_renderer import LaTeXRenderer with open('foo.md', 'r') as fin: rendered = mistletoe.markdown(fin, LaTeXRenderer) ``` -------------------------------- ### Markdown to Markdown Parsing and Rendering Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Process Markdown to an AST, modify it, and render it back to Markdown. This is useful for text replacements that should not affect code samples. ```python import mistletoe from mistletoe.block_token import BlockToken, Heading, Paragraph, SetextHeading from mistletoe.markdown_renderer import MarkdownRenderer from mistletoe.span_token import InlineCode, RawText, SpanToken def update_text(token: SpanToken): """Update the text contents of a span token and its children. `InlineCode` tokens are left unchanged.""" if isinstance(token, RawText): token.content = token.content.replace("mistletoe", "The Amazing mistletoe") if not isinstance(token, InlineCode) and token.children is not None: for child in token.children: update_text(child) def update_block(token: BlockToken): """Update the text contents of paragraphs and headings within this block, and recursively within its children.""" if isinstance(token, (Paragraph, SetextHeading, Heading)): for child in token.children: update_text(child) for child in token.children: if isinstance(child, BlockToken): update_block(child) with open("README.md", "r") as fin: with MarkdownRenderer() as renderer: document = mistletoe.Document(fin) update_block(document) md = renderer.render(document) print(md) ``` -------------------------------- ### Basic Code Block Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates a simple code block. Leading indentation is removed from each line. ```markdown This is a code block. ``` -------------------------------- ### Ordered List Syntax (Sequential) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Standard ordered list using sequential numbers and periods. Markdown generates HTML with correct numbering regardless of source numbering. ```markdown 1. Bird 2. McHale 3. Parish ``` -------------------------------- ### Create Custom jQuery Build (Exclude CSS) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Creates a custom build of jQuery excluding all CSS-related modules. This impacts features like animations and dimension calculations. ```bash grunt custom:-css ``` -------------------------------- ### View Markdown AST with AstRenderer Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Use the AstRenderer to inspect the parsed Abstract Syntax Tree (AST) of a markdown file. This is useful for understanding how mistletoe interprets markdown content. ```sh mistletoe text.md --renderer mistletoe.ast_renderer.AstRenderer ``` -------------------------------- ### Custom Token Parsing with HtmlRenderer Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Render an AST using HtmlRenderer, which also adds HtmlBlock and HtmlSpan tokens to the parsing process. The Document must be created within a 'with' block for the renderer. ```python from mistletoe import Document, HtmlRenderer with open('foo.md', 'r') as fin: with HtmlRenderer() as renderer: # or: `with HtmlRenderer(AnotherToken1, AnotherToken2) as renderer:` doc = Document(fin) # parse the lines into AST rendered = renderer.render(doc) # render the AST # internal lists of tokens to be parsed are automatically reset when exiting this `with` block ``` -------------------------------- ### Create Custom jQuery Build (Exclude Ajax) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Creates a custom build of jQuery excluding all AJAX functionality. This is useful for reducing build size when AJAX features are not needed. ```bash grunt custom:-ajax ``` -------------------------------- ### Use Contrib Renderer via CLI Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Specify a renderer from the contrib package, such as JiraRenderer, using the --renderer flag with the mistletoe command-line utility. ```sh mistletoe foo.md --renderer mistletoe.contrib.jira_renderer.JiraRenderer ``` -------------------------------- ### Inline Image Syntax Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use inline image syntax for images where the URL is directly included. An optional title can be provided in quotes. ```markdown ![Alt text](/path/to/img.jpg) ``` ```markdown ![Alt text](/path/to/img.jpg "Optional title") ``` -------------------------------- ### Automatic URL Link Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Create clickable links for URLs by enclosing them in angle brackets. Markdown automatically generates the anchor tag. ```html ``` -------------------------------- ### Render Markdown with Custom Tokens Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Use renderers as context managers to ensure custom tokens are cleaned up properly. This allows for parsing multiple Markdown documents with different token types in the same program. ```python from mistletoe import Document from contrib.github_wiki import GithubWikiRenderer with open('foo.md', 'r') as fin: with GithubWikiRenderer() as renderer: rendered = renderer.render(Document(fin)) ``` -------------------------------- ### Run Tests in an Iframe with jQuery Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Use `testIframe` to execute tests within a separate iframe. This is helpful for tests requiring a distinct document context. The callback function receives QUnit assert, iframe's jQuery, window, and document objects. ```javascript testIframe( testName, fileName, function testCallback( assert, jQuery, window, document, [ additional args ] ) { ... } ); ``` -------------------------------- ### Implement Custom Span Token Constructor Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Store relevant data from the regex match object in the token's constructor. The target is extracted from the second group of the regex match. ```python from mistletoe.span_token import SpanToken class GithubWiki(SpanToken): pattern = re.compile(r"[[] *(.+?) *| *(.+?) *[]]") def __init__(self, match_obj): self.target = match_obj.group(2) ``` -------------------------------- ### List Items Separated by Blank Lines Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Shows how blank lines between list items cause Markdown to wrap each item in `

` tags, affecting the HTML output. ```markdown * Bird * Magic ``` -------------------------------- ### Mistune's Greedy Parsing of Emphasis Source: https://github.com/miyuchina/mistletoe/blob/master/performance.md Illustrates how mistune (version 0.8.3) might greedily parse emphasis, leading to incorrect output for complex asterisk usage compared to CommonMark compliant parsers. ```html

*foo bar*

``` -------------------------------- ### Combined Ordered and Unordered List with Code Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/lists.md Illustrates a combined list featuring an ordered list with nested unordered lists. Includes an embedded code block within a list item. ```markdown 1. firstly 2. secondly * s-first another paragraph in s-first > line quote in s-first * s-second ``` with some code block in s-second ``` 3. thirdly ``` -------------------------------- ### HTML Encoding in Code Blocks Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Illustrates automatic HTML entity encoding for ampersands and angle brackets within code blocks. ```html ``` -------------------------------- ### List Item with Lazy Paragraph Indentation Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates that only the first line of a subsequent paragraph in a list item needs to be indented. Markdown handles the rest. ```markdown * This is a list item with two paragraphs. This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Another item in the same list. ``` -------------------------------- ### Reference-Style Links in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Define links using numbered references. Place definitions at the end of the document or after their usage. ```markdown I get 10 times more traffic from [Google][1] than from [Yahoo][2] or [MSN][3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" ``` -------------------------------- ### Inline Links in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Create links directly within the text using the format [Link Text](URL "Optional Title"). ```markdown I get 10 times more traffic from [Google](http://google.com/ "Google") than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or [MSN](http://msn.com/ "MSN Search"). ``` -------------------------------- ### Replace Sizzle Selector Engine Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md To replace the Sizzle selector engine with the browser's native `querySelectorAll`, use the `-sizzle` flag. This will use a more basic selector engine. ```bash grunt custom:-sizzle ``` -------------------------------- ### Add Regex Pattern to Custom Span Token Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Define the 'pattern' class variable with a compiled regex to identify the token in the document. The __init__ method is a placeholder. ```python import re from mistletoe.span_token import SpanToken class GithubWiki(SpanToken): pattern = re.compile(r"[[] *(.+?) *| *(.+?) *[]]") def __init__(self, match): pass ``` -------------------------------- ### QUnit Test Assertions Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md A collection of assertion methods provided by QUnit for validating test conditions. These include checks for truthiness, equality (strict and deep), and exceptions. ```javascript ok( value, [message] ); equal( actual, expected, [message] ); notEqual( actual, expected, [message] ); deepEqual( actual, expected, [message] ); notDeepEqual( actual, expected, [message] ); strictEqual( actual, expected, [message] ); notStrictEqual( actual, expected, [message] ); throws( block, [expected], [message] ); ``` -------------------------------- ### jQuery Test Helper: Select Elements by ID Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md A convenience function 'q' used in jQuery's test suite to select DOM elements by their IDs and return them as an array. Useful for setting up test environments. ```javascript q( ... ); ``` -------------------------------- ### HTML Entities in Code Span (Markdown) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates the encoding of HTML entities within Markdown code spans. ```markdown `—` is the decimal-encoded equivalent of `—`. ``` -------------------------------- ### Reflow Markdown with Custom Line Length Source: https://github.com/miyuchina/mistletoe/blob/master/README.md Reflow Markdown text to a specific line length using the MarkdownRenderer. This involves importing MarkdownRenderer and using a 'with' statement for the renderer. ```python import mistletoe from mistletoe.markdown_renderer import MarkdownRenderer with open('dev-guide.md', 'r') as fin: with MarkdownRenderer(max_line_length=20) as renderer: print(renderer.render(mistletoe.Document(fin))) ``` -------------------------------- ### Blockquote within a List Item Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Shows how to include a blockquote inside a list item. The blockquote's delimiters (`>`) must be indented along with the content. ```markdown * A list item with a blockquote: > This is a blockquote > inside a list item. ``` -------------------------------- ### Using Inline HTML in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Block-level HTML elements must be separated by blank lines and not indented. Markdown syntax is not processed within these blocks. ```html
Foo
``` -------------------------------- ### Reference-Style Image Syntax Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Reference-style images use an ID to link to a separately defined image reference. This keeps the main text cleaner. ```markdown ![Alt text][id] ``` ```markdown [id]: url/to/image "Optional title attribute" ``` -------------------------------- ### Configure Git to Auto Rebase Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Configures Git to automatically use the '--rebase' flag for 'git pull' operations on branches. This helps maintain a cleaner commit history when working with feature branches. ```bash git config branch.autosetuprebase local ``` -------------------------------- ### Preventing Accidental Ordered List Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Illustrates how to prevent Markdown from interpreting a number followed by a period and space as an ordered list marker by escaping the period. ```markdown 1986\. What a great season. ``` -------------------------------- ### Set Custom AMD Module Name Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Specify a custom name for jQuery's AMD definition using the `--amd` option. This is useful for avoiding conflicts with other libraries. ```bash grunt custom --amd="custom-name" ``` -------------------------------- ### Spaced Unordered List Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/lists.md Shows an unordered list with extra spacing between items and nested elements. Spacing does not affect rendering. ```markdown * vegetable * carrot * cucumber ``` -------------------------------- ### Strong Emphasis with Double Underscores in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Wrap text with double underscores (__) for bold emphasis, which renders as HTML tags. ```markdown __double underscores__ ``` -------------------------------- ### Lazy Blockquote Formatting Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Markdown allows for lazy blockquote formatting where `>` is only required on the first line of a hard-wrapped paragraph. ```markdown > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. ``` -------------------------------- ### Implicit Link Name Shortcut in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use implicit link names by omitting the number in the reference. The link text is used as the reference name. ```markdown I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [google]: http://google.com/ "Google" [yahoo]: http://search.yahoo.com/ "Yahoo Search" [msn]: http://search.msn.com/ "MSN Search" ``` -------------------------------- ### Multi-line List Item without Hanging Indent Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates that hanging indents are optional for multi-line list items. Markdown will still format them correctly. ```markdown * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. ``` -------------------------------- ### Strong Emphasis with Double Asterisks in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Wrap text with double asterisks (**) for bold emphasis, which renders as HTML tags. ```markdown **double asterisks** ``` -------------------------------- ### Reset Working Directory to Upstream Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Resets the local Git working directory to match the state of the 'upstream/master' branch, discarding all local changes and untracked files. Use with caution. ```bash git reset --hard upstream/master git clean -fdx ``` -------------------------------- ### Escape Ampersands in URLs Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md When including URLs with ampersands in Markdown, encode them as `&` to ensure correct HTML rendering. This is crucial for HTML validation. ```html http://images.google.com/images?num=30&q=larry+bird ``` -------------------------------- ### Code Block within a List Item Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Demonstrates embedding a code block within a list item. The code block must be indented twice (8 spaces or two tabs) relative to the list marker. ```markdown * A list item with a code block: ``` -------------------------------- ### Define Anonymous AMD Module Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md To define the jQuery AMD module anonymously, set the `--amd` option to an empty string. This can be useful in certain module loading scenarios. ```bash grunt custom --amd="" ``` -------------------------------- ### Code Span in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use single backticks (`) to denote inline code, which renders as HTML tags. ```markdown Use the `printf()` function. ``` -------------------------------- ### Blockquote with Header Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Blockquotes can contain other Markdown elements, such as headers. Ensure the `>` prefix is applied to each line of the nested element. ```markdown > ## This is a header. ``` -------------------------------- ### Automatic Email Link with Obfuscation Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Automatic email links are obfuscated using entity encoding to help prevent spam harvesting. The rendering is identical to a standard mailto link. ```html ``` -------------------------------- ### Emphasis with Single Underscores in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Wrap text with single underscores (_) for italic emphasis, which renders as HTML tags. ```markdown _single underscores_ ``` -------------------------------- ### Configure Span Token Parsing Behavior Source: https://github.com/miyuchina/mistletoe/blob/master/dev-guide.md Set 'parse_group' and 'parse_inner' to control how child tokens are parsed within the custom token. 'precedence' affects parsing order. ```python class SpanToken: parse_group = 1 parse_inner = True precedence = 5 ``` -------------------------------- ### Nested Blockquotes Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Blockquotes can be nested by adding additional levels of `>` characters. ```markdown > This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level. ``` -------------------------------- ### Emphasis with Single Asterisks in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Wrap text with single asterisks (*) for italic emphasis, which renders as HTML tags. ```markdown *single asterisks* ``` -------------------------------- ### Add Random Number to URL to Prevent Caching Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md Appends a random number as a query parameter to a URL to bypass browser caching. This is useful for ensuring fresh data is loaded. ```javascript url( "some/url.php" ); ``` ```javascript url("data/test.html"); => "data/test.html?10538358428943" url("data/test.php?foo=bar"); => "data/test.php?foo=bar&10538358345554" ``` -------------------------------- ### Escaped Literal Asterisk in Markdown Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md To display a literal asterisk that would otherwise be interpreted as emphasis, precede it with a backslash. ```markdown \*this text is surrounded by literal asterisks\* ``` -------------------------------- ### jQuery Test Helper: Assert Selection by IDs Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/jquery.md A test helper function 't' that asserts whether a given DOM selector matches a specific set of element IDs. It takes a test name, the selector, and an array of expected IDs. ```javascript t( testName, selector, [ "array", "of", "ids" ] ); ``` -------------------------------- ### HTML Tag in Code Span (Markdown) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Markdown automatically encodes ampersands and angle brackets in code spans, making it easy to include HTML tags. ```markdown Please don't use any `` tags. ``` -------------------------------- ### Literal Backtick in Code Span (Markdown) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md To include a literal backtick within a code span, use multiple backticks as delimiters. ```markdown ``There is a literal backtick (`) here.`` ``` -------------------------------- ### List of Backslash Escapable Characters Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Markdown supports backslash escapes for a variety of characters that have special meaning in its syntax. ```markdown \\ backslash ` backtick * asterisk _ underscore {} curly braces [] square brackets () parentheses # hash mark + plus sign - minus sign (hyphen) . dot ! exclamation mark ``` -------------------------------- ### Backslash Escape for Literal Asterisks Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Use backslash escapes to render special Markdown characters, like asterisks, as literal characters instead of formatting elements. ```markdown \*literal asterisks\* ``` -------------------------------- ### Backtick Delimiters with Spaces in Code Span (Markdown) Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Code span delimiters can include spaces, allowing literal backticks at the beginning or end of the span. ```markdown A single backtick in a code span: `` ` `` A backtick-delimited string in a code span: `` `foo` `` ``` -------------------------------- ### Markdown Auto-Escaping Source: https://github.com/miyuchina/mistletoe/blob/master/test/samples/syntax.md Markdown automatically escapes ampersands and angle brackets within code spans and blocks to facilitate writing about HTML. ```markdown © ``` ```markdown AT&T ``` ```markdown 4 < 5 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.