MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / run

Method run

markdown/preprocessors.py:108–188  ·  view source on GitHub ↗
(self, lines)

Source from the content-addressed store, hash-verified

106 return (tag in ['hr', 'hr/'])
107
108 def run(self, lines):
109 text = "\n".join(lines)
110 new_blocks = []
111 text = text.split("\n\n")
112 items = []
113 left_tag = ''
114 right_tag = ''
115 in_tag = False # flag
116
117 while text:
118 block = text[0]
119 if block.startswith("\n"):
120 block = block[1:]
121 text = text[1:]
122
123 if block.startswith("\n"):
124 block = block[1:]
125
126 if not in_tag:
127 if block.startswith("<"):
128 left_tag = self._get_left_tag(block)
129 right_tag, data_index = self._get_right_tag(left_tag, block)
130
131 if block[1] == "!":
132 # is a comment block
133 left_tag = "--"
134 right_tag, data_index = self._get_right_tag(left_tag, block)
135 # keep checking conditions below and maybe just append
136
137 if data_index < len(block) \
138 and markdown.isBlockLevel(left_tag):
139 text.insert(0, block[data_index:])
140 block = block[:data_index]
141
142 if not (markdown.isBlockLevel(left_tag) \
143 or block[1] in ["!", "?", "@", "%"]):
144 new_blocks.append(block)
145 continue
146
147 if self._is_oneliner(left_tag):
148 new_blocks.append(block.strip())
149 continue
150
151 if block.rstrip().endswith(">") \
152 and self._equal_tags(left_tag, right_tag):
153 new_blocks.append(
154 self.markdown.htmlStash.store(block.strip()))
155 continue
156 else: #if not block[1] == "!":
157 # if is block level tag and is not complete
158
159 if markdown.isBlockLevel(left_tag) or left_tag == "--" \
160 and not block.rstrip().endswith(">"):
161 items.append(block.strip())
162 in_tag = True
163 else:
164 new_blocks.append(
165 self.markdown.htmlStash.store(block.strip()))

Callers

nothing calls this directly

Calls 8

_get_left_tagMethod · 0.95
_get_right_tagMethod · 0.95
_is_onelinerMethod · 0.95
_equal_tagsMethod · 0.95
storeMethod · 0.80
splitMethod · 0.45
insertMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected