sections.py 554 B

123456789101112131415161718192021222324252627282930
  1. n = "\n"
  2. w = " "
  3. bold = lambda x: f"**{x}:** "
  4. bold_ul = lambda x: f"**--{x}:**-- "
  5. mono = lambda x: f"`{x}`{n}"
  6. def section(
  7. title: str,
  8. body: dict,
  9. indent: int = 2,
  10. underline: bool = True,
  11. ) -> str:
  12. text = (bold_ul(title) + n) if underline else bold(title) + n
  13. for key, value in body.items():
  14. text += (
  15. indent * w
  16. + bold(key)
  17. + (
  18. (value[0] + n)
  19. if isinstance(value, list)
  20. else mono(value)
  21. )
  22. )
  23. return text