‹› markdown.inlinepatterns

In version 3.0, a new, more flexible inline processor was added, markdown.inlinepatterns.InlineProcessor. The original inline patterns, which inherit from markdown.inlinepatterns.Pattern or one of its children are still supported, though users are encouraged to migrate.

The new InlineProcessor provides two major enhancements to Patterns:

  1. Inline Processors no longer need to match the entire block, so regular expressions no longer need to start with r'^(.*?)' and end with r'(.*?)%'. This runs faster. The returned Match object will only contain what is explicitly matched in the pattern, and extension pattern groups now start with m.group(1).

  2. The handleMatch method now takes an additional input called data, which is the entire block under analysis, not just what is matched with the specified pattern. The method now returns the element and the indexes relative to data that the return element is replacing (usually m.start(0) and m.end(0)). If the boundaries are returned as None, it is assumed that the match did not take place, and nothing will be altered in data.

    This allows handling of more complex constructs than regular expressions can handle, e.g., matching nested brackets, and explicit control of the span “consumed” by the processor.

‹› markdown.inlinepatterns.build_inlinepatterns(md: Markdown, **kwargs: Any) -> util.Registry[InlineProcessor]

Build the default set of inline patterns for Markdown.

The order in which processors and/or patterns are applied is very important - e.g. if we first replace http://.../ links with <a> tags and then try to replace inline HTML, we would end up with a mess. So, we apply the expressions in the following order:

  • backticks and escaped characters have to be handled before everything else so that we can preempt any markdown patterns by escaping them;

  • then we handle the various types of links (auto-links must be handled before inline HTML);

  • then we handle inline HTML. At this point we will simply replace all inline HTML strings with a placeholder and add the actual HTML to a stash;

  • finally we apply strong, emphasis, etc.

Return a Registry instance which contains the following collection of classes with their assigned names and priorities.

Class Instance Name Priority
BacktickInlineProcessor(BACKTICK_RE) backtick 190
EscapeInlineProcessor(ESCAPE_RE) escape 180
ReferenceInlineProcessor(REFERENCE_RE) reference 170
LinkInlineProcessor(LINK_RE) link 160
ImageInlineProcessor(IMAGE_LINK_RE) image_link 150
ImageReferenceInlineProcessor(IMAGE_REFERENCE_RE) image_reference 140
ShortReferenceInlineProcessor(REFERENCE_RE) short_reference 130
ShortImageReferenceInlineProcessor(IMAGE_REFERENCE_RE) short_image_ref 125
AutolinkInlineProcessor(AUTOLINK_RE) autolink 120
AutomailInlineProcessor(AUTOMAIL_RE) automail 110
SubstituteTagInlineProcessor(LINE_BREAK_RE) linebreak 100
HtmlInlineProcessor(HTML_RE) html 90
HtmlInlineProcessor(ENTITY_RE) entity 80
SimpleTextInlineProcessor(NOT_STRONG_RE) not_strong 70
AsteriskProcessor("\*") em_strong 60
UnderscoreProcessor("_") em_strong2 50

‹› markdown.inlinepatterns.NOIMG module-attribute

Match not an image. Partial regular expression which matches if not preceded by !.

Defined Value:

NOIMG = r'(?<!\!)'

‹› markdown.inlinepatterns.BACKTICK_RE module-attribute

Match backtick quoted string (`e=f()` or ``e=f("`")``).

Defined Value:

BACKTICK_RE = r'(?:(?<!\\)((?:\\{2})+)(?=`+)|(?<!\\)(`+)(.+?)(?<!`)\2(?!`))'

‹› markdown.inlinepatterns.ESCAPE_RE module-attribute

Match a backslash escaped character (\< or \*).

Defined Value:

ESCAPE_RE = r'\\(.)'

‹› markdown.inlinepatterns.EMPHASIS_RE module-attribute

Match emphasis with an asterisk (*emphasis*).

Defined Value:

EMPHASIS_RE = r'(\*)([^\*]+)\1'

‹› markdown.inlinepatterns.STRONG_RE module-attribute

