text.py 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Skip text characters for text token, place those to pending buffer
  2. # and increment current pos
  3. from .state_inline import StateInline
  4. # Rule to skip pure text
  5. # '{}$%@~+=:' reserved for extensions
  6. # !!!! Don't confuse with "Markdown ASCII Punctuation" chars
  7. # http://spec.commonmark.org/0.15/#ascii-punctuation-character
  8. _TerminatorChars = {
  9. "\n",
  10. "!",
  11. "#",
  12. "$",
  13. "%",
  14. "&",
  15. "*",
  16. "+",
  17. "-",
  18. ":",
  19. "<",
  20. "=",
  21. ">",
  22. "@",
  23. "[",
  24. "\\",
  25. "]",
  26. "^",
  27. "_",
  28. "`",
  29. "{",
  30. "}",
  31. "~",
  32. }
  33. def text(state: StateInline, silent: bool) -> bool:
  34. pos = state.pos
  35. posMax = state.posMax
  36. while (pos < posMax) and state.src[pos] not in _TerminatorChars:
  37. pos += 1
  38. if pos == state.pos:
  39. return False
  40. if not silent:
  41. state.pending += state.src[state.pos : pos]
  42. state.pos = pos
  43. return True