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