Match strong with an asterisk (**strong**).

Defined Value:

STRONG_RE = r'(\*{2})(.+?)\1'

‹› markdown.inlinepatterns.SMART_STRONG_RE module-attribute

Match strong with underscore while ignoring middle word underscores (__smart__strong__).

Defined Value:

SMART_STRONG_RE = r'(?<!\w)(_{2})(?!_)(.+?)(?<!_)\1(?!\w)'

‹› markdown.inlinepatterns.SMART_EMPHASIS_RE module-attribute

Match emphasis with underscore while ignoring middle word underscores (_smart_emphasis_).

Defined Value:

SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\1(?!\w)'

‹› markdown.inlinepatterns.SMART_STRONG_EM_RE module-attribute

Match strong emphasis with underscores (__strong _em__).

Defined Value:

SMART_STRONG_EM_RE = r'(?<!\w)(\_)\1(?!\1)(.+?)(?<!\w)\1(?!\1)(.+?)\1{3}(?!\w)'

‹› markdown.inlinepatterns.EM_STRONG_RE module-attribute

Match emphasis strong with asterisk (***strongem*** or ***em*strong**).

Defined Value:

EM_STRONG_RE = r'(\*)\1{2}(.+?)\1(.*?)\1{2}'

‹› markdown.inlinepatterns.EM_STRONG2_RE module-attribute

Match emphasis strong with underscores (___emstrong___ or ___em_strong__).

Defined Value:

EM_STRONG2_RE = r'(_)\1{2}(.+?)\1(.*?)\1{2}'

‹› markdown.inlinepatterns.STRONG_EM_RE module-attribute

Match strong emphasis with asterisk (***strong**em*).

Defined Value:

STRONG_EM_RE = r'(\*)\1{2}(.+?)\1{2}(.*?)\1'

‹› markdown.inlinepatterns.STRONG_EM2_RE module-attribute

Match strong emphasis with underscores (___strong__em_).

Defined Value:

STRONG_EM2_RE = r'(_)\1{2}(.+?)\1{2}(.*?)\1'

‹› markdown.inlinepatterns.STRONG_EM3_RE module-attribute

Match strong emphasis with asterisk (**strong*em***).

Defined Value:

STRONG_EM3_RE = r'(\*)\1(?!\1)([^*]+?)\1(?!\1)(.+?)\1{3}'

Match start of in-line link ([text](url) or [text](<url>) or [text](url "title")).

Defined Value:

LINK_RE = NOIMG + r'\['

Match start of in-line image link (![alttxt](url) or ![alttxt](<url>)).

Defined Value:

IMAGE_LINK_RE = r'\!\['

‹› markdown.inlinepatterns.REFERENCE_RE module-attribute

Match start of reference link ([Label][3]).

Defined Value:

REFERENCE_RE = LINK_RE

‹› markdown.inlinepatterns.IMAGE_REFERENCE_RE module-attribute

Match start of image reference (![alt text][2]).

Defined Value:

IMAGE_REFERENCE_RE = IMAGE_LINK_RE

‹› markdown.inlinepatterns.NOT_STRONG_RE module-attribute

Match a stand-alone * or _.

Defined Value:

NOT_STRONG_RE = r'((^|(?<=\s))(\*{1,3}|_{1,3})(?=\s|$))'

