_export_format.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. CONSOLE_HTML_FORMAT = """\
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="UTF-8">
  6. <style>
  7. {stylesheet}
  8. body {{
  9. color: {foreground};
  10. background-color: {background};
  11. }}
  12. </style>
  13. </head>
  14. <body>
  15. <pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
  16. </body>
  17. </html>
  18. """
  19. CONSOLE_SVG_FORMAT = """\
  20. <svg class="rich-terminal" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
  21. <!-- Generated with Rich https://www.textualize.io -->
  22. <style>
  23. @font-face {{
  24. font-family: "Fira Code";
  25. src: local("FiraCode-Regular"),
  26. url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
  27. url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
  28. font-style: normal;
  29. font-weight: 400;
  30. }}
  31. @font-face {{
  32. font-family: "Fira Code";
  33. src: local("FiraCode-Bold"),
  34. url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
  35. url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
  36. font-style: bold;
  37. font-weight: 700;
  38. }}
  39. .{unique_id}-matrix {{
  40. font-family: Fira Code, monospace;
  41. font-size: {char_height}px;
  42. line-height: {line_height}px;
  43. font-variant-east-asian: full-width;
  44. }}
  45. .{unique_id}-title {{
  46. font-size: 18px;
  47. font-weight: bold;
  48. font-family: arial;
  49. }}
  50. {styles}
  51. </style>
  52. <defs>
  53. <clipPath id="{unique_id}-clip-terminal">
  54. <rect x="0" y="0" width="{terminal_width}" height="{terminal_height}" />
  55. </clipPath>
  56. {lines}
  57. </defs>
  58. {chrome}
  59. <g transform="translate({terminal_x}, {terminal_y})" clip-path="url(#{unique_id}-clip-terminal)">
  60. {backgrounds}
  61. <g class="{unique_id}-matrix">
  62. {matrix}
  63. </g>
  64. </g>
  65. </svg>
  66. """
  67. _SVG_FONT_FAMILY = "Rich Fira Code"
  68. _SVG_CLASSES_PREFIX = "rich-svg"