|
22 | 22 |
|
23 | 23 |
|
24 | 24 | _re_doctest_flags = re.compile(r"^(>>>.*\S)(\s+)# doctest:\s+\+[A-Z_]+\s*$", flags=re.MULTILINE) |
| 25 | +_re_lt_html = re.compile(r"<(((!(DOCTYPE|--))|((\/\s*)?[a-z]+))[^>]*?)>", re.IGNORECASE) |
| 26 | +_re_lcub_svelte = re.compile( |
| 27 | + r"<(Question|Tip|Added|Changed|Deprecated|DocNotebookDropdown|CourseFloatingBanner|FrameworkSwitch|audio|PipelineIcon|PipelineTag)(((?!<(Question|Tip|Added|Changed|Deprecated|DocNotebookDropdown|CourseFloatingBanner|FrameworkSwitch|audio|PipelineIcon|PipelineTag)).)*)>|&lcub;(#if|:else}|/if})", |
| 28 | + re.DOTALL, |
| 29 | +) |
25 | 30 |
|
26 | 31 |
|
27 | 32 | def convert_md_to_mdx(md_text, page_info): |
@@ -68,18 +73,13 @@ def convert_special_chars(text): |
68 | 73 | """ |
69 | 74 | Convert { and < that have special meanings in MDX. |
70 | 75 | """ |
71 | | - _re_lcub_svelte = re.compile( |
72 | | - r"<(Question|Tip|Added|Changed|Deprecated|DocNotebookDropdown|CourseFloatingBanner|FrameworkSwitch|audio|PipelineIcon|PipelineTag)(((?!<(Question|Tip|Added|Changed|Deprecated|DocNotebookDropdown|CourseFloatingBanner|FrameworkSwitch|audio|PipelineIcon|PipelineTag)).)*)>|&lcub;(#if|:else}|/if})", |
73 | | - re.DOTALL, |
74 | | - ) |
75 | 76 | text = text.replace("{", "&lcub;") |
76 | 77 | # We don't want to escape `{` that are part of svelte syntax |
77 | 78 | text = _re_lcub_svelte.sub(lambda match: match[0].replace("&lcub;", "{"), text) |
78 | 79 | # We don't want to replace those by the HTML code, so we temporarily set them at LTHTML |
79 | 80 | # source is a special tag, it can be standalone (html tag) or closing (doc tag) |
80 | 81 |
|
81 | 82 | # Temporarily replace all valid HTML tags with LTHTML |
82 | | - _re_lt_html = re.compile(r"<(((!(DOCTYPE|--))|((\/\s*)?\w+))[^>]*?)>", re.DOTALL) |
83 | 83 | text = re.sub(_re_lt_html, r"LTHTML\1>", text) |
84 | 84 | # Encode remaining < symbols |
85 | 85 | text = text.replace("<", "&lt;") |
|
0 commit comments