Match an automatic link (<http://www.example.com>).

Defined Value:

AUTOLINK_RE = r'<((?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^<>]*)>'

‹› markdown.inlinepatterns.AUTOMAIL_RE module-attribute

Match an automatic email link (<me@example.com>).

Defined Value:

AUTOMAIL_RE = r'<([^<> !]+@[^@<> ]+)>'

‹› markdown.inlinepatterns.HTML_RE module-attribute

Match an HTML tag (<...>).

Defined Value:

HTML_RE = r'(<(\/?[a-zA-Z][^<>@ ]*( [^<>]*)?|!--(?:(?!<!--|-->).)*--)>)'

‹› markdown.inlinepatterns.ENTITY_RE module-attribute

Match an HTML entity (&#38; (decimal) or &#x26; (hex) or &amp; (named)).

Defined Value:

ENTITY_RE = r'(&(?:\#[0-9]+|\#x[0-9a-fA-F]+|[a-zA-Z0-9]+);)'

‹› markdown.inlinepatterns.LINE_BREAK_RE module-attribute

Match two spaces at end of line.

Defined Value:

LINE_BREAK_RE = r'  \n'

‹› markdown.inlinepatterns.dequote(string: str) -> str

Remove quotes from around a string.

‹› markdown.inlinepatterns.EmStrongItem

Bases: NamedTuple

Emphasis/strong pattern item.

‹› markdown.inlinepatterns.Pattern(pattern: str, md: Markdown | None = None)

Base class that inline patterns subclass.

Inline patterns are handled by means of Pattern subclasses, one per regular expression. Each pattern object uses a single regular expression and must support the following methods: getCompiledRegExp and handleMatch.

All the regular expressions used by Pattern subclasses must capture the whole block. For this reason, they all start with ^(.*) and end with (.*)!. When passing a regular expression on class initialization, the ^(.*) and (.*)! are added automatically and the regular expression is pre-compiled.

It is strongly suggested that the newer style markdown.inlinepatterns.InlineProcessor that use a more efficient and flexible search approach be used instead. However, the older style Pattern remains for backward compatibility with many existing third-party extensions.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.Pattern.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.Pattern.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.Pattern.handleMatch(m: re.Match[str]) -> etree.Element | str

Return a ElementTree element from the given match.

Subclasses should override this method.

Parameters:

  • m (Match[str]) –

    A match object containing a match of the pattern.

Returns: An ElementTree Element object.

‹› markdown.inlinepatterns.Pattern.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.Pattern.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.InlineProcessor(pattern: str, md: Markdown | None = None)

Bases: Pattern

Base class that inline processors subclass.

This is the newer style inline processor that uses a more efficient and flexible search approach.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.InlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.InlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.InlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.InlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.InlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | str | None, int | None, int | None]

Return a ElementTree element from the given match and the start and end index of the matched text.

If start and/or end are returned as None, it will be assumed that the processor did not find a valid region of text.

Subclasses should override this method.

Parameters:

  • m (Match[str]) –

    A re match object containing a match of the pattern.

  • data (str) –

    The buffer currently under analysis.

Returns:

  • el ( Element | str | None ) –

    The ElementTree element, text or None.

  • start ( int | None ) –

    The start of the region that has been matched or None.

  • end ( int | None ) –

    The end of the region that has been matched or None.

‹› markdown.inlinepatterns.SimpleTextPattern(pattern: str, md: Markdown | None = None)

Bases: Pattern

Return a simple text of group(2) of a Pattern.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.SimpleTextPattern.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SimpleTextPattern.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SimpleTextPattern.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SimpleTextPattern.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SimpleTextPattern.handleMatch(m: re.Match[str]) -> str

Return string content of group(2) of a matching pattern.

‹› markdown.inlinepatterns.SimpleTextInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Return a simple text of group(1) of a Pattern.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.SimpleTextInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SimpleTextInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SimpleTextInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SimpleTextInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SimpleTextInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[str, int, int]

Return string content of group(1) of a matching pattern.

‹› markdown.inlinepatterns.EscapeInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Return an escaped character.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.EscapeInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.EscapeInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.EscapeInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.EscapeInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.EscapeInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[str | None, int, int]

If the character matched by group(1) of a pattern is in ESCAPED_CHARS then return the integer representing the character’s Unicode code point (as returned by ord) wrapped in util.STX and util.ETX.

If the matched character is not in ESCAPED_CHARS, then return None.

‹› markdown.inlinepatterns.SimpleTagPattern(pattern: str, tag: str)

Bases: Pattern

Return element of type tag with a text attribute of group(3) of a Pattern.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.SimpleTagPattern.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SimpleTagPattern.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SimpleTagPattern.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SimpleTagPattern.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SimpleTagPattern.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.SimpleTagPattern.handleMatch(m: re.Match[str]) -> etree.Element

Return Element of type tag with the string in group(3) of a matching pattern as the Element’s text.

‹› markdown.inlinepatterns.SimpleTagInlineProcessor(pattern: str, tag: str)

Bases: InlineProcessor

Return element of type tag with a text attribute of group(2) of a Pattern.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.SimpleTagInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element, int, int]

