pylitehtml 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. pylitehtml-0.2.1/CMakeLists.txt +109 -0
  2. pylitehtml-0.2.1/LICENSE +21 -0
  3. pylitehtml-0.2.1/PKG-INFO +299 -0
  4. pylitehtml-0.2.1/README.md +249 -0
  5. pylitehtml-0.2.1/fonts/DejaVuSans.ttf +0 -0
  6. pylitehtml-0.2.1/fonts/NotoSans-Regular.ttf +0 -0
  7. pylitehtml-0.2.1/fonts/NotoSansSC-Regular.otf +0 -0
  8. pylitehtml-0.2.1/fonts/fonts.conf +51 -0
  9. pylitehtml-0.2.1/pyproject.toml +82 -0
  10. pylitehtml-0.2.1/pyrightconfig.json +8 -0
  11. pylitehtml-0.2.1/src/cpp/base64.h +33 -0
  12. pylitehtml-0.2.1/src/cpp/binding.cpp +173 -0
  13. pylitehtml-0.2.1/src/cpp/encode.cpp +119 -0
  14. pylitehtml-0.2.1/src/cpp/encode.h +10 -0
  15. pylitehtml-0.2.1/src/cpp/font_manager.cpp +53 -0
  16. pylitehtml-0.2.1/src/cpp/font_manager.h +43 -0
  17. pylitehtml-0.2.1/src/cpp/http_util.cpp +61 -0
  18. pylitehtml-0.2.1/src/cpp/http_util.h +9 -0
  19. pylitehtml-0.2.1/src/cpp/image_cache.cpp +357 -0
  20. pylitehtml-0.2.1/src/cpp/image_cache.h +54 -0
  21. pylitehtml-0.2.1/src/cpp/py_container.cpp +331 -0
  22. pylitehtml-0.2.1/src/cpp/py_container.h +113 -0
  23. pylitehtml-0.2.1/src/cpp/vendor/httplib.h +10255 -0
  24. pylitehtml-0.2.1/src/python/pylitehtml/__init__.py +338 -0
  25. pylitehtml-0.2.1/src/python/pylitehtml/__init__.pyi +153 -0
  26. pylitehtml-0.2.1/src/python/pylitehtml/_core.pyi +159 -0
  27. pylitehtml-0.2.1/src/python/pylitehtml/_html2png.py +247 -0
  28. pylitehtml-0.2.1/src/python/pylitehtml/_jinja.py +30 -0
  29. pylitehtml-0.2.1/src/python/pylitehtml/fonts/DejaVuSans.ttf +0 -0
  30. pylitehtml-0.2.1/src/python/pylitehtml/fonts/NotoSans-Regular.ttf +0 -0
  31. pylitehtml-0.2.1/src/python/pylitehtml/fonts/NotoSansSC-Regular.otf +0 -0
  32. pylitehtml-0.2.1/src/python/pylitehtml/fonts/fonts.conf +51 -0
  33. pylitehtml-0.2.1/src/python/pylitehtml/markdown.py +480 -0
  34. pylitehtml-0.2.1/src/python/pylitehtml/py.typed +0 -0
  35. pylitehtml-0.2.1/third_party/litehtml/.clang-format +60 -0
  36. pylitehtml-0.2.1/third_party/litehtml/CMakeLists.txt +208 -0
  37. pylitehtml-0.2.1/third_party/litehtml/LICENSE +24 -0
  38. pylitehtml-0.2.1/third_party/litehtml/README.md +38 -0
  39. pylitehtml-0.2.1/third_party/litehtml/cmake/litehtmlConfig.cmake +3 -0
  40. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/cairo_borders.cpp +347 -0
  41. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/cairo_borders.h +70 -0
  42. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/cairo_images_cache.h +91 -0
  43. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/conic_gradient.cpp +99 -0
  44. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/conic_gradient.h +11 -0
  45. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/container_cairo.cpp +776 -0
  46. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/container_cairo.h +95 -0
  47. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/container_cairo_pango.cpp +444 -0
  48. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/container_cairo_pango.h +46 -0
  49. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/render2png.cpp +320 -0
  50. pylitehtml-0.2.1/third_party/litehtml/containers/cairo/render2png.h +42 -0
  51. pylitehtml-0.2.1/third_party/litehtml/containers/haiku/container_haiku.cpp +584 -0
  52. pylitehtml-0.2.1/third_party/litehtml/containers/haiku/container_haiku.h +89 -0
  53. pylitehtml-0.2.1/third_party/litehtml/containers/test/Bitmap.cpp +133 -0
  54. pylitehtml-0.2.1/third_party/litehtml/containers/test/Bitmap.h +58 -0
  55. pylitehtml-0.2.1/third_party/litehtml/containers/test/Font.cpp +249 -0
  56. pylitehtml-0.2.1/third_party/litehtml/containers/test/Font.h +41 -0
  57. pylitehtml-0.2.1/third_party/litehtml/containers/test/canvas_ity.hpp +3627 -0
  58. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/OFL.txt +94 -0
  59. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/ahem-README +49 -0
  60. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/ahem.ttf +0 -0
  61. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/readme.txt +17 -0
  62. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-12px.yaff +1478 -0
  63. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-14px.yaff +1672 -0
  64. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-16px-bold.yaff +1866 -0
  65. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-16px.yaff +1866 -0
  66. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-18px.yaff +2060 -0
  67. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-20px.yaff +2254 -0
  68. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-22px.yaff +2448 -0
  69. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-24px.yaff +2642 -0
  70. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-28px.yaff +3030 -0
  71. pylitehtml-0.2.1/third_party/litehtml/containers/test/fonts/terminus-32px.yaff +3418 -0
  72. pylitehtml-0.2.1/third_party/litehtml/containers/test/lodepng.cpp +6661 -0
  73. pylitehtml-0.2.1/third_party/litehtml/containers/test/lodepng.h +2085 -0
  74. pylitehtml-0.2.1/third_party/litehtml/containers/test/test_container.cpp +372 -0
  75. pylitehtml-0.2.1/third_party/litehtml/containers/test/test_container.h +54 -0
  76. pylitehtml-0.2.1/third_party/litehtml/containers/windows/cairo/cairo_font.cpp +378 -0
  77. pylitehtml-0.2.1/third_party/litehtml/containers/windows/cairo/cairo_font.h +121 -0
  78. pylitehtml-0.2.1/third_party/litehtml/containers/windows/cairo/windows_container.cpp +198 -0
  79. pylitehtml-0.2.1/third_party/litehtml/containers/windows/cairo/windows_container.h +39 -0
  80. pylitehtml-0.2.1/third_party/litehtml/containers/windows/gdiplus/gdiplus_container.cpp +241 -0
  81. pylitehtml-0.2.1/third_party/litehtml/containers/windows/gdiplus/gdiplus_container.h +23 -0
  82. pylitehtml-0.2.1/third_party/litehtml/containers/windows/win32/win32_container.cpp +474 -0
  83. pylitehtml-0.2.1/third_party/litehtml/containers/windows/win32/win32_container.h +78 -0
  84. pylitehtml-0.2.1/third_party/litehtml/doc/document_container.md +523 -0
  85. pylitehtml-0.2.1/third_party/litehtml/doc/document_createFromString.md +75 -0
  86. pylitehtml-0.2.1/third_party/litehtml/doc/using.md +153 -0
  87. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/background.h +146 -0
  88. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/borders.h +294 -0
  89. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/codepoint.h +47 -0
  90. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_length.h +131 -0
  91. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_margins.h +37 -0
  92. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_offsets.h +37 -0
  93. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_parser.h +53 -0
  94. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_position.h +28 -0
  95. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_properties.h +752 -0
  96. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_selector.h +285 -0
  97. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/css_tokenizer.h +218 -0
  98. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/document.h +149 -0
  99. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/document_container.h +79 -0
  100. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_anchor.h +18 -0
  101. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_base.h +17 -0
  102. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_before_after.h +39 -0
  103. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_body.h +17 -0
  104. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_break.h +17 -0
  105. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_cdata.h +19 -0
  106. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_comment.h +25 -0
  107. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_div.h +17 -0
  108. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_font.h +17 -0
  109. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_image.h +31 -0
  110. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_link.h +18 -0
  111. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_para.h +18 -0
  112. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_script.h +21 -0
  113. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_space.h +20 -0
  114. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_style.h +22 -0
  115. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_table.h +18 -0
  116. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_td.h +17 -0
  117. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_text.h +32 -0
  118. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_title.h +18 -0
  119. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/el_tr.h +17 -0
  120. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/element.h +241 -0
  121. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/encodings.h +92 -0
  122. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/flex_item.h +154 -0
  123. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/flex_line.h +55 -0
  124. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/font_description.h +45 -0
  125. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/formatting_context.h +73 -0
  126. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/gradient.h +209 -0
  127. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/html.h +186 -0
  128. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/html_microsyntaxes.h +23 -0
  129. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/html_tag.h +154 -0
  130. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/iterators.h +83 -0
  131. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/line_box.h +187 -0
  132. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/master_css.h +375 -0
  133. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/media_query.h +120 -0
  134. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/num_cvt.h +18 -0
  135. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/os_types.h +16 -0
  136. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_block.h +48 -0
  137. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_block_context.h +32 -0
  138. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_flex.h +34 -0
  139. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_image.h +26 -0
  140. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_inline.h +50 -0
  141. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_inline_context.h +61 -0
  142. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_item.h +495 -0
  143. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/render_table.h +57 -0
  144. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/scroll_view.h +84 -0
  145. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/string_id.h +365 -0
  146. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/style.h +125 -0
  147. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/stylesheet.h +73 -0
  148. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/table.h +249 -0
  149. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/types.h +1110 -0
  150. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/url.h +140 -0
  151. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/url_path.h +49 -0
  152. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/utf8_strings.h +43 -0
  153. pylitehtml-0.2.1/third_party/litehtml/include/litehtml/web_color.h +38 -0
  154. pylitehtml-0.2.1/third_party/litehtml/include/litehtml.h +12 -0
  155. pylitehtml-0.2.1/third_party/litehtml/litehtml.vcxproj +376 -0
  156. pylitehtml-0.2.1/third_party/litehtml/litehtml.vcxproj.filters +452 -0
  157. pylitehtml-0.2.1/third_party/litehtml/src/background.cpp +916 -0
  158. pylitehtml-0.2.1/third_party/litehtml/src/codepoint.cpp +82 -0
  159. pylitehtml-0.2.1/third_party/litehtml/src/css_borders.cpp +7 -0
  160. pylitehtml-0.2.1/third_party/litehtml/src/css_length.cpp +78 -0
  161. pylitehtml-0.2.1/third_party/litehtml/src/css_parser.cpp +570 -0
  162. pylitehtml-0.2.1/third_party/litehtml/src/css_properties.cpp +594 -0
  163. pylitehtml-0.2.1/third_party/litehtml/src/css_selector.cpp +716 -0
  164. pylitehtml-0.2.1/third_party/litehtml/src/css_tokenizer.cpp +725 -0
  165. pylitehtml-0.2.1/third_party/litehtml/src/document.cpp +1158 -0
  166. pylitehtml-0.2.1/third_party/litehtml/src/document_container.cpp +42 -0
  167. pylitehtml-0.2.1/third_party/litehtml/src/el_anchor.cpp +26 -0
  168. pylitehtml-0.2.1/third_party/litehtml/src/el_base.cpp +13 -0
  169. pylitehtml-0.2.1/third_party/litehtml/src/el_before_after.cpp +216 -0
  170. pylitehtml-0.2.1/third_party/litehtml/src/el_body.cpp +11 -0
  171. pylitehtml-0.2.1/third_party/litehtml/src/el_break.cpp +12 -0
  172. pylitehtml-0.2.1/third_party/litehtml/src/el_cdata.cpp +19 -0
  173. pylitehtml-0.2.1/third_party/litehtml/src/el_comment.cpp +24 -0
  174. pylitehtml-0.2.1/third_party/litehtml/src/el_div.cpp +18 -0
  175. pylitehtml-0.2.1/third_party/litehtml/src/el_font.cpp +57 -0
  176. pylitehtml-0.2.1/third_party/litehtml/src/el_image.cpp +86 -0
  177. pylitehtml-0.2.1/third_party/litehtml/src/el_link.cpp +39 -0
  178. pylitehtml-0.2.1/third_party/litehtml/src/el_para.cpp +17 -0
  179. pylitehtml-0.2.1/third_party/litehtml/src/el_script.cpp +29 -0
  180. pylitehtml-0.2.1/third_party/litehtml/src/el_space.cpp +44 -0
  181. pylitehtml-0.2.1/third_party/litehtml/src/el_style.cpp +44 -0
  182. pylitehtml-0.2.1/third_party/litehtml/src/el_table.cpp +47 -0
  183. pylitehtml-0.2.1/third_party/litehtml/src/el_td.cpp +54 -0
  184. pylitehtml-0.2.1/third_party/litehtml/src/el_text.cpp +142 -0
  185. pylitehtml-0.2.1/third_party/litehtml/src/el_title.cpp +16 -0
  186. pylitehtml-0.2.1/third_party/litehtml/src/el_tr.cpp +32 -0
  187. pylitehtml-0.2.1/third_party/litehtml/src/element.cpp +503 -0
  188. pylitehtml-0.2.1/third_party/litehtml/src/encodings.cpp +2039 -0
  189. pylitehtml-0.2.1/third_party/litehtml/src/flex_item.cpp +514 -0
  190. pylitehtml-0.2.1/third_party/litehtml/src/flex_line.cpp +551 -0
  191. pylitehtml-0.2.1/third_party/litehtml/src/formatting_context.cpp +581 -0
  192. pylitehtml-0.2.1/third_party/litehtml/src/gradient.cpp +565 -0
  193. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/CMakeLists.txt +79 -0
  194. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/LICENSE +202 -0
  195. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/attribute.c +44 -0
  196. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/char_ref.c +23069 -0
  197. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/char_ref.rl +2554 -0
  198. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/error.c +286 -0
  199. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/attribute.h +37 -0
  200. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/char_ref.h +60 -0
  201. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/error.h +225 -0
  202. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/insertion_mode.h +57 -0
  203. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/parser.h +57 -0
  204. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/string_buffer.h +84 -0
  205. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/string_piece.h +38 -0
  206. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tag_enum.h +156 -0
  207. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tag_gperf.h +331 -0
  208. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tag_sizes.h +4 -0
  209. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tag_strings.h +156 -0
  210. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/token_type.h +41 -0
  211. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tokenizer.h +123 -0
  212. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/tokenizer_states.h +103 -0
  213. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/utf8.h +132 -0
  214. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/util.h +60 -0
  215. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo/vector.h +67 -0
  216. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/include/gumbo.h +674 -0
  217. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/parser.c +4113 -0
  218. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/string_buffer.c +110 -0
  219. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/string_piece.c +48 -0
  220. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/tag.c +94 -0
  221. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/tag.in +152 -0
  222. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/tokenizer.c +2898 -0
  223. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/utf8.c +270 -0
  224. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/util.c +58 -0
  225. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/vector.c +123 -0
  226. pylitehtml-0.2.1/third_party/litehtml/src/gumbo/visualc/include/strings.h +4 -0
  227. pylitehtml-0.2.1/third_party/litehtml/src/html.cpp +310 -0
  228. pylitehtml-0.2.1/third_party/litehtml/src/html_microsyntaxes.cpp +103 -0
  229. pylitehtml-0.2.1/third_party/litehtml/src/html_tag.cpp +1608 -0
  230. pylitehtml-0.2.1/third_party/litehtml/src/internal.h +26 -0
  231. pylitehtml-0.2.1/third_party/litehtml/src/iterators.cpp +98 -0
  232. pylitehtml-0.2.1/third_party/litehtml/src/line_box.cpp +893 -0
  233. pylitehtml-0.2.1/third_party/litehtml/src/media_query.cpp +682 -0
  234. pylitehtml-0.2.1/third_party/litehtml/src/num_cvt.cpp +108 -0
  235. pylitehtml-0.2.1/third_party/litehtml/src/render_block.cpp +361 -0
  236. pylitehtml-0.2.1/third_party/litehtml/src/render_block_context.cpp +174 -0
  237. pylitehtml-0.2.1/third_party/litehtml/src/render_flex.cpp +442 -0
  238. pylitehtml-0.2.1/third_party/litehtml/src/render_image.cpp +153 -0
  239. pylitehtml-0.2.1/third_party/litehtml/src/render_inline_context.cpp +377 -0
  240. pylitehtml-0.2.1/third_party/litehtml/src/render_item.cpp +1451 -0
  241. pylitehtml-0.2.1/third_party/litehtml/src/render_table.cpp +511 -0
  242. pylitehtml-0.2.1/third_party/litehtml/src/string_id.cpp +54 -0
  243. pylitehtml-0.2.1/third_party/litehtml/src/strtod.cpp +275 -0
  244. pylitehtml-0.2.1/third_party/litehtml/src/style.cpp +1673 -0
  245. pylitehtml-0.2.1/third_party/litehtml/src/stylesheet.cpp +143 -0
  246. pylitehtml-0.2.1/third_party/litehtml/src/table.cpp +610 -0
  247. pylitehtml-0.2.1/third_party/litehtml/src/url.cpp +214 -0
  248. pylitehtml-0.2.1/third_party/litehtml/src/url_path.cpp +86 -0
  249. pylitehtml-0.2.1/third_party/litehtml/src/utf8_strings.cpp +103 -0
  250. pylitehtml-0.2.1/third_party/litehtml/src/web_color.cpp +447 -0
  251. pylitehtml-0.2.1/third_party/litehtml/support/README.md +309 -0
  252. pylitehtml-0.2.1/third_party/litehtml/support/draw_buffer/draw_buffer.cpp +141 -0
  253. pylitehtml-0.2.1/third_party/litehtml/support/draw_buffer/draw_buffer.h +186 -0
  254. pylitehtml-0.2.1/third_party/litehtml/support/gtkmm4/html_widget.cpp +746 -0
  255. pylitehtml-0.2.1/third_party/litehtml/support/gtkmm4/html_widget.h +320 -0
  256. pylitehtml-0.2.1/third_party/litehtml/support/webpage/html_host.h +40 -0
  257. pylitehtml-0.2.1/third_party/litehtml/support/webpage/http_request.cpp +129 -0
  258. pylitehtml-0.2.1/third_party/litehtml/support/webpage/http_request.h +75 -0
  259. pylitehtml-0.2.1/third_party/litehtml/support/webpage/http_requests_pool.cpp +104 -0
  260. pylitehtml-0.2.1/third_party/litehtml/support/webpage/http_requests_pool.h +62 -0
  261. pylitehtml-0.2.1/third_party/litehtml/support/webpage/web_history.cpp +62 -0
  262. pylitehtml-0.2.1/third_party/litehtml/support/webpage/web_history.h +28 -0
  263. pylitehtml-0.2.1/third_party/litehtml/support/webpage/web_page.cpp +332 -0
  264. pylitehtml-0.2.1/third_party/litehtml/support/webpage/web_page.h +203 -0
  265. pylitehtml-0.2.1/vcpkg.json +13 -0
