weflow-cli 1.5.0 → 1.6.1

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 (332) hide show
  1. package/ARCHITECTURE.md +105 -0
  2. package/CHANGELOG.md +121 -0
  3. package/CONTRIBUTING.md +45 -0
  4. package/LICENSE +21 -21
  5. package/OPERATIONS.md +272 -0
  6. package/README.en.md +281 -0
  7. package/README.md +334 -149
  8. package/SECURITY.md +47 -0
  9. package/bin/weflow-cli.ts +4050 -581
  10. package/dist/bin/weflow-cli.js +4310 -588
  11. package/dist/bin/weflow-cli.js.map +1 -1
  12. package/dist/mcp-server/index.js +178 -236
  13. package/dist/mcp-server/index.js.map +1 -1
  14. package/dist/src/core/dbPathService.d.ts +15 -1
  15. package/dist/src/core/dbPathService.d.ts.map +1 -1
  16. package/dist/src/core/dbPathService.js +177 -19
  17. package/dist/src/core/dbPathService.js.map +1 -1
  18. package/dist/src/core/keyService.d.ts +8 -0
  19. package/dist/src/core/keyService.d.ts.map +1 -1
  20. package/dist/src/core/keyService.js +127 -22
  21. package/dist/src/core/keyService.js.map +1 -1
  22. package/dist/src/core/ntCore.d.ts +59 -1
  23. package/dist/src/core/ntCore.d.ts.map +1 -1
  24. package/dist/src/core/ntCore.js +201 -65
  25. package/dist/src/core/ntCore.js.map +1 -1
  26. package/dist/src/core/sqlcipherCore.d.ts.map +1 -1
  27. package/dist/src/core/sqlcipherCore.js +18 -1
  28. package/dist/src/core/sqlcipherCore.js.map +1 -1
  29. package/dist/src/core/wcdbCore.d.ts.map +1 -1
  30. package/dist/src/core/wcdbCore.js +3 -6
  31. package/dist/src/core/wcdbCore.js.map +1 -1
  32. package/dist/src/services/assistantDaemon.d.ts +19 -0
  33. package/dist/src/services/assistantDaemon.d.ts.map +1 -0
  34. package/dist/src/services/assistantDaemon.js +117 -0
  35. package/dist/src/services/assistantDaemon.js.map +1 -0
  36. package/dist/src/services/assistantMemory.d.ts +36 -0
  37. package/dist/src/services/assistantMemory.d.ts.map +1 -0
  38. package/dist/src/services/assistantMemory.js +182 -0
  39. package/dist/src/services/assistantMemory.js.map +1 -0
  40. package/dist/src/services/assistantPrivacy.d.ts +25 -0
  41. package/dist/src/services/assistantPrivacy.d.ts.map +1 -0
  42. package/dist/src/services/assistantPrivacy.js +77 -0
  43. package/dist/src/services/assistantPrivacy.js.map +1 -0
  44. package/dist/src/services/assistantRouting.d.ts +18 -0
  45. package/dist/src/services/assistantRouting.d.ts.map +1 -0
  46. package/dist/src/services/assistantRouting.js +68 -0
  47. package/dist/src/services/assistantRouting.js.map +1 -0
  48. package/dist/src/services/assistantService.d.ts +37 -0
  49. package/dist/src/services/assistantService.d.ts.map +1 -0
  50. package/dist/src/services/assistantService.js +284 -0
  51. package/dist/src/services/assistantService.js.map +1 -0
  52. package/dist/src/services/assistantTools.d.ts +24 -0
  53. package/dist/src/services/assistantTools.d.ts.map +1 -0
  54. package/dist/src/services/assistantTools.js +582 -0
  55. package/dist/src/services/assistantTools.js.map +1 -0
  56. package/dist/src/services/chatService.d.ts +44 -0
  57. package/dist/src/services/chatService.d.ts.map +1 -1
  58. package/dist/src/services/chatService.js +105 -4
  59. package/dist/src/services/chatService.js.map +1 -1
  60. package/dist/src/services/configService.d.ts +55 -0
  61. package/dist/src/services/configService.d.ts.map +1 -1
  62. package/dist/src/services/configService.js +147 -6
  63. package/dist/src/services/configService.js.map +1 -1
  64. package/dist/src/services/evidenceService.d.ts +30 -0
  65. package/dist/src/services/evidenceService.d.ts.map +1 -0
  66. package/dist/src/services/evidenceService.js +98 -0
  67. package/dist/src/services/evidenceService.js.map +1 -0
  68. package/dist/src/services/exportService.d.ts +13 -20
  69. package/dist/src/services/exportService.d.ts.map +1 -1
  70. package/dist/src/services/exportService.js +113 -47
  71. package/dist/src/services/exportService.js.map +1 -1
  72. package/dist/src/services/initKeyService.d.ts +19 -0
  73. package/dist/src/services/initKeyService.d.ts.map +1 -0
  74. package/dist/src/services/initKeyService.js +80 -0
  75. package/dist/src/services/initKeyService.js.map +1 -0
  76. package/dist/src/services/messageContract.d.ts +23 -0
  77. package/dist/src/services/messageContract.d.ts.map +1 -0
  78. package/dist/src/services/messageContract.js +49 -0
  79. package/dist/src/services/messageContract.js.map +1 -0
  80. package/dist/src/services/messageQuery.d.ts +7 -0
  81. package/dist/src/services/messageQuery.d.ts.map +1 -0
  82. package/dist/src/services/messageQuery.js +30 -0
  83. package/dist/src/services/messageQuery.js.map +1 -0
  84. package/dist/src/services/wechat-formatter.js +14 -14
  85. package/dist/src/services/wechatMessageService.d.ts.map +1 -1
  86. package/dist/src/services/wechatMessageService.js +31 -3
  87. package/dist/src/services/wechatMessageService.js.map +1 -1
  88. package/dist/src/services/whitelistService.d.ts +52 -4
  89. package/dist/src/services/whitelistService.d.ts.map +1 -1
  90. package/dist/src/services/whitelistService.js +183 -17
  91. package/dist/src/services/whitelistService.js.map +1 -1
  92. package/dist/src/types.d.ts +20 -0
  93. package/dist/src/types.d.ts.map +1 -1
  94. package/dist/src/utils/dateRange.d.ts +15 -0
  95. package/dist/src/utils/dateRange.d.ts.map +1 -0
  96. package/dist/src/utils/dateRange.js +48 -0
  97. package/dist/src/utils/dateRange.js.map +1 -0
  98. package/dist/src/utils/mcpSecurity.d.ts +5 -0
  99. package/dist/src/utils/mcpSecurity.d.ts.map +1 -0
  100. package/dist/src/utils/mcpSecurity.js +39 -0
  101. package/dist/src/utils/mcpSecurity.js.map +1 -0
  102. package/dist/src/utils/packageRoot.d.ts +2 -0
  103. package/dist/src/utils/packageRoot.d.ts.map +1 -0
  104. package/dist/src/utils/packageRoot.js +16 -0
  105. package/dist/src/utils/packageRoot.js.map +1 -0
  106. package/dist/src/utils/python.d.ts +2 -0
  107. package/dist/src/utils/python.d.ts.map +1 -0
  108. package/dist/src/utils/python.js +72 -0
  109. package/dist/src/utils/python.js.map +1 -0
  110. package/dist/src/utils/pythonProcessEnv.d.ts +3 -0
  111. package/dist/src/utils/pythonProcessEnv.d.ts.map +1 -0
  112. package/dist/src/utils/pythonProcessEnv.js +46 -0
  113. package/dist/src/utils/pythonProcessEnv.js.map +1 -0
  114. package/dist/src/utils/talkerUtils.d.ts +4 -1
  115. package/dist/src/utils/talkerUtils.d.ts.map +1 -1
  116. package/dist/src/utils/talkerUtils.js +9 -9
  117. package/dist/src/utils/talkerUtils.js.map +1 -1
  118. package/dist/src/utils/wechatEmoji.d.ts +5 -0
  119. package/dist/src/utils/wechatEmoji.d.ts.map +1 -0
  120. package/dist/src/utils/wechatEmoji.js +35 -0
  121. package/dist/src/utils/wechatEmoji.js.map +1 -0
  122. package/docs/AI_INTERFACE.md +189 -0
  123. package/docs/BRANCHES.md +87 -0
  124. package/docs/DATA_CONTRACT.md +74 -0
  125. package/docs/DECISIONS.md +270 -0
  126. package/docs/DEEPSEEK_V4_FLASH/346/226/275/345/267/245/346/226/207/346/241/243.md +234 -0
  127. package/docs/EVIDENCE_GUIDE.md +96 -0
  128. package/docs/MCP.md +95 -0
  129. package/docs/PARTNERS.md +41 -0
  130. package/docs/PROJECT_STATE.md +96 -0
  131. package/docs/RELEASING.md +124 -0
  132. package/docs/ROADMAP.md +191 -0
  133. package/docs/SETUP.md +103 -0
  134. package/docs/images/weflow-architecture-gpt-image-2.png +0 -0
  135. package/docs/images/weflow-architecture.png +0 -0
  136. package/docs/images/weflow-architecture.svg +65 -0
  137. package/mcp-server/index.ts +169 -269
  138. package/package.json +81 -72
  139. package/requirements-3x.txt +4 -0
  140. package/requirements-voice.txt +15 -0
  141. package/requirements.txt +9 -0
  142. package/resources/js/marked.min.js +69 -0
  143. package/resources/wechat-emoji/666.png +0 -0
  144. package/resources/wechat-emoji/Awesome.png +0 -0
  145. package/resources/wechat-emoji/Concerned.png +0 -0
  146. package/resources/wechat-emoji/Cry.png +0 -0
  147. package/resources/wechat-emoji/Emm.png +0 -0
  148. package/resources/wechat-emoji/Facepalm.png +0 -0
  149. package/resources/wechat-emoji/Grin.png +0 -0
  150. package/resources/wechat-emoji/OK.png +0 -0
  151. package/resources/wechat-emoji/Respect.png +0 -0
  152. package/resources/wechat-emoji/Sick.png +0 -0
  153. package/resources/wechat-emoji/Sleep.png +0 -0
  154. package/resources/wechat-emoji/Smile.png +0 -0
  155. package/resources/wechat-emoji//344/272/262/344/272/262.png +0 -0
  156. package/resources/wechat-emoji//344/276/277/344/276/277.png +0 -0
  157. package/resources/wechat-emoji//345/201/267/347/254/221.png +0 -0
  158. package/resources/wechat-emoji//345/202/262/346/205/242.png +0 -0
  159. package/resources/wechat-emoji//345/206/215/350/247/201.png +0 -0
  160. package/resources/wechat-emoji//345/207/213/350/260/242.png +0 -0
  161. package/resources/wechat-emoji//345/212/240/346/262/271.png +0 -0
  162. package/resources/wechat-emoji//345/213/276/345/274/225.png +0 -0
  163. package/resources/wechat-emoji//345/217/221/345/221/206.png +0 -0
  164. package/resources/wechat-emoji//345/217/221/346/200/222.png +0 -0
  165. package/resources/wechat-emoji//345/217/221/346/212/226.png +0 -0
  166. package/resources/wechat-emoji//345/217/257/346/200/234.png +0 -0
  167. package/resources/wechat-emoji//345/217/263/345/223/274/345/223/274.png +0 -0
  168. package/resources/wechat-emoji//345/217/271/346/260/224.png +0 -0
  169. package/resources/wechat-emoji//345/220/203/347/223/234.png +0 -0
  170. package/resources/wechat-emoji//345/220/210/345/215/201.png +0 -0
  171. package/resources/wechat-emoji//345/220/220.png +0 -0
  172. package/resources/wechat-emoji//345/221/262/347/211/231.png +0 -0
  173. package/resources/wechat-emoji//345/222/222/351/252/202.png +0 -0
  174. package/resources/wechat-emoji//345/222/226/345/225/241.png +0 -0
  175. package/resources/wechat-emoji//345/223/207.png +0 -0
  176. package/resources/wechat-emoji//345/225/244/351/205/222.png +0 -0
  177. package/resources/wechat-emoji//345/230/230.png +0 -0
  178. package/resources/wechat-emoji//345/230/264/345/224/207.png +0 -0
  179. package/resources/wechat-emoji//345/230/277/345/223/210.png +0 -0
  180. package/resources/wechat-emoji//345/233/247.png +0 -0
  181. package/resources/wechat-emoji//345/233/260.png +0 -0
  182. package/resources/wechat-emoji//345/235/217/347/254/221.png +0 -0
  183. package/resources/wechat-emoji//345/244/247/345/223/255.png +0 -0
  184. package/resources/wechat-emoji//345/244/251/345/225/212.png +0 -0
  185. package/resources/wechat-emoji//345/244/252/351/230/263.png +0 -0
  186. package/resources/wechat-emoji//345/244/261/346/234/233.png +0 -0
  187. package/resources/wechat-emoji//345/245/270/347/254/221.png +0 -0
  188. package/resources/wechat-emoji//345/245/275/347/232/204.png +0 -0
  189. package/resources/wechat-emoji//345/247/224/345/261/210.png +0 -0
  190. package/resources/wechat-emoji//345/256/263/347/276/236.png +0 -0
  191. package/resources/wechat-emoji//345/260/264/345/260/254.png +0 -0
  192. package/resources/wechat-emoji//345/272/206/347/245/235.png +0 -0
  193. package/resources/wechat-emoji//345/274/261.png +0 -0
  194. package/resources/wechat-emoji//345/274/272.png +0 -0
  195. package/resources/wechat-emoji//345/276/227/346/204/217.png +0 -0
  196. package/resources/wechat-emoji//345/276/256/347/254/221.png +0 -0
  197. package/resources/wechat-emoji//345/277/203/347/242/216.png +0 -0
  198. package/resources/wechat-emoji//345/277/253/345/223/255/344/272/206.png +0 -0
  199. package/resources/wechat-emoji//346/201/220/346/203/247.png +0 -0
  200. package/resources/wechat-emoji//346/202/240/351/227/262.png +0 -0
  201. package/resources/wechat-emoji//346/203/212/346/201/220.png +0 -0
  202. package/resources/wechat-emoji//346/203/212/350/256/266.png +0 -0
  203. package/resources/wechat-emoji//346/204/211/345/277/253.png +0 -0
  204. package/resources/wechat-emoji//346/206/250/347/254/221.png +0 -0
  205. package/resources/wechat-emoji//346/211/223/350/204/270.png +0 -0
  206. package/resources/wechat-emoji//346/212/223/347/213/202.png +0 -0
  207. package/resources/wechat-emoji//346/212/240/351/274/273.png +0 -0
  208. package/resources/wechat-emoji//346/212/261/346/213/263.png +0 -0
  209. package/resources/wechat-emoji//346/213/245/346/212/261.png +0 -0
  210. package/resources/wechat-emoji//346/213/263/345/244/264.png +0 -0
  211. package/resources/wechat-emoji//346/215/202/350/204/270.png +0 -0
  212. package/resources/wechat-emoji//346/217/241/346/211/213.png +0 -0
  213. package/resources/wechat-emoji//346/222/207/345/230/264.png +0 -0
  214. package/resources/wechat-emoji//346/223/246/346/261/227.png +0 -0
  215. package/resources/wechat-emoji//346/225/262/346/211/223.png +0 -0
  216. package/resources/wechat-emoji//346/227/240/350/257/255.png +0 -0
  217. package/resources/wechat-emoji//346/227/272/346/237/264.png +0 -0
  218. package/resources/wechat-emoji//346/231/225.png +0 -0
  219. package/resources/wechat-emoji//346/234/210/344/272/256.png +0 -0
  220. package/resources/wechat-emoji//346/234/272/346/231/272.png +0 -0
  221. package/resources/wechat-emoji//346/261/227.png +0 -0
  222. package/resources/wechat-emoji//346/265/201/346/263/252.png +0 -0
  223. package/resources/wechat-emoji//347/202/270/345/274/271.png +0 -0
  224. package/resources/wechat-emoji//347/203/237/350/212/261.png +0 -0
  225. package/resources/wechat-emoji//347/210/206/347/253/271.png +0 -0
  226. package/resources/wechat-emoji//347/210/261/345/277/203.png +0 -0
  227. package/resources/wechat-emoji//347/214/252/345/244/264.png +0 -0
  228. package/resources/wechat-emoji//347/216/253/347/221/260.png +0 -0
  229. package/resources/wechat-emoji//347/224/237/347/227/205.png +0 -0
  230. package/resources/wechat-emoji//347/226/221/351/227/256.png +0 -0
  231. package/resources/wechat-emoji//347/231/274.png +0 -0
  232. package/resources/wechat-emoji//347/231/275/347/234/274.png +0 -0
  233. package/resources/wechat-emoji//347/232/261/347/234/211.png +0 -0
  234. package/resources/wechat-emoji//347/235/241.png +0 -0
  235. package/resources/wechat-emoji//347/240/264/346/266/225/344/270/272/347/254/221.png +0 -0
  236. package/resources/wechat-emoji//347/244/274/347/211/251.png +0 -0
  237. package/resources/wechat-emoji//347/244/276/344/274/232/347/244/276/344/274/232.png +0 -0
  238. package/resources/wechat-emoji//347/246/217.png +0 -0
  239. package/resources/wechat-emoji//347/254/221/350/204/270.png +0 -0
  240. package/resources/wechat-emoji//347/272/242/345/214/205.png +0 -0
  241. package/resources/wechat-emoji//347/277/273/347/231/275/347/234/274.png +0 -0
  242. package/resources/wechat-emoji//350/200/266.png +0 -0
  243. package/resources/wechat-emoji//350/203/234/345/210/251.png +0 -0
  244. package/resources/wechat-emoji//350/204/270/347/272/242.png +0 -0
  245. package/resources/wechat-emoji//350/211/262.png +0 -0
  246. package/resources/wechat-emoji//350/213/246/346/266/251.png +0 -0
  247. package/resources/wechat-emoji//350/217/234/345/210/200.png +0 -0
  248. package/resources/wechat-emoji//350/233/213/347/263/225.png +0 -0
  249. package/resources/wechat-emoji//350/241/260.png +0 -0
  250. package/resources/wechat-emoji//350/243/202/345/274/200.png +0 -0
  251. package/resources/wechat-emoji//350/256/251/346/210/221/347/234/213/347/234/213.png +0 -0
  252. package/resources/wechat-emoji//350/260/203/347/232/256.png +0 -0
  253. package/resources/wechat-emoji//350/267/263/350/267/263.png +0 -0
  254. package/resources/wechat-emoji//350/275/254/345/234/210.png +0 -0
  255. package/resources/wechat-emoji//351/204/231/350/247/206.png +0 -0
  256. package/resources/wechat-emoji//351/227/255/345/230/264.png +0 -0
  257. package/resources/wechat-emoji//351/230/264/351/231/251.png +0 -0
  258. package/resources/wechat-emoji//351/232/276/350/277/207.png +0 -0
  259. package/resources/wechat-emoji//351/252/267/351/253/205.png +0 -0
  260. package/resources/wechat-emoji//351/274/223/346/216/214.png +0 -0
  261. package/scripts/_batch_link_sources.py +73 -73
  262. package/scripts/_utils.py +29 -0
  263. package/scripts/annual_report.py +796 -796
  264. package/scripts/auto_tag.py +128 -128
  265. package/scripts/biz_daily.py +210 -53
  266. package/scripts/chat_report.py +10 -0
  267. package/scripts/chat_stats.py +702 -702
  268. package/scripts/classify_daily.py +17 -11
  269. package/scripts/create_reading_notes.py +370 -370
  270. package/scripts/daily_stats.py +132 -0
  271. package/scripts/enrich_backlinks.py +163 -163
  272. package/scripts/export_chat_html.py +1704 -107
  273. package/scripts/extract_todos.py +445 -404
  274. package/scripts/fav_server.py +119 -12
  275. package/scripts/fix_topics.py +111 -111
  276. package/scripts/generate_ai_report.py +1 -1
  277. package/scripts/generate_html.py +597 -277
  278. package/scripts/inspection_records.py +354 -0
  279. package/scripts/mcp_bridge.py +398 -398
  280. package/scripts/nt_decrypt.py +702 -48
  281. package/scripts/pipeline.py +27 -19
  282. package/scripts/promote_all.py +312 -310
  283. package/scripts/promote_ideas.py +299 -297
  284. package/scripts/rag_chat.py +194 -191
  285. package/scripts/semantic_search.py +435 -431
  286. package/scripts/sync_fav.py +201 -146
  287. package/scripts/sync_weread.py +192 -192
  288. package/scripts/vault_rag.py +140 -139
  289. package/scripts/vault_search.py +141 -141
  290. package/scripts/wechat_emoji.py +132 -0
  291. package/scripts/wechat_emoticon.py +433 -0
  292. package/scripts/wechat_image.py +258 -0
  293. package/scripts/wechat_voice.py +327 -0
  294. package/src/core/dbPathService.ts +163 -18
  295. package/src/core/keyService.ts +137 -25
  296. package/src/core/ntCore.ts +215 -62
  297. package/src/core/sqlcipherCore.ts +17 -1
  298. package/src/core/wcdbCore.ts +3 -7
  299. package/src/services/assistantDaemon.ts +111 -0
  300. package/src/services/assistantMemory.ts +193 -0
  301. package/src/services/assistantPrivacy.ts +87 -0
  302. package/src/services/assistantRouting.ts +92 -0
  303. package/src/services/assistantService.ts +295 -0
  304. package/src/services/assistantTools.ts +549 -0
  305. package/src/services/chatService.ts +133 -4
  306. package/src/services/configService.ts +194 -6
  307. package/src/services/evidenceService.ts +129 -0
  308. package/src/services/exportService.ts +113 -48
  309. package/src/services/initKeyService.ts +83 -0
  310. package/src/services/messageContract.ts +77 -0
  311. package/src/services/messageQuery.ts +38 -0
  312. package/src/services/wechat-formatter.ts +348 -348
  313. package/src/services/wechatMessageService.ts +25 -3
  314. package/src/services/wereadService.ts +308 -308
  315. package/src/services/whitelistService.ts +209 -22
  316. package/src/types.ts +20 -0
  317. package/src/utils/dateRange.ts +58 -0
  318. package/src/utils/mcpSecurity.ts +39 -0
  319. package/src/utils/packageRoot.ts +14 -0
  320. package/src/utils/python.ts +73 -0
  321. package/src/utils/pythonProcessEnv.ts +45 -0
  322. package/src/utils/talkerUtils.ts +14 -2
  323. package/dist/src/utils/errors.d.ts +0 -25
  324. package/dist/src/utils/errors.d.ts.map +0 -1
  325. package/dist/src/utils/errors.js +0 -43
  326. package/dist/src/utils/errors.js.map +0 -1
  327. package/dist/src/utils/pythonRunner.d.ts +0 -27
  328. package/dist/src/utils/pythonRunner.d.ts.map +0 -1
  329. package/dist/src/utils/pythonRunner.js +0 -62
  330. package/dist/src/utils/pythonRunner.js.map +0 -1
  331. package/src/utils/errors.ts +0 -42
  332. package/src/utils/pythonRunner.ts +0 -81