Return Element of type tag with the string in group(2) of a matching pattern as the Element’s text.

‹› markdown.inlinepatterns.SubstituteTagPattern(pattern: str, tag: str)

Bases: SimpleTagPattern

Return an element of type tag with no children.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.SubstituteTagPattern.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SubstituteTagPattern.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SubstituteTagPattern.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SubstituteTagPattern.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SubstituteTagPattern.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.SubstituteTagPattern.handleMatch(m: re.Match[str]) -> etree.Element

Return empty Element of type tag.

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor(pattern: str, tag: str)

Bases: SimpleTagInlineProcessor

Return an element of type tag with no children.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.SubstituteTagInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element, int, int]

Return empty Element of type tag.

‹› markdown.inlinepatterns.BacktickInlineProcessor(pattern: str)

Bases: InlineProcessor

Return a <code> element containing the escaped matching text.

‹› markdown.inlinepatterns.BacktickInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.BacktickInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.BacktickInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.BacktickInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.BacktickInlineProcessor.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = 'code'

‹› markdown.inlinepatterns.BacktickInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | str, int, int]

If the match contains group(3) of a pattern, then return a code Element which contains HTML escaped text (with code_escape) as an AtomicString.

If the match does not contain group(3) then return the text of group(1) backslash escaped.

‹› markdown.inlinepatterns.DoubleTagPattern(pattern: str, tag: str)

Bases: SimpleTagPattern

Return a ElementTree element nested in tag2 nested in tag1.

Useful for strong emphasis etc.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.DoubleTagPattern.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.DoubleTagPattern.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.DoubleTagPattern.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.DoubleTagPattern.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.DoubleTagPattern.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.DoubleTagPattern.handleMatch(m: re.Match[str]) -> etree.Element

Return Element in following format: <tag1><tag2>group(3)</tag2>group(4)</tag2> where group(4) is optional.

‹› markdown.inlinepatterns.DoubleTagInlineProcessor(pattern: str, tag: str)

Bases: SimpleTagInlineProcessor

Return a ElementTree element nested in tag2 nested in tag1.

Useful for strong emphasis etc.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • tag (str) –

    Tag of element.

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.tag instance-attribute

The tag of the rendered element.

Defined Value:

self.tag = tag

‹› markdown.inlinepatterns.DoubleTagInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element, int, int]

Return Element in following format: <tag1><tag2>group(2)</tag2>group(3)</tag2> where group(3) is optional.

‹› markdown.inlinepatterns.HtmlInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Store raw inline html and return a placeholder.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.HtmlInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.HtmlInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.HtmlInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.HtmlInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[str, int, int]

Store the text of group(1) of a pattern and return a placeholder string.

‹› markdown.inlinepatterns.HtmlInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.HtmlInlineProcessor.backslash_unescape(text: str) -> str

Return text with backslash escapes undone (backslashes are restored).

‹› markdown.inlinepatterns.AsteriskProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Emphasis processor for handling strong and em matches inside asterisks.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.AsteriskProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.AsteriskProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.AsteriskProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.AsteriskProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.AsteriskProcessor.PATTERNS class-attribute instance-attribute

The various strong and emphasis patterns handled by this processor.

Defined Value:

PATTERNS = [
    EmStrongItem(re.compile(EM_STRONG_RE, re.DOTALL | re.UNICODE), 'double', 'strong,em'),
    EmStrongItem(re.compile(STRONG_EM_RE, re.DOTALL | re.UNICODE), 'double', 'em,strong'),
    EmStrongItem(re.compile(STRONG_EM3_RE, re.DOTALL | re.UNICODE), 'double2', 'strong,em'),
    EmStrongItem(re.compile(STRONG_RE, re.DOTALL | re.UNICODE), 'single', 'strong'),
    EmStrongItem(re.compile(EMPHASIS_RE, re.DOTALL | re.UNICODE), 'single', 'em')
]