@@ -0,0 +1,109 @@
1
+ cmake_minimum_required(VERSION 3.21)
2
+ project(pylitehtml CXX)
3
+
4
+ # macOS: pin deployment target to match Homebrew Python (15.0).
5
+ # Without this, CMake defaults to the current SDK version and produces a .so
6
+ # that requires libc++ symbols unavailable in older Python runtimes.
7
+ if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
8
+ set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0" CACHE STRING "Minimum macOS version")
9
+ endif()
10
+
11
+ set(CMAKE_CXX_STANDARD 17)
12
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
13
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # required for .so on Linux
14
+
15
+ # ── Dependencies via pkg-config ───────────────────────────────────────────────
16
+ find_package(PkgConfig REQUIRED)
17
+ pkg_check_modules(CAIRO REQUIRED IMPORTED_TARGET cairo)
18
+ pkg_check_modules(PANGOCAIRO REQUIRED IMPORTED_TARGET pangocairo)
19
+ pkg_check_modules(FONTCONFIG REQUIRED IMPORTED_TARGET fontconfig)
20
+
21
+ # JPEG: prefer CMake config (libjpeg-turbo), fall back to pkg-config
22
+ find_package(JPEG QUIET)
23
+ if(NOT JPEG_FOUND)
24
+ pkg_check_modules(JPEG REQUIRED IMPORTED_TARGET libjpeg)
25
+ endif()
26
+
27
+ # WebP: prefer CMake config, fall back to pkg-config
28
+ find_package(WebP CONFIG QUIET)
29
+ if(NOT WebP_FOUND)
30
+ pkg_check_modules(WEBP REQUIRED IMPORTED_TARGET libwebp)
31
+ endif()
32
+
33
+ # OpenSSL: enables HTTPS fetching (images / CSS) in the vendored cpp-httplib.
34
+ # Optional — without it the build still works, but https:// resources are
35
+ # skipped (never an error). Most real-world images are https, so prefer having it.
36
+ find_package(OpenSSL QUIET)
37
+
38
+ # ── litehtml ──────────────────────────────────────────────────────────────────
39
+ set(LITEHTML_BUILD_TESTING OFF CACHE BOOL "" FORCE)
40
+ add_subdirectory(third_party/litehtml)
41
+
42
+ # ── pybind11 ─────────────────────────────────────────────────────────────────
43
+ find_package(pybind11 CONFIG REQUIRED)
44
+
45
+ # ── Extension module ─────────────────────────────────────────────────────────
46
+ pybind11_add_module(_core MODULE
47
+ src/cpp/binding.cpp
48
+ src/cpp/http_util.cpp
49
+ src/cpp/image_cache.cpp
50
+ src/cpp/font_manager.cpp
51
+ src/cpp/py_container.cpp
52
+ src/cpp/encode.cpp
53
+ # Reuse Cairo drawing helpers from litehtml (no GDK dependency)
54
+ third_party/litehtml/containers/cairo/container_cairo.cpp
55
+ third_party/litehtml/containers/cairo/cairo_borders.cpp
56
+ third_party/litehtml/containers/cairo/conic_gradient.cpp
57
+ )
58
+
59
+ target_include_directories(_core PRIVATE
60
+ src/cpp
61
+ src/cpp/vendor
62
+ third_party/litehtml/include
63
+ third_party/litehtml/containers/cairo
64
+ )
65
+
66
+ # Use IMPORTED_TARGET from pkg_check_modules — carries both include dirs AND cflags
67
+ target_link_libraries(_core PRIVATE
68
+ litehtml
69
+ PkgConfig::CAIRO
70
+ PkgConfig::PANGOCAIRO
71
+ PkgConfig::FONTCONFIG
72
+ )
73
+
74
+ if(JPEG_FOUND AND TARGET JPEG::JPEG)
75
+ target_link_libraries(_core PRIVATE JPEG::JPEG)
76
+ elseif(TARGET PkgConfig::JPEG)
77
+ target_link_libraries(_core PRIVATE PkgConfig::JPEG)
78
+ endif()
79
+
80
+ if(TARGET WebP::webp)
81
+ target_link_libraries(_core PRIVATE WebP::webp)
82
+ elseif(TARGET PkgConfig::WEBP)
83
+ target_link_libraries(_core PRIVATE PkgConfig::WEBP)
84
+ endif()
85
+
86
+ # The vendored cpp-httplib requires OpenSSL >= 3.0 for TLS. manylinux_2_28 ships
87
+ # OpenSSL 1.1.1, so gate the feature on the version: with < 3.0 (or none) HTTPS
88
+ # is disabled and https:// resources are skipped gracefully (never a build error).
89
+ if(OpenSSL_FOUND AND OPENSSL_VERSION VERSION_GREATER_EQUAL "3.0.0")
90
+ message(STATUS "pylitehtml: OpenSSL ${OPENSSL_VERSION} — HTTPS fetching enabled")
91
+ target_compile_definitions(_core PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT)
92
+ target_link_libraries(_core PRIVATE OpenSSL::SSL OpenSSL::Crypto)
93
+ else()
94
+ message(STATUS "pylitehtml: OpenSSL >= 3.0 not found — https:// resources will be skipped")
95
+ endif()
96
+
97
+ # stdc++fs on older Linux toolchains
98
+ if(UNIX AND NOT APPLE)
99
+ target_link_libraries(_core PRIVATE stdc++fs)
100
+ endif()
101
+
102
+ # MSVC: enable M_PI and other POSIX math constants (not defined by default)
103
+ if(MSVC)
104
+ target_compile_definitions(_core PRIVATE _USE_MATH_DEFINES)
105
+ endif()
106
+
107
+ # ── Install ───────────────────────────────────────────────────────────────────
108
+ install(TARGETS _core DESTINATION pylitehtml)
109
+ install(DIRECTORY fonts/ DESTINATION pylitehtml/fonts)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 tyql688
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,299 @@
1
+ Metadata-Version: 2.2
2
+ Name: pylitehtml
3
+ Version: 0.2.1
4
+ Summary: HTML+CSS to image renderer based on litehtml
5
+ Keywords: html,css,render,image,png,litehtml,screenshot,markdown
6
+ Author: tyql688
7
+ License: MIT License
8
+
9
+ Copyright (c) 2025 tyql688
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Classifier: Programming Language :: Python :: 3.10
30
+ Classifier: Programming Language :: Python :: 3.11
31
+ Classifier: Programming Language :: Python :: 3.12
32
+ Classifier: Programming Language :: Python :: 3.13
33
+ Classifier: Programming Language :: Python :: 3.14
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Topic :: Multimedia :: Graphics
37
+ Classifier: Typing :: Typed
38
+ Project-URL: Homepage, https://github.com/tyql688/pylitehtml
39
+ Project-URL: Repository, https://github.com/tyql688/pylitehtml
40
+ Project-URL: Issues, https://github.com/tyql688/pylitehtml/issues
41
+ Requires-Python: >=3.10
42
+ Requires-Dist: jinja2>=3.0
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest; extra == "dev"
45
+ Requires-Dist: pillow; extra == "dev"
46
+ Requires-Dist: numpy; extra == "dev"
47
+ Requires-Dist: pytest-asyncio; extra == "dev"
48
+ Requires-Dist: ruff; extra == "dev"
49
+ Description-Content-Type: text/markdown
50
+
51
+ # pylitehtml
52
+
53
+ ![CI](https://github.com/tyql688/pylitehtml/actions/workflows/test.yml/badge.svg)
54
+
55
+ HTML+CSS → PNG/JPEG 图像渲染器。轻量级,无需无头浏览器,线程安全。需要 Python ≥ 3.10。
56
+
57
+ ## 效果展示
58
+
59
+ [`examples/`](https://github.com/tyql688/pylitehtml/blob/main/examples/) 下有若干**独立可运行**的示例,各渲染一张图(无浏览器、纯 pylitehtml,与 `tests/` 分开)。
60
+
61
+ | 示例 | 说明 | 渲染结果 |
62
+ | --- | --- | --- |
63
+ | [`showcase_html.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/showcase_html.py) | HTML/CSS 能力参考:排版、颜色/渐变、表格、代码、列表、进度条 + **真实 HTTPS 图片** + `data:` URI 图标 | ![html](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/showcase_html.png) |
64
+ | [`showcase_css.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/showcase_css.py) | More CSS:conic/radial 渐变、边框样式、`position`、`::before`、`text-overflow:ellipsis`、`white-space:pre`、`vertical-align` | ![css](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/showcase_css.png) |
65
+ | [`showcase_markdown.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/showcase_markdown.py) | 内置**零依赖** Markdown 转换器的端到端输出 | ![markdown](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/showcase_markdown.png) |
66
+ | [`showcase_jinja2.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/showcase_jinja2.py) | Jinja2 数据驱动模板(循环 / 条件 / 过滤器 / **autoescape**,一张订单发票) | ![jinja2](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/showcase_jinja2.png) |
67
+ | [`markdown_full_converter.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/markdown_full_converter.py) | 用 markdown-it-py 接入**完整 GFM**(脚注 / 定义列表 / Pygments 语法高亮;需 `pip install markdown-it-py mdit-py-plugins pygments`) | ![gfm](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/showcase_markdown_full.png) |
68
+ | [`render_markdown_doc.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/render_markdown_doc.py) | 渲染一篇**真实复杂文档**([`markdown.md`](https://github.com/tyql688/pylitehtml/blob/main/examples/markdown.md):多表格 / 嵌套列表 / 多语言代码 / Mermaid 源码 / 数学 TeX / 行号引用代码块) | ![doc](https://raw.githubusercontent.com/tyql688/pylitehtml/main/assets/markdown_doc.png) |
69
+
70
+ > 中英文混排共享同一基线(不会出现中文“飞起来”的错位);文本测量为子像素精度;
71
+ > 模板变量经 autoescape 安全转义;抓取失败的远程图片自动跳过,不影响整图渲染。
72
+
73
+ ```bash
74
+ python examples/showcase_html.py # 生成 assets/showcase_html.png(需联网加载真实图片)
75
+ python examples/showcase_css.py
76
+ python examples/showcase_markdown.py
77
+ python examples/showcase_jinja2.py
78
+ ```
79
+
80
+ ## 性能(对比 Playwright)
81
+
82
+ 同一篇文档各渲染 30 次(macOS arm64,width=720;基准脚本
83
+ [`bench/bench_vs_playwright.py`](https://github.com/tyql688/pylitehtml/blob/main/bench/bench_vs_playwright.py)):
84
+
85
+ | 指标 | pylitehtml | Playwright(无头 Chromium) |
86
+ | --- | --- | --- |
87
+ | 单次渲染(warm,均值) | **≈ 15.5 ms** | ≈ 21 ms |
88
+ | 首屏 / 冷启动 | ≈ 0.2 s | ≈ 0.25 s(OS 已缓存)/ **首次可达 ~3.4 s** |
89
+ | 额外依赖 | 无(仅系统 Cairo/Pango 等) | **需下载 Chromium ~190 MB+**,每次渲染有浏览器进程内存开销 |
90
+ | JavaScript | ❌ 不执行 | ✅ 可执行(KaTeX/Mermaid 等) |
91
+
92
+ 要点:稳态吞吐 pylitehtml **约快 1.4×**;真正的差距在**部署体积与冷启动** ——
93
+ 无需 ~190MB 的 Chromium、无浏览器进程,特别适合容器 / Serverless / 边缩缩容场景。
94
+ 需要执行 JS(数学排版、Mermaid 绘图)时仍应选 Playwright。
95
+
96
+ ```bash
97
+ pip install playwright && playwright install chromium # 或: uv pip install --group bench
98
+ python bench/bench_vs_playwright.py 30
99
+ ```
100
+
101
+ ## 安装
102
+
103
+ ```bash
104
+ pip install pylitehtml
105
+ ```
106
+
107
+ ## 快速上手
108
+
109
+ ```python
110
+ import pylitehtml
111
+
112
+ # 最简单:HTML 片段 → PNG(自动套用一套干净的默认样式)
113
+ png = pylitehtml.html_to_png("<h1>Hello</h1><p>世界</p>")
114
+ open("out.png", "wb").write(png)
115
+
116
+ # Markdown → PNG(零依赖内置转换器)
117
+ from pylitehtml.markdown import markdown_to_png
118
+ png = markdown_to_png("# 标题\n\n- 列表\n- [x] 任务")
119
+
120
+ # 需要精细控制时用底层接口:render / Renderer(不注入默认样式)
121
+ png = pylitehtml.render("<h1>Hello</h1>", width=800)
122
+ r = pylitehtml.Renderer(width=800) # 复用,字体只加载一次
123
+ jpg = r.render("<h1>Hello</h1>", fmt="jpeg", quality=90)
124
+
125
+ # 本地 HTML 文件(自动解析相对路径的 CSS/图片)+ Jinja2 模板
126
+ png = r.render_file("project/index.html")
127
+ png = r.render_file("project/order.html", title="订单", items=[...])
128
+
129
+ # 异步(不阻塞事件循环)
130
+ import asyncio
131
+ png = await asyncio.to_thread(r.render, "<h1>Hello</h1>")
132
+ ```
133
+
134
+ ---
135
+
136
+ ## 高级封装:html_to_png / markdown_to_png
137
+
138
+ `render()` 是最底层接口(HTML 字符串 → 图片)。在它之上提供了两个高层便捷函数。
139
+
140
+ ### `html_to_png` — 带默认样式的 HTML 渲染(核心、零额外依赖)
141
+
142
+ ```python
143
+ from pylitehtml import html_to_png, html_to_image, wrap_html, DEFAULT_CSS
144
+
145
+ # 传入“片段”时,自动套用一套干净的 GitHub 风默认样式
146
+ png = html_to_png("<h1>标题</h1><p>正文 <code>code</code></p>", width=720)
147
+
148
+ # 传入完整文档(含 <html>/<body>)时,按原样渲染,不再注入默认样式
149
+ png = html_to_png("<html><body style='background:#000'>…</body></html>")
150
+
151
+ # HiDPI:scale 同时放大画布宽度与(默认样式的)根字号,em 布局等比放大
152
+ png = html_to_png(fragment, width=720, scale=2)
153
+
154
+ # 追加/覆盖样式;或拿原始 RGBA 像素
155
+ png = html_to_png(fragment, extra_css="body{background:#0d1117;color:#e6edf3}")
156
+ raw = html_to_image(fragment, fmt="raw") # → RawResult(.data/.width/.height)
157
+ doc = wrap_html("<p>x</p>", css=DEFAULT_CSS) # 仅生成完整 HTML 文档字符串
158
+ ```
159
+
160
+ 主要参数:`width`、`scale`(HiDPI 倍数,默认 1)、`wrap`(`None` 自动判断片段/整文档;`True/False` 强制)、
161
+ `css` / `extra_css`、`fmt`(`"png"`/`"jpeg"`)、`quality`、`height`、`shrink_to_fit`、`locale`、`fonts`、`images`。
162
+
163
+ ### `markdown_to_png` — Markdown → HTML → 图片(可选、默认零依赖)
164
+
165
+ “用 HTML 渲染 Markdown”:内置一个**纯标准库**的轻量 Markdown→HTML 转换器,再交给 `html_to_png`。
166
+ **不引入** `markdown-it-py`、`pygments` 等任何第三方依赖。
167
+
168
+ ```python
169
+ from pylitehtml.markdown import markdown_to_png, markdown_to_html
170
+
171
+ png = markdown_to_png("# 标题\n\n- 列表\n- [x] 任务\n\n> 引用", width=720) # scale 默认 2
172
+ html = markdown_to_html("**bold**") # → '<p><strong>bold</strong></p>'
173
+ ```
174
+
175
+ 内置转换器覆盖:标题、粗/斜/`***粗斜***`/删除线/行内代码、反斜杠转义、链接/图片/裸 URL、
176
+ 行内 raw HTML、硬换行、围栏代码块(不高亮)、引用、有序(含 `start`)/无序/嵌套/任务列表、
177
+ 带对齐的 GFM 表格、分隔线。**不支持**:setext 标题、引用式链接、脚注、定义列表、缩进代码块。
178
+
179
+ 需要完整 CommonMark/GFM(脚注、定义列表、语法高亮)时传入 `converter=` 接入 markdown-it-py,
180
+ 见 [`examples/markdown_full_converter.py`](https://github.com/tyql688/pylitehtml/blob/main/examples/markdown_full_converter.py):
181
+
182
+ ```python
183
+ from markdown_it import MarkdownIt
184
+ from mdit_py_plugins.footnote import footnote_plugin
185
+ from mdit_py_plugins.deflist import deflist_plugin
186
+ from pylitehtml.markdown import markdown_to_png
187
+
188
+ md = MarkdownIt("gfm-like").use(footnote_plugin).use(deflist_plugin)
189
+ png = markdown_to_png(text, converter=md.render)
190
+ ```
191
+
192
+ > **不执行 JavaScript**:数学公式(KaTeX)与 Mermaid 无法排版/绘制,需调用前自行预渲染或接入完整引擎。
193
+
194
+ ---
195
+
196
+ ## 支持 / 不支持
197
+
198
+ litehtml = CSS 2.1 + 部分 CSS3。下表为**实测**结论:
199
+
200
+ | 能力 | 状态 |
201
+ | --- | --- |
202
+ | PNG / JPEG / RAW 输出 | ✅ |
203
+ | 盒模型、边框(solid/dashed/dotted/double)、`border-radius`、背景色 | ✅ |
204
+ | `linear-gradient` / `conic-gradient`(`radial-gradient` ⚠️ 仅颜色对) | ✅ |
205
+ | 字体、`color`、`text-align`、`line-height`、`text-shadow`、`text-transform` | ✅ |
206
+ | `text-decoration`、`<mark>`/`<sub>`/`<sup>`/`<kbd>`、`white-space:pre/nowrap` | ✅ |
207
+ | 列表(嵌套 / `list-style-type` / 任务列表)、定义列表、表格(对齐 / `:nth-child`) | ✅ |
208
+ | `float`、`inline-block`、`position:relative/absolute`、`text-overflow:ellipsis`、`::before/::after` | ✅ |
209
+ | 图片 `<img>`:`data:`(PNG/JPEG/WebP/SVG) / 本地 / HTTP·HTTPS、`@import` CSS | ✅ |
210
+ | 中文 / 多语言(内置 Noto Sans + SC,中英共享基线、子像素测量) | ✅ |
211
+ | 多线程并发、`asyncio.to_thread` | ✅ |
212
+ | Flexbox(简单行 / 列) | ⚠️ 部分 |
213
+ | `background-image:url()`、`box-shadow`、`transform`、`opacity`、`letter-spacing` | ❌ |
214
+ | CSS Grid、`var()`、`@font-face`、动画 / 过渡、`filter`、JavaScript | ❌ |
215
+
216
+ > 图片抓取失败会自动跳过(不报错);官方 wheel(Linux manylinux_2_34 / macOS / Windows)均含 OpenSSL ≥ 3.0,支持 https。
217
+
218
+ ---
219
+
220
+ ## API
221
+
222
+ ```python
223
+ # 高层(推荐):自动默认样式、片段/整文档自动判别、HiDPI scale
224
+ html_to_png(html, *, width=720, scale=1, wrap=None, css=DEFAULT_CSS, extra_css="",
225
+ fmt="png", quality=85, height=0, shrink_to_fit=True,
226
+ locale="en-US", fonts=None, images=None) -> bytes
227
+ html_to_image(...) # 同参数,fmt 可取 "raw" → RawResult(.data/.width/.height,RGBA 行主序)
228
+
229
+ # 底层:不注入默认样式
230
+ Renderer(width, *, locale="en-US", dpi=96.0, device_height=600, fonts=None, images=None)
231
+ Renderer.render(html, *, fmt="png", quality=85, height=0, shrink_to_fit=True)
232
+ Renderer.render_file(path, *, fmt="png", quality=85, height=0, shrink_to_fit=True, **template_data)
233
+ render(html, width, ...) / render_file(path, width, ...) # 一次性便捷函数
234
+
235
+ FontConfig(default="Noto Sans", size=16, extra=[]) # 已内置 Noto Sans/SC + DejaVu Sans
236
+ ImageConfig(cache_mb=64.0, timeout_ms=5000, max_mb=10.0, allow_http=True)
237
+ ```
238
+
239
+ - `fmt="raw"` 返回 RGBA:`Image.frombytes("RGBA",(raw.width,raw.height),raw.data)` 或 `np.frombuffer(...)`。
240
+ - `scale` 等比放大画布与(默认样式的)根字号;`shrink_to_fit` 把画布收窄到内容宽度。
241
+ - 内置字体使 `sans-serif`/`serif`/`monospace` 与中文在无系统字体时也能渲染;`dpi` 影响 `pt` 换算。
242
+
243
+ ---
244
+
245
+ ## render_file 与 Jinja2
246
+
247
+ 按标准网页组织目录,自动解析相对路径的 CSS/图片;传入关键字参数即作为
248
+ [Jinja2](https://jinja.palletsprojects.com/) 模板渲染(变量 / 循环 / 条件 / 过滤器 / `include` / `extends`):
249
+
250
+ ```python
251
+ png = r.render_file("project/index.html") # 纯文件
252
+ png = r.render_file("order.html", title="订单", items=[{"name": "苹果", "price": 5}]) # 模板
253
+ ```
254
+
255
+ > **autoescape 默认开启**:`.html` 模板里的 `{{ 变量 }}` 会转义 `<`/`&`/`"`,不可信数据也不会注入。
256
+ > **本地文件安全**:`file://` 与根路径资源仅在 `render_file()` 下加载;直接 `render()` 字符串时忽略。
257
+
258
+ ---
259
+
260
+ ## 线程 / 异步
261
+
262
+ 先在单线程构造 `Renderer`,之后可多线程并发 `render()`(渲染期间释放 GIL);
263
+ 异步用 `await asyncio.to_thread(r.render, html)`。带 `extra_fonts` 的构造会改写进程级字体配置,
264
+ 勿在渲染进行中于其它线程构造新 `Renderer`。
265
+
266
+ ---
267
+
268
+ ## 从源码构建
269
+
270
+ **Ubuntu / Debian**
271
+
272
+ ```bash
273
+ sudo apt-get install -y libcairo2-dev libpango1.0-dev libfontconfig1-dev \
274
+ libwebp-dev libjpeg-turbo8-dev libssl-dev cmake ninja-build pkg-config
275
+ pip install -e ".[dev]" --no-build-isolation
276
+ ```
277
+
278
+ **macOS**
279
+
280
+ ```bash
281
+ brew install cairo pango fontconfig webp jpeg-turbo openssl@3 cmake ninja
282
+ CC=/usr/bin/clang CXX=/usr/bin/clang++ pip install -e ".[dev]" --no-build-isolation
283
+ ```
284
+
285
+ **运行测试 / 代码检查**
286
+
287
+ ```bash
288
+ pytest tests/ -v
289
+ ruff check . # lint
290
+ ruff format . # 格式化(CI 用 `ruff format --check` 校验)
291
+ ```
292
+
293
+ ---
294
+
295
+ ## 基于
296
+
297
+ [litehtml](https://github.com/litehtml/litehtml) · [Cairo](https://www.cairographics.org/) · [Pango](https://pango.gnome.org/) · [FontConfig](https://www.freedesktop.org/wiki/Software/fontconfig/) · [pybind11](https://github.com/pybind/pybind11)
298
+
299
+ MIT License