MCPcopy
hub / github.com/Python-Markdown/markdown / build_inlinepatterns

Function build_inlinepatterns

markdown/inlinepatterns.py:53–95  ·  view source on GitHub ↗

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 ` ` tags and _then_ try to replace inline HTML, we would end up with a mess. So, we apply the exp

(md: Markdown, **kwargs: Any)

Source from the content-addressed store, hash-verified

51
52
53def build_inlinepatterns(md: Markdown, **kwargs: Any) -> util.Registry[InlineProcessor]:
54 """
55 Build the default set of inline patterns for Markdown.
56
57 The order in which processors and/or patterns are applied is very important - e.g. if we first replace
58 `http://.../` links with `<a>` tags and _then_ try to replace inline HTML, we would end up with a mess. So, we
59 apply the expressions in the following order:
60
61 * backticks and escaped characters have to be handled before everything else so that we can preempt any markdown
62 patterns by escaping them;
63
64 * then we handle the various types of links (auto-links must be handled before inline HTML);
65
66 * then we handle inline HTML. At this point we will simply replace all inline HTML strings with a placeholder
67 and add the actual HTML to a stash;
68
69 * finally we apply strong, emphasis, etc.
70
71 """
72 inlinePatterns = util.Registry()
73 inlinePatterns.register(BacktickInlineProcessor(BACKTICK_RE), 'backtick', 190)
74 inlinePatterns.register(EscapeInlineProcessor(ESCAPE_RE, md), 'escape', 180)
75 inlinePatterns.register(ReferenceInlineProcessor(REFERENCE_RE, md), 'reference', 170)
76 inlinePatterns.register(LinkInlineProcessor(LINK_RE, md), 'link', 160)
77 inlinePatterns.register(ImageInlineProcessor(IMAGE_LINK_RE, md), 'image_link', 150)
78 inlinePatterns.register(
79 ImageReferenceInlineProcessor(IMAGE_REFERENCE_RE, md), 'image_reference', 140
80 )
81 inlinePatterns.register(
82 ShortReferenceInlineProcessor(REFERENCE_RE, md), 'short_reference', 130
83 )
84 inlinePatterns.register(
85 ShortImageReferenceInlineProcessor(IMAGE_REFERENCE_RE, md), 'short_image_ref', 125
86 )
87 inlinePatterns.register(AutolinkInlineProcessor(AUTOLINK_RE, md), 'autolink', 120)
88 inlinePatterns.register(AutomailInlineProcessor(AUTOMAIL_RE, md), 'automail', 110)
89 inlinePatterns.register(SubstituteTagInlineProcessor(LINE_BREAK_RE, 'br'), 'linebreak', 100)
90 inlinePatterns.register(HtmlInlineProcessor(HTML_RE, md), 'html', 90)
91 inlinePatterns.register(HtmlInlineProcessor(ENTITY_RE, md), 'entity', 80)
92 inlinePatterns.register(SimpleTextInlineProcessor(NOT_STRONG_RE), 'not_strong', 70)
93 inlinePatterns.register(AsteriskProcessor(r'\*'), 'em_strong', 60)
94 inlinePatterns.register(UnderscoreProcessor(r'_'), 'em_strong2', 50)
95 return inlinePatterns
96
97
98# The actual regular expressions for patterns

Callers 1

build_parserMethod · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…