‹› markdown.inlinepatterns.AsteriskProcessor.build_single(m: re.Match[str], tag: str, idx: int) -> etree.Element

Return single tag.

‹› markdown.inlinepatterns.AsteriskProcessor.build_double(m: re.Match[str], tags: str, idx: int) -> etree.Element

Return double tag.

‹› markdown.inlinepatterns.AsteriskProcessor.build_double2(m: re.Match[str], tags: str, idx: int) -> etree.Element

Return double tags (variant 2): <strong>text <em>text</em></strong>.

‹› markdown.inlinepatterns.AsteriskProcessor.parse_sub_patterns(data: str, parent: etree.Element, last: etree.Element | None, idx: int) -> None

Parses sub patterns.

data: text to evaluate.

parent: Parent to attach text and sub elements to.

last: Last appended child to parent. Can also be None if parent has no children.

idx: Current pattern index that was used to evaluate the parent.

‹› markdown.inlinepatterns.AsteriskProcessor.build_element(m: re.Match[str], builder: str, tags: str, index: int) -> etree.Element

Element builder.

‹› markdown.inlinepatterns.AsteriskProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Parse patterns.

‹› markdown.inlinepatterns.UnderscoreProcessor(pattern: str, md: Markdown | None = None)

Bases: AsteriskProcessor

Emphasis processor for handling strong and em matches inside underscores.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.UnderscoreProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.UnderscoreProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.UnderscoreProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Parse patterns.

‹› markdown.inlinepatterns.UnderscoreProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.UnderscoreProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.UnderscoreProcessor.build_single(m: re.Match[str], tag: str, idx: int) -> etree.Element

Return single tag.

‹› markdown.inlinepatterns.UnderscoreProcessor.build_double(m: re.Match[str], tags: str, idx: int) -> etree.Element

Return double tag.

‹› markdown.inlinepatterns.UnderscoreProcessor.build_double2(m: re.Match[str], tags: str, idx: int) -> etree.Element

Return double tags (variant 2): <strong>text <em>text</em></strong>.

‹› markdown.inlinepatterns.UnderscoreProcessor.parse_sub_patterns(data: str, parent: etree.Element, last: etree.Element | None, idx: int) -> None

Parses sub patterns.

data: text to evaluate.

parent: Parent to attach text and sub elements to.

last: Last appended child to parent. Can also be None if parent has no children.

idx: Current pattern index that was used to evaluate the parent.

‹› markdown.inlinepatterns.UnderscoreProcessor.build_element(m: re.Match[str], builder: str, tags: str, index: int) -> etree.Element

Element builder.

‹› markdown.inlinepatterns.UnderscoreProcessor.PATTERNS class-attribute instance-attribute

The various strong and emphasis patterns handled by this processor.

Defined Value:

PATTERNS = [
    EmStrongItem(re.compile(EM_STRONG2_RE, re.DOTALL | re.UNICODE), 'double', 'strong,em'),
    EmStrongItem(re.compile(STRONG_EM2_RE, re.DOTALL | re.UNICODE), 'double', 'em,strong'),
    EmStrongItem(re.compile(SMART_STRONG_EM_RE, re.DOTALL | re.UNICODE), 'double2', 'strong,em'),
    EmStrongItem(re.compile(SMART_STRONG_RE, re.DOTALL | re.UNICODE), 'single', 'strong'),
    EmStrongItem(re.compile(SMART_EMPHASIS_RE, re.DOTALL | re.UNICODE), 'single', 'em')
]

‹› markdown.inlinepatterns.LinkInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Return a link element from the given match.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.LinkInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.LinkInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.LinkInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.LinkInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.LinkInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return an a Element or (None, None, None).

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.LinkInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ImageInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: LinkInlineProcessor

