MCPcopy
hub / github.com/sphinx-doc/sphinx / parse

Method parse

sphinx/roles.py:424–460  ·  view source on GitHub ↗
(self, text: str)

Source from the content-addressed store, hash-verified

422 return [node], []
423
424 def parse(self, text: str) -> list[Node]:
425 result: list[Node] = []
426
427 stack = ['']
428 for part in self.parens_re.split(text):
429 if part == '\\\\': # escaped backslash
430 stack[-1] += '\\'
431 elif part == '{':
432 if len(stack) >= 2 and stack[-2] == '{': # nested
433 stack[-1] += '{'
434 else:
435 # start emphasis
436 stack.extend(('{', ''))
437 elif part == '}':
438 if len(stack) == 3 and stack[1] == '{' and len(stack[2]) > 0:
439 # emphasized word found
440 if stack[0]:
441 result.append(nodes.Text(stack[0]))
442 result.append(nodes.emphasis(stack[2], stack[2]))
443 stack = ['']
444 else:
445 # emphasized word not found; the rparen is not a special symbol
446 stack.append('}')
447 stack = [''.join(stack)]
448 elif part == '\\{': # escaped left-brace
449 stack[-1] += '{'
450 elif part == '\\}': # escaped right-brace
451 stack[-1] += '}'
452 else: # others (containing escaped braces)
453 stack[-1] += part
454
455 if ''.join(stack):
456 # remaining is treated as Text
457 text = ''.join(stack)
458 result.append(nodes.Text(text))
459
460 return result
461
462
463class Abbreviation(SphinxRole):

Callers 1

runMethod · 0.95

Calls 3

splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected