code.py 859 B

1234567891011121314151617181920212223242526272829303132333435
  1. """Code block (4 spaces padded)."""
  2. import logging
  3. from .state_block import StateBlock
  4. LOGGER = logging.getLogger(__name__)
  5. def code(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
  6. LOGGER.debug("entering code: %s, %s, %s, %s", state, startLine, endLine, silent)
  7. if not state.is_code_block(startLine):
  8. return False
  9. last = nextLine = startLine + 1
  10. while nextLine < endLine:
  11. if state.isEmpty(nextLine):
  12. nextLine += 1
  13. continue
  14. if state.is_code_block(nextLine):
  15. nextLine += 1
  16. last = nextLine
  17. continue
  18. break
  19. state.line = last
  20. token = state.push("code_block", "code", 0)
  21. token.content = state.getLines(startLine, last, 4 + state.blkIndent, False) + "\n"
  22. token.map = [startLine, state.line]
  23. return True