Return a img element from the given match.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.ImageInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.ImageInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.ImageInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.ImageInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.ImageInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ImageInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return an img Element or (None, None, None).

‹› markdown.inlinepatterns.ReferenceInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: LinkInlineProcessor

Match to a stored reference and return link element.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.ReferenceInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.ReferenceInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.ReferenceInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.ReferenceInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.ReferenceInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ReferenceInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return Element returned by makeTag method or (None, None, None).

‹› markdown.inlinepatterns.ReferenceInlineProcessor.evalId(data: str, index: int, text: str) -> tuple[str | None, int, bool]

Evaluate the id portion of [ref][id].

If [ref][] use [ref].

‹› markdown.inlinepatterns.ReferenceInlineProcessor.makeTag(href: str, title: str, text: str) -> etree.Element

Return an a Element.

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: ReferenceInlineProcessor

Short form of reference: [google].

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return Element returned by makeTag method or (None, None, None).

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.makeTag(href: str, title: str, text: str) -> etree.Element

Return an a Element.

‹› markdown.inlinepatterns.ShortReferenceInlineProcessor.evalId(data: str, index: int, text: str) -> tuple[str, int, bool]

Evaluate the id of [ref].

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: ReferenceInlineProcessor

Match to a stored reference and return img element.

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return Element returned by makeTag method or (None, None, None).

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.evalId(data: str, index: int, text: str) -> tuple[str | None, int, bool]

Evaluate the id portion of [ref][id].

If [ref][] use [ref].

‹› markdown.inlinepatterns.ImageReferenceInlineProcessor.makeTag(href: str, title: str, text: str) -> etree.Element

Return an img Element.

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: ImageReferenceInlineProcessor

Short form of image reference: ![ref].

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]

Return Element returned by makeTag method or (None, None, None).

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

Parse data between () of [Text]() allowing recursive ().

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.getText(data: str, index: int) -> tuple[str, int, bool]

Parse the content between [] of the start of an image or link resolving nested square brackets.

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.makeTag(href: str, title: str, text: str) -> etree.Element

Return an img Element.

‹› markdown.inlinepatterns.ShortImageReferenceInlineProcessor.evalId(data: str, index: int, text: str) -> tuple[str, int, bool]

Evaluate the id of [ref].

‹› markdown.inlinepatterns.AutolinkInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Return a link Element given an auto-link (<http://example/com>).

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.AutolinkInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.AutolinkInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.AutolinkInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.AutolinkInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.AutolinkInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element, int, int]

Return an a Element of group(1).

‹› markdown.inlinepatterns.AutomailInlineProcessor(pattern: str, md: Markdown | None = None)

Bases: InlineProcessor

Return a mailto link Element given an auto-mail link (<foo@example.com>).

Parameters:

  • pattern (str) –

    A regular expression that matches a pattern.

  • md (Markdown | None, default: None ) –

    An optional pointer to the instance of markdown.Markdown and is available as self.md on the class instance.

‹› markdown.inlinepatterns.AutomailInlineProcessor.ANCESTOR_EXCLUDES: Collection[str] class-attribute instance-attribute

A collection of elements which are undesirable ancestors. The processor will be skipped if it would cause the content to be a descendant of one of the listed tag names.

Defined Value:

ANCESTOR_EXCLUDES: Collection[str] = tuple()

‹› markdown.inlinepatterns.AutomailInlineProcessor.getCompiledRegExp() -> re.Pattern

Return a compiled regular expression.

‹› markdown.inlinepatterns.AutomailInlineProcessor.type() -> str

Return class name, to define pattern type

‹› markdown.inlinepatterns.AutomailInlineProcessor.unescape(text: str) -> str

Return unescaped text given text with an inline placeholder.

‹› markdown.inlinepatterns.AutomailInlineProcessor.handleMatch(m: re.Match[str], data: str) -> tuple[etree.Element, int, int]

Return an Element containing a mailto link of group(1).