def get_tokens(self, txtnodes): # A generator that yields ``(texttype, nodetext)`` tuples for a list # of "Text" nodes (interface to ``smartquotes.educate_tokens()``). texttype = {True: 'literal', # "literal" text is not changed: False: 'plain'} for txtnode in txtnodes: smartquotable = not is_smartquotable(txtnode) yield (texttype[smartquotable], txtnode.astext())
def get_tokens(self, txtnodes: List[Text]) -> Generator[Tuple[str, str], None, None]: # A generator that yields ``(texttype, nodetext)`` tuples for a list # of "Text" nodes (interface to ``smartquotes.educate_tokens()``). for txtnode in txtnodes: if is_smartquotable(txtnode): if docutils.__version_info__ >= (0, 16): # SmartQuotes uses backslash escapes instead of null-escapes text = re.sub(r'(?<=\x00)([-\\\'".`])', r'\\\1', str(txtnode)) else: text = txtnode.astext() yield ('plain', text) else: # skip smart quotes yield ('literal', txtnode.astext())