MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / __applyPattern

Method __applyPattern

markdown/treeprocessors.py:198–240  ·  view source on GitHub ↗

Check if the line fits the pattern, create the necessary elements, add it to stashed_nodes. Keyword arguments: * data: the text to be processed * pattern: the pattern to be checked * patternIndex: index of current pattern * startIndex: strin

(self, pattern, data, patternIndex, startIndex=0)

Source from the content-addressed store, hash-verified

196 return result
197
198 def __applyPattern(self, pattern, data, patternIndex, startIndex=0):
199 """
200 Check if the line fits the pattern, create the necessary
201 elements, add it to stashed_nodes.
202
203 Keyword arguments:
204
205 * data: the text to be processed
206 * pattern: the pattern to be checked
207 * patternIndex: index of current pattern
208 * startIndex: string index, from which we starting search
209
210 Returns: String with placeholders instead of ElementTree elements.
211
212 """
213 match = pattern.getCompiledRegExp().match(data[startIndex:])
214 leftData = data[:startIndex]
215
216 if not match:
217 return data, False, 0
218
219 node = pattern.handleMatch(match)
220
221 if node is None:
222 return data, True, len(leftData) + match.span(len(match.groups()))[0]
223
224 if not isString(node):
225 if not isinstance(node.text, markdown.AtomicString):
226 # We need to process current node too
227 for child in [node] + list(node):
228 if not isString(node):
229 if child.text:
230 child.text = self.__handleInline(child.text,
231 patternIndex + 1)
232 if child.tail:
233 child.tail = self.__handleInline(child.tail,
234 patternIndex)
235
236 placeholder = self.__stashNode(node, pattern.type())
237
238 return "%s%s%s%s" % (leftData,
239 match.group(1),
240 placeholder, match.groups()[-1]), True, 0
241
242 def run(self, tree):
243 """Apply inline patterns to a parsed Markdown tree.

Callers 1

__handleInlineMethod · 0.95

Calls 7

__handleInlineMethod · 0.95
__stashNodeMethod · 0.95
isStringFunction · 0.85
getCompiledRegExpMethod · 0.80
typeMethod · 0.80
matchMethod · 0.45
handleMatchMethod · 0.45

Tested by

no test coverage detected