@@ -1,348 +1,348 @@
1
- /**
2
- * 微信公众号 Markdown → HTML 排版转换器
3
- *
4
- * 基于 wechat-publisher-mcp 的 MarkdownConverter.js(MIT 许可)改写,
5
- * 增加多主题支持,输出微信兼容的 inline-style HTML。
6
- */
7
- export interface FormatOptions {
8
- theme?: 'default' | 'warm' | 'minimal' | 'green';
9
- fontSize?: number;
10
- lineHeight?: number;
11
- }
12
-
13
- interface ThemeConfig {
14
- id: string;
15
- name: string;
16
- description: string;
17
- h1: { color: string; border: string };
18
- h2: { color: string; prefix: string };
19
- h3: { color: string; prefix: string };
20
- h4: { color: string; prefix: string };
21
- bold: { color: string };
22
- italic: { color: string };
23
- del: { color: string };
24
- codeBlock: { bg: string; border: string };
25
- inlineCode: { bg: string; color: string };
26
- blockquote: { border: string; bg: string; color: string };
27
- link: { color: string };
28
- }
29
-
30
- const THEMES: Record<string, ThemeConfig> = {
31
- default: {
32
- id: 'default',
33
- name: '经典蓝',
34
- description: '蓝色强调 + 红色重点,适配大多数内容',
35
- h1: { color: '#2c3e50', border: '#3498db' },
36
- h2: { color: '#3498db', prefix: '🔹' },
37
- h3: { color: '#27ae60', prefix: '▶' },
38
- h4: { color: '#8e44ad', prefix: '•' },
39
- bold: { color: '#e74c3c' },
40
- italic: { color: '#9b59b6' },
41
- del: { color: '#95a5a6' },
42
- codeBlock: { bg: '#f8f9fa', border: '#e9ecef' },
43
- inlineCode: { bg: '#f1f3f4', color: '#e91e63' },
44
- blockquote: { border: '#3498db', bg: '#f8fafb', color: '#555' },
45
- link: { color: '#3498db' },
46
- },
47
- warm: {
48
- id: 'warm',
49
- name: '暖橙',
50
- description: '温暖橙色系,适合生活/人文类内容',
51
- h1: { color: '#c0392b', border: '#e67e22' },
52
- h2: { color: '#e67e22', prefix: '🔥' },
53
- h3: { color: '#d35400', prefix: '▸' },
54
- h4: { color: '#a0522d', prefix: '·' },
55
- bold: { color: '#c0392b' },
56
- italic: { color: '#d35400' },
57
- del: { color: '#bdc3c7' },
58
- codeBlock: { bg: '#fef9f4', border: '#f5d9b5' },
59
- inlineCode: { bg: '#fdf2e9', color: '#c0392b' },
60
- blockquote: { border: '#e67e22', bg: '#fef9f4', color: '#7f5539' },
61
- link: { color: '#e67e22' },
62
- },
63
- minimal: {
64
- id: 'minimal',
65
- name: '极简黑白',
66
- description: '黑白灰极简风,适合技术/严肃内容',
67
- h1: { color: '#1a1a1a', border: '#333' },
68
- h2: { color: '#333', prefix: '#' },
69
- h3: { color: '#555', prefix: '##' },
70
- h4: { color: '#777', prefix: '###' },
71
- bold: { color: '#1a1a1a' },
72
- italic: { color: '#666' },
73
- del: { color: '#aaa' },
74
- codeBlock: { bg: '#f5f5f5', border: '#ddd' },
75
- inlineCode: { bg: '#f0f0f0', color: '#333' },
76
- blockquote: { border: '#999', bg: '#f9f9f9', color: '#666' },
77
- link: { color: '#333' },
78
- },
79
- green: {
80
- id: 'green',
81
- name: '清新绿',
82
- description: '绿色自然系,适合健康/科普/环保内容',
83
- h1: { color: '#1e5631', border: '#27ae60' },
84
- h2: { color: '#27ae60', prefix: '🌿' },
85
- h3: { color: '#2ecc71', prefix: '▹' },
86
- h4: { color: '#16a085', prefix: '◦' },
87
- bold: { color: '#27ae60' },
88
- italic: { color: '#2ecc71' },
89
- del: { color: '#a0c4a8' },
90
- codeBlock: { bg: '#f0faf3', border: '#c8e6c9' },
91
- inlineCode: { bg: '#e8f5e9', color: '#1e5631' },
92
- blockquote: { border: '#27ae60', bg: '#f0faf3', color: '#2e7d32' },
93
- link: { color: '#27ae60' },
94
- },
95
- };
96
-
97
- /** 列出所有可用主题 */
98
- export function listThemes(): { id: string; name: string; description: string }[] {
99
- return Object.values(THEMES).map(t => ({
100
- id: t.id,
101
- name: t.name,
102
- description: t.description,
103
- }));
104
- }
105
-
106
- /** 获取单个主题配置 */
107
- export function getTheme(id: string): ThemeConfig | undefined {
108
- return THEMES[id];
109
- }
110
-
111
- /** HTML 实体转义 */
112
- function escapeHtml(text: string): string {
113
- const map: Record<string, string> = {
114
- '&': '&amp;',
115
- '<': '&lt;',
116
- '>': '&gt;',
117
- '"': '&quot;',
118
- "'": '&#039;',
119
- };
120
- return text.replace(/[&<>"']/g, m => map[m]);
121
- }
122
-
123
- /** 主入口:Markdown → 微信兼容 HTML */
124
- export function formatWeChatArticle(markdown: string, options: FormatOptions = {}): string {
125
- if (!markdown || typeof markdown !== 'string') return '';
126
-
127
- const theme = THEMES[options.theme || 'default'] || THEMES.default;
128
- const fontSize = options.fontSize || 16;
129
- const lineHeight = options.lineHeight || 1.8;
130
-
131
- let html = markdown;
132
-
133
- // 1. 代码块(最先处理,避免被后续规则影响)
134
- html = convertCodeBlocks(html, theme);
135
-
136
- // 2. 标题
137
- html = convertHeadings(html, theme);
138
-
139
- // 3. 文本格式
140
- html = convertTextFormatting(html, theme);
141
-
142
- // 4. 列表
143
- html = convertLists(html);
144
-
145
- // 5. 引用
146
- html = convertBlockquotes(html, theme);
147
-
148
- // 6. 链接
149
- html = convertLinks(html, theme);
150
-
151
- // 7. 表格
152
- html = convertTables(html);
153
-
154
- // 8. 段落
155
- html = convertParagraphs(html, fontSize, lineHeight);
156
-
157
- // 9. 清理
158
- html = cleanupHTML(html);
159
-
160
- // 10. 添加基础样式
161
- return addBaseStyles(html, fontSize, lineHeight);
162
- }
163
-
164
- function convertCodeBlocks(html: string, theme: ThemeConfig): string {
165
- // 围栏代码块
166
- html = html.replace(
167
- /```(\w+)?\n([\s\S]*?)```/g,
168
- (_match, lang, code) => {
169
- const language = lang || 'text';
170
- return `<pre data-language="${language}" style="background: ${theme.codeBlock.bg}; padding: 16px; border-radius: 8px; overflow-x: auto; font-size: 14px; line-height: 1.4; border: 1px solid ${theme.codeBlock.border}; margin: 16px 0;"><code style="color: #333; background: none; padding: 0;">${escapeHtml(code.trim())}</code></pre>`;
171
- }
172
- );
173
-
174
- // 行内代码
175
- html = html.replace(
176
- /`([^`]+)`/g,
177
- `<code style="background: ${theme.inlineCode.bg}; color: ${theme.inlineCode.color}; padding: 2px 6px; border-radius: 4px; font-size: 0.9em;">$1</code>`
178
- );
179
-
180
- return html;
181
- }
182
-
183
- function convertHeadings(html: string, theme: ThemeConfig): string {
184
- html = html.replace(
185
- /^# (.+)$/gm,
186
- `<h1 style="color: ${theme.h1.color}; font-size: 26px; font-weight: bold; margin: 24px 0 16px 0; line-height: 1.3; border-bottom: 3px solid ${theme.h1.border}; padding-bottom: 8px;">$1</h1>`
187
- );
188
- html = html.replace(
189
- /^## (.+)$/gm,
190
- `<h2 style="color: ${theme.h2.color}; font-size: 22px; font-weight: bold; margin: 20px 0 12px 0; line-height: 1.3;">${theme.h2.prefix} $1</h2>`
191
- );
192
- html = html.replace(
193
- /^### (.+)$/gm,
194
- `<h3 style="color: ${theme.h3.color}; font-size: 18px; font-weight: bold; margin: 18px 0 10px 0; line-height: 1.3;">${theme.h3.prefix} $1</h3>`
195
- );
196
- html = html.replace(
197
- /^#### (.+)$/gm,
198
- `<h4 style="color: ${theme.h4.color}; font-size: 17px; font-weight: bold; margin: 16px 0 8px 0; line-height: 1.3;">${theme.h4.prefix} $1</h4>`
199
- );
200
- return html;
201
- }
202
-
203
- function convertTextFormatting(html: string, theme: ThemeConfig): string {
204
- html = html.replace(
205
- /\*\*(.+?)\*\*/g,
206
- `<strong style="color: ${theme.bold.color}; font-weight: bold;">$1</strong>`
207
- );
208
- html = html.replace(
209
- /\*(?!\*)(.+?)(?<!\*)\*/g,
210
- `<em style="color: ${theme.italic.color}; font-style: italic;">$1</em>`
211
- );
212
- html = html.replace(
213
- /~~(.+?)~~/g,
214
- `<del style="color: ${theme.del.color}; text-decoration: line-through;">$1</del>`
215
- );
216
- return html;
217
- }
218
-
219
- function convertLists(html: string): string {
220
- // 有序列表
221
- html = html.replace(
222
- /^\d+\.\s+(.+)$/gm,
223
- '<li style="margin: 8px 0; line-height: 1.6;">$1</li>'
224
- );
225
- // 无序列表
226
- html = html.replace(
227
- /^[-*+]\s+(.+)$/gm,
228
- '<li style="margin: 8px 0; line-height: 1.6;">$1</li>'
229
- );
230
- // 包裹连续的 <li>
231
- html = html.replace(
232
- /(<li[^>]*>.*?<\/li>(\s*<li[^>]*>.*?<\/li>)*)/gs,
233
- (match: string) => `<ul style="margin: 16px 0; padding-left: 24px; list-style-type: disc;">${match}</ul>`
234
- );
235
- return html;
236
- }
237
-
238
- function convertBlockquotes(html: string, theme: ThemeConfig): string {
239
- return html.replace(
240
- /^>\s*(.+)$/gm,
241
- `<blockquote style="border-left: 4px solid ${theme.blockquote.border}; padding: 16px 20px; margin: 16px 0; background: ${theme.blockquote.bg}; font-style: italic; color: ${theme.blockquote.color}; border-radius: 0 8px 8px 0;">$1</blockquote>`
242
- );
243
- }
244
-
245
- function convertLinks(html: string, theme: ThemeConfig): string {
246
- return html.replace(
247
- /\[([^\]]+)\]\(([^)]+)\)/g,
248
- `<a href="$2" style="color: ${theme.link.color}; text-decoration: none; border-bottom: 1px dotted ${theme.link.color};" target="_blank">$1</a>`
249
- );
250
- }
251
-
252
- function convertTables(html: string): string {
253
- const lines = html.split('\n');
254
- let inTable = false;
255
- let tableLines: string[] = [];
256
- const result: string[] = [];
257
-
258
- for (const line of lines) {
259
- const trimmed = line.trim();
260
- if (trimmed.includes('|') && !inTable) {
261
- inTable = true;
262
- tableLines = [trimmed];
263
- } else if (trimmed.includes('|') && inTable) {
264
- tableLines.push(trimmed);
265
- } else if (inTable) {
266
- if (tableLines.length > 0) result.push(convertTableToHTML(tableLines));
267
- inTable = false;
268
- tableLines = [];
269
- result.push(line);
270
- } else {
271
- result.push(line);
272
- }
273
- }
274
- if (inTable && tableLines.length > 0) {
275
- result.push(convertTableToHTML(tableLines));
276
- }
277
- return result.join('\n');
278
- }
279
-
280
- function convertTableToHTML(tableLines: string[]): string {
281
- if (tableLines.length < 2) return tableLines.join('\n');
282
-
283
- const headerLine = tableLines[0];
284
- const separatorLine = tableLines[1];
285
- const dataLines = tableLines.slice(2);
286
-
287
- const headers = headerLine.split('|').map(h => h.trim()).filter(h => h);
288
- if (!separatorLine.includes('-')) return tableLines.join('\n');
289
-
290
- let tableHTML =
291
- '<table style="width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">';
292
- tableHTML += '<thead><tr style="background: #f8f9fa;">';
293
- headers.forEach(header => {
294
- tableHTML += `<th style="border: 1px solid #dee2e6; padding: 12px 8px; text-align: left; font-weight: bold; color: #495057;">${header}</th>`;
295
- });
296
- tableHTML += '</tr></thead><tbody>';
297
- dataLines.forEach((line, index) => {
298
- const cells = line.split('|').map(c => c.trim()).filter(c => c);
299
- const bg = index % 2 === 0 ? '#ffffff' : '#f8f9fa';
300
- tableHTML += `<tr style="background: ${bg};">`;
301
- cells.forEach(cell => {
302
- tableHTML += `<th style="border: 1px solid #dee2e6; padding: 12px 8px; color: #495057;">${cell}</th>`;
303
- });
304
- tableHTML += '</tr>';
305
- });
306
- tableHTML += '</tbody></table>';
307
- return tableHTML;
308
- }
309
-
310
- function convertParagraphs(html: string, fontSize: number, lineHeight: number): string {
311
- html = html.replace(
312
- /\n\s*\n/g,
313
- `</p><p style="margin: 15px 0; line-height: ${lineHeight}; text-align: justify; color: #333; font-size: ${fontSize}px;">`
314
- );
315
- html =
316
- `<p style="margin: 15px 0; line-height: ${lineHeight}; text-align: justify; color: #333; font-size: ${fontSize}px;">${html}</p>`;
317
- return html;
318
- }
319
-
320
- function cleanupHTML(html: string): string {
321
- html = html.replace(/<p[^>]*>\s*<\/p>/g, '');
322
- html = html.replace(/<p[^>]*>(\s*<h[1-6][^>]*>.*?<\/h[1-6]>\s*)<\/p>/g, '$1');
323
- html = html.replace(/<p[^>]*>(\s*<ul[^>]*>.*?<\/ul>\s*)<\/p>/gs, '$1');
324
- html = html.replace(/<p[^>]*>(\s*<ol[^>]*>.*?<\/ol>\s*)<\/p>/gs, '$1');
325
- html = html.replace(/<p[^>]*>(\s*<blockquote[^>]*>.*?<\/blockquote>\s*)<\/p>/gs, '$1');
326
- html = html.replace(/<p[^>]*>(\s*<pre[^>]*>.*?<\/pre>\s*)<\/p>/gs, '$1');
327
- html = html.replace(/<p[^>]*>(\s*<table[^>]*>.*?<\/table>\s*)<\/p>/gs, '$1');
328
- return html;
329
- }
330
-
331
- function addBaseStyles(html: string, fontSize: number, lineHeight: number): string {
332
- const style = `
333
- <style>
334
- body {
335
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
336
- line-height: ${lineHeight};
337
- color: #333;
338
- background: #fff;
339
- font-size: ${fontSize}px;
340
- margin: 0;
341
- padding: 20px;
342
- }
343
- img { max-width: 100%; height: auto; display: block; margin: 16px auto; border-radius: 8px; }
344
- hr { border: none; height: 1px; background: linear-gradient(to right, transparent, #ddd, transparent); margin: 24px 0; }
345
- </style>
346
- `;
347
- return style + html;
348
- }
1
+ /**
2
+ * 微信公众号 Markdown → HTML 排版转换器
3
+ *
4
+ * 基于 wechat-publisher-mcp 的 MarkdownConverter.js(MIT 许可)改写,
5
+ * 增加多主题支持,输出微信兼容的 inline-style HTML。
6
+ */
7
+ export interface FormatOptions {
8
+ theme?: 'default' | 'warm' | 'minimal' | 'green';
9
+ fontSize?: number;
10
+ lineHeight?: number;
11
+ }
12
+
13
+ interface ThemeConfig {
14
+ id: string;
15
+ name: string;
16
+ description: string;
17
+ h1: { color: string; border: string };
18
+ h2: { color: string; prefix: string };
19
+ h3: { color: string; prefix: string };
20
+ h4: { color: string; prefix: string };
21
+ bold: { color: string };
22
+ italic: { color: string };
23
+ del: { color: string };
24
+ codeBlock: { bg: string; border: string };
25
+ inlineCode: { bg: string; color: string };
26
+ blockquote: { border: string; bg: string; color: string };
27
+ link: { color: string };
28
+ }
29
+
30
+ const THEMES: Record<string, ThemeConfig> = {
31
+ default: {
32
+ id: 'default',
33
+ name: '经典蓝',
34
+ description: '蓝色强调 + 红色重点,适配大多数内容',
35
+ h1: { color: '#2c3e50', border: '#3498db' },
36
+ h2: { color: '#3498db', prefix: '🔹' },
37
+ h3: { color: '#27ae60', prefix: '▶' },
38
+ h4: { color: '#8e44ad', prefix: '•' },
39
+ bold: { color: '#e74c3c' },
40
+ italic: { color: '#9b59b6' },
41
+ del: { color: '#95a5a6' },
42
+ codeBlock: { bg: '#f8f9fa', border: '#e9ecef' },
43
+ inlineCode: { bg: '#f1f3f4', color: '#e91e63' },
44
+ blockquote: { border: '#3498db', bg: '#f8fafb', color: '#555' },
45
+ link: { color: '#3498db' },
46
+ },
47
+ warm: {
48
+ id: 'warm',
49
+ name: '暖橙',
50
+ description: '温暖橙色系,适合生活/人文类内容',
51
+ h1: { color: '#c0392b', border: '#e67e22' },
52
+ h2: { color: '#e67e22', prefix: '🔥' },
53
+ h3: { color: '#d35400', prefix: '▸' },
54
+ h4: { color: '#a0522d', prefix: '·' },
55
+ bold: { color: '#c0392b' },
56
+ italic: { color: '#d35400' },
57
+ del: { color: '#bdc3c7' },
58
+ codeBlock: { bg: '#fef9f4', border: '#f5d9b5' },
59
+ inlineCode: { bg: '#fdf2e9', color: '#c0392b' },
60
+ blockquote: { border: '#e67e22', bg: '#fef9f4', color: '#7f5539' },
61
+ link: { color: '#e67e22' },
62
+ },
63
+ minimal: {
64
+ id: 'minimal',
65
+ name: '极简黑白',
66
+ description: '黑白灰极简风,适合技术/严肃内容',
67
+ h1: { color: '#1a1a1a', border: '#333' },
68
+ h2: { color: '#333', prefix: '#' },
69
+ h3: { color: '#555', prefix: '##' },
70
+ h4: { color: '#777', prefix: '###' },
71
+ bold: { color: '#1a1a1a' },
72
+ italic: { color: '#666' },
73
+ del: { color: '#aaa' },
74
+ codeBlock: { bg: '#f5f5f5', border: '#ddd' },
75
+ inlineCode: { bg: '#f0f0f0', color: '#333' },
76
+ blockquote: { border: '#999', bg: '#f9f9f9', color: '#666' },
77
+ link: { color: '#333' },
78
+ },
79
+ green: {
80
+ id: 'green',
81
+ name: '清新绿',
82
+ description: '绿色自然系,适合健康/科普/环保内容',
83
+ h1: { color: '#1e5631', border: '#27ae60' },
84
+ h2: { color: '#27ae60', prefix: '🌿' },
85
+ h3: { color: '#2ecc71', prefix: '▹' },
86
+ h4: { color: '#16a085', prefix: '◦' },
87
+ bold: { color: '#27ae60' },
88
+ italic: { color: '#2ecc71' },
89
+ del: { color: '#a0c4a8' },
90
+ codeBlock: { bg: '#f0faf3', border: '#c8e6c9' },
91
+ inlineCode: { bg: '#e8f5e9', color: '#1e5631' },
92
+ blockquote: { border: '#27ae60', bg: '#f0faf3', color: '#2e7d32' },
93
+ link: { color: '#27ae60' },
94
+ },
95
+ };
96
+
97
+ /** 列出所有可用主题 */
98
+ export function listThemes(): { id: string; name: string; description: string }[] {
99
+ return Object.values(THEMES).map(t => ({
100
+ id: t.id,
101
+ name: t.name,
102
+ description: t.description,
103
+ }));
104
+ }
105
+
106
+ /** 获取单个主题配置 */
107
+ export function getTheme(id: string): ThemeConfig | undefined {
108
+ return THEMES[id];
109
+ }
110
+
111
+ /** HTML 实体转义 */
112
+ function escapeHtml(text: string): string {
113
+ const map: Record<string, string> = {
114
+ '&': '&amp;',
115
+ '<': '&lt;',
116
+ '>': '&gt;',
117
+ '"': '&quot;',
118
+ "'": '&#039;',
119
+ };
120
+ return text.replace(/[&<>"']/g, m => map[m]);
121
+ }
122
+
123
+ /** 主入口:Markdown → 微信兼容 HTML */
124
+ export function formatWeChatArticle(markdown: string, options: FormatOptions = {}): string {
125
+ if (!markdown || typeof markdown !== 'string') return '';
126
+
127
+ const theme = THEMES[options.theme || 'default'] || THEMES.default;
128
+ const fontSize = options.fontSize || 16;
129
+ const lineHeight = options.lineHeight || 1.8;
130
+
131
+ let html = markdown;
132
+
133
+ // 1. 代码块(最先处理,避免被后续规则影响)
134
+ html = convertCodeBlocks(html, theme);
135
+
136
+ // 2. 标题
137
+ html = convertHeadings(html, theme);
138
+
139
+ // 3. 文本格式
140
+ html = convertTextFormatting(html, theme);
141
+
142
+ // 4. 列表
143
+ html = convertLists(html);
144
+
145
+ // 5. 引用
146
+ html = convertBlockquotes(html, theme);
147
+
148
+ // 6. 链接
149
+ html = convertLinks(html, theme);
150
+
151
+ // 7. 表格
152
+ html = convertTables(html);
153
+
154
+ // 8. 段落
155
+ html = convertParagraphs(html, fontSize, lineHeight);
156
+
157
+ // 9. 清理
158
+ html = cleanupHTML(html);
159
+
160
+ // 10. 添加基础样式
161
+ return addBaseStyles(html, fontSize, lineHeight);
162
+ }
163
+
164
+ function convertCodeBlocks(html: string, theme: ThemeConfig): string {
165
+ // 围栏代码块
166
+ html = html.replace(
167
+ /```(\w+)?\n([\s\S]*?)```/g,
168
+ (_match, lang, code) => {
169
+ const language = lang || 'text';
170
+ return `<pre data-language="${language}" style="background: ${theme.codeBlock.bg}; padding: 16px; border-radius: 8px; overflow-x: auto; font-size: 14px; line-height: 1.4; border: 1px solid ${theme.codeBlock.border}; margin: 16px 0;"><code style="color: #333; background: none; padding: 0;">${escapeHtml(code.trim())}</code></pre>`;
171
+ }
172
+ );
173
+
174
+ // 行内代码
175
+ html = html.replace(
176
+ /`([^`]+)`/g,
177
+ `<code style="background: ${theme.inlineCode.bg}; color: ${theme.inlineCode.color}; padding: 2px 6px; border-radius: 4px; font-size: 0.9em;">$1</code>`
178
+ );
179
+
180
+ return html;
181
+ }
182
+
183
+ function convertHeadings(html: string, theme: ThemeConfig): string {
184
+ html = html.replace(
185
+ /^# (.+)$/gm,
186
+ `<h1 style="color: ${theme.h1.color}; font-size: 26px; font-weight: bold; margin: 24px 0 16px 0; line-height: 1.3; border-bottom: 3px solid ${theme.h1.border}; padding-bottom: 8px;">$1</h1>`
187
+ );
188
+ html = html.replace(
189
+ /^## (.+)$/gm,
190
+ `<h2 style="color: ${theme.h2.color}; font-size: 22px; font-weight: bold; margin: 20px 0 12px 0; line-height: 1.3;">${theme.h2.prefix} $1</h2>`
191
+ );
192
+ html = html.replace(
193
+ /^### (.+)$/gm,
194
+ `<h3 style="color: ${theme.h3.color}; font-size: 18px; font-weight: bold; margin: 18px 0 10px 0; line-height: 1.3;">${theme.h3.prefix} $1</h3>`
195
+ );
196
+ html = html.replace(
197
+ /^#### (.+)$/gm,
198
+ `<h4 style="color: ${theme.h4.color}; font-size: 17px; font-weight: bold; margin: 16px 0 8px 0; line-height: 1.3;">${theme.h4.prefix} $1</h4>`
199
+ );
200
+ return html;
201
+ }
202
+
203
+ function convertTextFormatting(html: string, theme: ThemeConfig): string {
204
+ html = html.replace(
205
+ /\*\*(.+?)\*\*/g,
206
+ `<strong style="color: ${theme.bold.color}; font-weight: bold;">$1</strong>`
207
+ );
208
+ html = html.replace(
209
+ /\*(?!\*)(.+?)(?<!\*)\*/g,
210
+ `<em style="color: ${theme.italic.color}; font-style: italic;">$1</em>`
211
+ );
212
+ html = html.replace(
213
+ /~~(.+?)~~/g,
214
+ `<del style="color: ${theme.del.color}; text-decoration: line-through;">$1</del>`
215
+ );
216
+ return html;
217
+ }
218
+
219
+ function convertLists(html: string): string {
220
+ // 有序列表
221
+ html = html.replace(
222
+ /^\d+\.\s+(.+)$/gm,
223
+ '<li style="margin: 8px 0; line-height: 1.6;">$1</li>'
224
+ );
225
+ // 无序列表
226
+ html = html.replace(
227
+ /^[-*+]\s+(.+)$/gm,
228
+ '<li style="margin: 8px 0; line-height: 1.6;">$1</li>'
229
+ );
230
+ // 包裹连续的 <li>
231
+ html = html.replace(
232
+ /(<li[^>]*>.*?<\/li>(\s*<li[^>]*>.*?<\/li>)*)/gs,
233
+ (match: string) => `<ul style="margin: 16px 0; padding-left: 24px; list-style-type: disc;">${match}</ul>`
234
+ );
235
+ return html;
236
+ }
237
+
238
+ function convertBlockquotes(html: string, theme: ThemeConfig): string {
239
+ return html.replace(
240
+ /^>\s*(.+)$/gm,
241
+ `<blockquote style="border-left: 4px solid ${theme.blockquote.border}; padding: 16px 20px; margin: 16px 0; background: ${theme.blockquote.bg}; font-style: italic; color: ${theme.blockquote.color}; border-radius: 0 8px 8px 0;">$1</blockquote>`
242
+ );
243
+ }
244
+
245
+ function convertLinks(html: string, theme: ThemeConfig): string {
246
+ return html.replace(
247
+ /\[([^\]]+)\]\(([^)]+)\)/g,
248
+ `<a href="$2" style="color: ${theme.link.color}; text-decoration: none; border-bottom: 1px dotted ${theme.link.color};" target="_blank">$1</a>`
249
+ );
250
+ }
251
+
252
+ function convertTables(html: string): string {
253
+ const lines = html.split('\n');
254
+ let inTable = false;
255
+ let tableLines: string[] = [];
256
+ const result: string[] = [];
257
+
258
+ for (const line of lines) {
259
+ const trimmed = line.trim();
260
+ if (trimmed.includes('|') && !inTable) {
261
+ inTable = true;
262
+ tableLines = [trimmed];
263
+ } else if (trimmed.includes('|') && inTable) {
264
+ tableLines.push(trimmed);
265
+ } else if (inTable) {
266
+ if (tableLines.length > 0) result.push(convertTableToHTML(tableLines));
267
+ inTable = false;
268
+ tableLines = [];
269
+ result.push(line);
270
+ } else {
271
+ result.push(line);
272
+ }
273
+ }
274
+ if (inTable && tableLines.length > 0) {
275
+ result.push(convertTableToHTML(tableLines));
276
+ }
277
+ return result.join('\n');
278
+ }
279
+
280
+ function convertTableToHTML(tableLines: string[]): string {
281
+ if (tableLines.length < 2) return tableLines.join('\n');
282
+
283
+ const headerLine = tableLines[0];
284
+ const separatorLine = tableLines[1];
285
+ const dataLines = tableLines.slice(2);
286
+
287
+ const headers = headerLine.split('|').map(h => h.trim()).filter(h => h);
288
+ if (!separatorLine.includes('-')) return tableLines.join('\n');
289
+
290
+ let tableHTML =
291
+ '<table style="width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">';
292
+ tableHTML += '<thead><tr style="background: #f8f9fa;">';
293
+ headers.forEach(header => {
294
+ tableHTML += `<th style="border: 1px solid #dee2e6; padding: 12px 8px; text-align: left; font-weight: bold; color: #495057;">${header}</th>`;
295
+ });
296
+ tableHTML += '</tr></thead><tbody>';
297
+ dataLines.forEach((line, index) => {
298
+ const cells = line.split('|').map(c => c.trim()).filter(c => c);
299
+ const bg = index % 2 === 0 ? '#ffffff' : '#f8f9fa';
300
+ tableHTML += `<tr style="background: ${bg};">`;
301
+ cells.forEach(cell => {
302
+ tableHTML += `<th style="border: 1px solid #dee2e6; padding: 12px 8px; color: #495057;">${cell}</th>`;
303
+ });
304
+ tableHTML += '</tr>';
305
+ });
306
+ tableHTML += '</tbody></table>';
307
+ return tableHTML;
308
+ }
309
+
310
+ function convertParagraphs(html: string, fontSize: number, lineHeight: number): string {
311
+ html = html.replace(
312
+ /\n\s*\n/g,
313
+ `</p><p style="margin: 15px 0; line-height: ${lineHeight}; text-align: justify; color: #333; font-size: ${fontSize}px;">`
314
+ );
315
+ html =
316
+ `<p style="margin: 15px 0; line-height: ${lineHeight}; text-align: justify; color: #333; font-size: ${fontSize}px;">${html}</p>`;
317
+ return html;
318
+ }
319
+
320
+ function cleanupHTML(html: string): string {
321
+ html = html.replace(/<p[^>]*>\s*<\/p>/g, '');
322
+ html = html.replace(/<p[^>]*>(\s*<h[1-6][^>]*>.*?<\/h[1-6]>\s*)<\/p>/g, '$1');
323
+ html = html.replace(/<p[^>]*>(\s*<ul[^>]*>.*?<\/ul>\s*)<\/p>/gs, '$1');
324
+ html = html.replace(/<p[^>]*>(\s*<ol[^>]*>.*?<\/ol>\s*)<\/p>/gs, '$1');
325
+ html = html.replace(/<p[^>]*>(\s*<blockquote[^>]*>.*?<\/blockquote>\s*)<\/p>/gs, '$1');
326
+ html = html.replace(/<p[^>]*>(\s*<pre[^>]*>.*?<\/pre>\s*)<\/p>/gs, '$1');
327
+ html = html.replace(/<p[^>]*>(\s*<table[^>]*>.*?<\/table>\s*)<\/p>/gs, '$1');
328
+ return html;
329
+ }
330
+
331
+ function addBaseStyles(html: string, fontSize: number, lineHeight: number): string {
332
+ const style = `
333
+ <style>
334
+ body {
335
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
336
+ line-height: ${lineHeight};
337
+ color: #333;
338
+ background: #fff;
339
+ font-size: ${fontSize}px;
340
+ margin: 0;
341
+ padding: 20px;
342
+ }
343
+ img { max-width: 100%; height: auto; display: block; margin: 16px auto; border-radius: 8px; }
344
+ hr { border: none; height: 1px; background: linear-gradient(to right, transparent, #ddd, transparent); margin: 24px 0; }
345
+ </style>
346
+ `;
347
+ return style + html;
348
+ }