CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pymdown-extensions

Extension pack for Python Markdown that provides 20+ specialized extensions for enhanced text processing.

Pending
Overview
Eval results
Files

text-enhancement.mddocs/

Text Enhancement Extensions

Extensions that enhance text formatting capabilities including better emphasis handling, insert/delete markup, superscript/subscript support, text highlighting, and intelligent symbol replacement.

Capabilities

Better Emphasis (BetterEm)

Provides enhanced emphasis handling with improved asterisk and underscore processing, offering more control over bold and italic formatting behavior.

def makeExtension(**kwargs):
    """
    Create BetterEm extension with configurable emphasis handling.
    
    Configuration:
    - smart_enable: str - Enable smart processing ("underscore", "asterisk", "all")
    
    Returns:
    BetterEmExtension instance
    """

class BetterEmExtension(Extension):
    """Enhanced emphasis handling extension."""

class AsteriskProcessor(PatternSequenceProcessor):
    """Processes asterisk emphasis patterns."""

class UnderscoreProcessor(PatternSequenceProcessor):
    """Processes underscore emphasis patterns."""

class SmartAsteriskProcessor(PatternSequenceProcessor):
    """Smart asterisk emphasis processor."""

class SmartUnderscoreProcessor(PatternSequenceProcessor):
    """Smart underscore emphasis processor."""

Usage Example:

import markdown

# Basic usage
md = markdown.Markdown(extensions=['pymdownx.betterem'])

# With smart processing enabled for all types
md = markdown.Markdown(extensions=[
    'pymdownx.betterem'
], extension_configs={
    'pymdownx.betterem': {
        'smart_enable': 'all'
    }
})

text = "This is **bold** and *italic* text with better_handling."
html = md.convert(text)

Caret (Insert and Superscript)

Adds support for insert tags and superscript formatting using caret (^) syntax, providing semantic markup for text additions and mathematical superscripts.

def makeExtension(**kwargs):
    """
    Create Caret extension for insert and superscript support.
    
    Configuration:
    - smart_insert: bool - Enable smart insert processing (True)
    - insert: bool - Enable insert tag support (True)
    - superscript: bool - Enable superscript support (True)
    
    Returns:
    InsertSupExtension instance
    """

class InsertSupExtension(Extension):
    """Insert and superscript extension."""

class CaretProcessor(PatternSequenceProcessor):
    """Full caret processing for both insert and superscript."""

class CaretSupProcessor(PatternSequenceProcessor):
    """Superscript-only caret processor."""

class CaretInsertProcessor(PatternSequenceProcessor):
    """Insert-only caret processor."""

Usage Example:

import markdown

md = markdown.Markdown(extensions=['pymdownx.caret'])

# Insert syntax: ^^inserted text^^
# Superscript syntax: ^superscript^
text = "E = mc^^2^^ and H^^+^^ ion concentration"
html = md.convert(text)

Tilde (Delete and Subscript)

Enables delete/strikethrough and subscript formatting using tilde (~) syntax, providing semantic markup for text deletions and chemical/mathematical subscripts.

def makeExtension(**kwargs):
    """
    Create Tilde extension for delete and subscript support.
    
    Configuration:
    - smart_delete: bool - Enable smart delete processing (True)
    - delete: bool - Enable delete tag support (True)
    - subscript: bool - Enable subscript support (True)
    
    Returns:
    DeleteSubExtension instance
    """

class DeleteSubExtension(Extension):
    """Delete and subscript extension."""

class TildeProcessor(PatternSequenceProcessor):
    """Full tilde processing for both delete and subscript."""

class TildeDeleteProcessor(PatternSequenceProcessor):
    """Delete-only tilde processor."""

class TildeSubProcessor(PatternSequenceProcessor):
    """Subscript-only tilde processor."""

Usage Example:

import markdown

md = markdown.Markdown(extensions=['pymdownx.tilde'])

# Delete syntax: ~~deleted text~~
# Subscript syntax: ~subscript~
text = "H~2~O is ~~not~~ water"
html = md.convert(text)

Mark (Text Highlighting)

Provides text highlighting capabilities using mark tags, enabling visual emphasis through background highlighting.

def makeExtension(**kwargs):
    """
    Create Mark extension for text highlighting.
    
    Configuration:
    - smart_mark: bool - Enable smart mark processing (True)
    
    Returns:
    MarkExtension instance
    """

class MarkExtension(Extension):
    """Text highlighting extension."""

class MarkProcessor(PatternSequenceProcessor):
    """Mark text processor."""

class MarkSmartProcessor(PatternSequenceProcessor):
    """Smart mark processor."""

Usage Example:

import markdown

md = markdown.Markdown(extensions=['pymdownx.mark'])

# Highlighting syntax: ==highlighted text==
text = "This is ==important information== to remember."
html = md.convert(text)

Smart Symbols

Automatically replaces ASCII character sequences with their Unicode symbol equivalents, enhancing typography with proper symbols for fractions, arrows, quotes, and other special characters.

def makeExtension(**kwargs):
    """
    Create SmartSymbols extension for intelligent symbol replacement.
    
    Configuration:
    - smart_symbols: str - Symbol categories to enable
    - symbols: dict - Custom symbol mappings
    
    Returns:
    SmartSymbolsExtension instance
    """

class SmartSymbolsExtension(Extension):
    """Smart symbol replacement extension."""

class SmartSymbolsTreeprocessor(Treeprocessor):
    """Symbol replacement processor."""

Usage Example:

import markdown

md = markdown.Markdown(extensions=['pymdownx.smartsymbols'])

# Automatic replacements:
# --> becomes →
# <-- becomes ←
# 1/2 becomes ½
# (c) becomes ©
text = "Copyright (c) 2023. Go to page --> or back <--. Mix 1/2 cup."
html = md.convert(text)

Common Configuration Patterns

Smart Processing Configuration

Many text enhancement extensions support "smart" processing modes:

extension_configs = {
    'pymdownx.betterem': {'smart_enable': 'all'},
    'pymdownx.caret': {'smart_insert': True},
    'pymdownx.tilde': {'smart_delete': True},
    'pymdownx.mark': {'smart_mark': True}
}

Selective Feature Enabling

Extensions can be configured to enable specific features:

extension_configs = {
    'pymdownx.caret': {
        'insert': True,      # Enable insert tags
        'superscript': False  # Disable superscript
    },
    'pymdownx.tilde': {
        'delete': True,      # Enable delete tags
        'subscript': False   # Disable subscript
    }
}

Types

from pymdownx.util import PatternSequenceProcessor, PatSeqItem
from markdown import Extension, Treeprocessor

# Configuration types
SmartEnableList = List[str]  # List of characters for smart processing
SymbolDict = Dict[str, str]  # Symbol replacement mappings
ConfigBool = bool           # Boolean configuration option

Install with Tessl CLI

npx tessl i tessl/pypi-pymdown-extensions

docs

advanced-blocks.md

code-and-math.md

content-structure.md

index.md

linking-and-media.md

text-enhancement.md

utilities-specialized.md

tile.json