MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / _split

Method _split

markdown/extensions/tables.py:158–228  ·  view source on GitHub ↗

split a row of text with some code into a list of cells.

(self, row: str)

Source from the content-addressed store, hash-verified

156 return self._split(row)
157
158 def _split(self, row: str) -> list[str]:
159 """ split a row of text with some code into a list of cells. """
160 elements = []
161 pipes = []
162 tics = []
163 tic_points = []
164 tic_region = []
165 good_pipes = []
166
167 # Parse row
168 # Throw out \\, and \|
169 for m in self.RE_CODE_PIPES.finditer(row):
170 # Store ` data (len, start_pos, end_pos)
171 if m.group(2):
172 # \`+
173 # Store length of each tic group: subtract \
174 tics.append(len(m.group(2)) - 1)
175 # Store start of group, end of group, and escape length
176 tic_points.append((m.start(2), m.end(2) - 1, 1))
177 elif m.group(3):
178 # `+
179 # Store length of each tic group
180 tics.append(len(m.group(3)))
181 # Store start of group, end of group, and escape length
182 tic_points.append((m.start(3), m.end(3) - 1, 0))
183 # Store pipe location
184 elif m.group(5):
185 pipes.append(m.start(5))
186
187 # Pair up tics according to size if possible
188 # Subtract the escape length *only* from the opening.
189 # Walk through tic list and see if tic has a close.
190 # Store the tic region (start of region, end of region).
191 pos = 0
192 tic_len = len(tics)
193 while pos < tic_len:
194 try:
195 tic_size = tics[pos] - tic_points[pos][2]
196 if tic_size == 0:
197 raise ValueError
198 index = tics[pos + 1:].index(tic_size) + 1
199 tic_region.append((tic_points[pos][0], tic_points[pos + index][1]))
200 pos += index + 1
201 except ValueError:
202 pos += 1
203
204 # Resolve pipes. Check if they are within a tic pair region.
205 # Walk through pipes comparing them to each region.
206 # - If pipe position is less that a region, it isn't in a region
207 # - If it is within a region, we don't want it, so throw it out
208 # - If we didn't throw it out, it must be a table pipe
209 for pipe in pipes:
210 throw_out = False
211 for region in tic_region:
212 if pipe < region[0]:
213 # Pipe is not in a region
214 break
215 elif region[0] <= pipe <= region[1]:

Callers 1

_split_rowMethod · 0.95

Calls 1

finditerMethod · 0.80

Tested by

no test coverage detected