sophhub 0.4.19 → 0.4.21
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.
- package/README.md +199 -187
- package/agents/ai-cs-admin/.config.json +51 -51
- package/agents/ai-cs-admin/AGENTS.md +293 -293
- package/agents/ai-cs-admin/HEARTBEAT.md +18 -18
- package/agents/ai-cs-qa/.config.json +47 -47
- package/agents/ai-cs-qa/BOOTSTRAP.md +22 -22
- package/agents/ai-cs-qa/scripts/setup_links.sh +39 -39
- package/agents/beauty/.config.json +17 -17
- package/agents/beauty/AGENTS.md +234 -234
- package/agents/beauty/BOOTSTRAP.md +55 -55
- package/agents/beauty/HEARTBEAT.md +5 -5
- package/agents/beauty/IDENTITY.md +5 -5
- package/agents/beauty/MEMORY.md +44 -44
- package/agents/beauty/SOUL.md +64 -64
- package/agents/beauty/TOOLS.md +160 -160
- package/agents/beauty/USER.md +114 -114
- package/agents/intern-admin/.config.json +60 -60
- package/agents/intern-admin/AGENTS.md +267 -267
- package/agents/intern-admin/BOOTSTRAP.md +21 -21
- package/agents/intern-admin/HEARTBEAT.md +3 -3
- package/agents/intern-admin/IDENTITY.md +6 -6
- package/agents/intern-admin/MEMORY.md +21 -21
- package/agents/intern-admin/SOUL.md +23 -23
- package/agents/intern-admin/TOOLS.md +93 -93
- package/agents/intern-admin/USER.md +16 -16
- package/agents/intern-admin/scripts/init_workspace.sh +27 -27
- package/agents/intern-qa/.config.json +46 -46
- package/agents/intern-qa/AGENTS.md +303 -303
- package/agents/intern-qa/BOOTSTRAP.md +16 -16
- package/agents/intern-qa/HEARTBEAT.md +3 -3
- package/agents/intern-qa/IDENTITY.md +6 -6
- package/agents/intern-qa/MEMORY.md +22 -22
- package/agents/intern-qa/SOUL.md +24 -24
- package/agents/intern-qa/TOOLS.md +24 -24
- package/agents/intern-qa/USER.md +27 -27
- package/agents/intern-qa/scripts/setup_links.sh +54 -54
- package/agents/parent-toddler/.config.json +37 -37
- package/agents/parent-toddler/AGENTS.md +51 -51
- package/agents/parent-toddler/BOOTSTRAP.md +55 -55
- package/agents/parent-toddler/HEARTBEAT.md +5 -5
- package/agents/parent-toddler/IDENTITY.md +5 -5
- package/agents/parent-toddler/MEMORY.md +22 -22
- package/agents/parent-toddler/SOUL.md +35 -35
- package/agents/parent-toddler/TOOLS.md +31 -31
- package/agents/parent-toddler/USER.md +44 -44
- package/agents/vip-admin/.config.json +51 -51
- package/agents/vip-admin/AGENTS.md +314 -314
- package/agents/vip-admin/BOOTSTRAP.md +21 -21
- package/agents/vip-admin/HEARTBEAT.md +19 -19
- package/agents/vip-admin/IDENTITY.md +6 -6
- package/agents/vip-admin/MEMORY.md +30 -30
- package/agents/vip-admin/SOUL.md +25 -25
- package/agents/vip-admin/TOOLS.md +108 -108
- package/agents/vip-admin/USER.md +31 -31
- package/agents/vip-qa/.config.json +58 -58
- package/agents/vip-qa/AGENTS.md +319 -319
- package/agents/vip-qa/BOOTSTRAP.md +73 -73
- package/agents/vip-qa/HEARTBEAT.md +23 -23
- package/agents/vip-qa/IDENTITY.md +7 -7
- package/agents/vip-qa/MEMORY.md +23 -23
- package/agents/vip-qa/SOUL.md +34 -34
- package/agents/vip-qa/TOOLS.md +41 -41
- package/agents/vip-qa/USER.md +16 -16
- package/agents/vip-qa/scripts/setup_links.sh +39 -39
- package/bin/sophhub.js +25 -25
- package/package.json +35 -33
- package/skills/agent-install/skill.json +34 -34
- package/skills/agent-install/src/SKILL.md +240 -240
- package/skills/agent-install/src/pyproject.toml +6 -6
- package/skills/agent-install/src/scripts/backup_agent.py +120 -120
- package/skills/agent-install/src/scripts/check_installed.py +479 -479
- package/skills/agent-install/src/scripts/common.py +568 -568
- package/skills/agent-install/src/scripts/copy_agent_files.py +59 -59
- package/skills/agent-install/src/scripts/list_agents.py +285 -285
- package/skills/agent-install/src/scripts/resolve_install_params.py +90 -90
- package/skills/agent-install/src/scripts/update_agent_md.py +76 -76
- package/skills/agent-install/src/scripts/update_openclaw.py +193 -193
- package/skills/agent-install/src/scripts/verify_download.py +148 -148
- package/skills/aippt/skill.json +20 -20
- package/skills/aippt/src/SKILL.md +235 -235
- package/skills/aippt/src/pyproject.toml +8 -8
- package/skills/aippt/src/scripts/auth.py +122 -122
- package/skills/aippt/src/scripts/ppt.py +361 -361
- package/skills/aippt/src/scripts/provider_docmee.py +299 -299
- package/skills/beauty-salon-inventory/skill.json +16 -16
- package/skills/beauty-salon-inventory/src/SKILL.md +69 -69
- package/skills/beauty-salon-inventory/src/scripts/init_salon_inventory.py +39 -39
- package/skills/beauty-salon-inventory/src/scripts/init_salon_inventory.sh +4 -4
- package/skills/beauty-salon-inventory/src/scripts/salon_inventory_cli.py +244 -244
- package/skills/beauty-salon-marketing/skill.json +10 -10
- package/skills/beauty-salon-marketing/src/SKILL.md +36 -36
- package/skills/beauty-salon-marketing/src/playbooks/beauty-salon-festival.md +19 -19
- package/skills/beauty-salon-marketing/src/playbooks/beauty-salon-segment.md +18 -18
- package/skills/beauty-salon-marketing/src/scripts/beauty_marketing_cli.py +99 -99
- package/skills/beauty-salon-marketing/src/scripts/member_segment.py +114 -114
- package/skills/beauty-salon-member-appointment/skill.json +10 -10
- package/skills/beauty-salon-member-appointment/src/SKILL.md +36 -36
- package/skills/beauty-salon-member-appointment/src/pyproject.toml +9 -9
- package/skills/beauty-salon-member-appointment/src/scripts/run_e2e_smoke.py +160 -160
- package/skills/beauty-salon-member-appointment/src/src/member_appt_cli/__init__.py +1 -1
- package/skills/beauty-salon-member-appointment/src/src/member_appt_cli/__main__.py +4 -4
- package/skills/beauty-salon-member-appointment/src/src/member_appt_cli/cli.py +921 -921
- package/skills/beauty-salon-member-appointment/src/src/member_appt_cli/db.py +30 -30
- package/skills/beauty-salon-membership/skill.json +20 -20
- package/skills/beauty-salon-membership/src/SKILL.md +67 -67
- package/skills/beauty-salon-product-service/skill.json +12 -12
- package/skills/beauty-salon-product-service/src/SKILL.md +42 -42
- package/skills/beauty-salon-product-service/src/pyproject.toml +9 -9
- package/skills/beauty-salon-product-service/src/src/product_service_cli/__init__.py +1 -1
- package/skills/beauty-salon-product-service/src/src/product_service_cli/__main__.py +4 -4
- package/skills/beauty-salon-product-service/src/src/product_service_cli/cli.py +329 -329
- package/skills/beauty-salon-product-service/src/src/product_service_cli/db.py +29 -29
- package/skills/beauty-salon-staff/skill.json +10 -10
- package/skills/beauty-salon-staff/src/SKILL.md +37 -37
- package/skills/beauty-salon-staff/src/pyproject.toml +9 -9
- package/skills/beauty-salon-staff/src/src/staff_cli/__init__.py +1 -1
- package/skills/beauty-salon-staff/src/src/staff_cli/__main__.py +4 -4
- package/skills/beauty-salon-staff/src/src/staff_cli/cli.py +479 -479
- package/skills/beauty-salon-staff/src/src/staff_cli/db.py +28 -28
- package/skills/beauty-salon-suite/skill.json +13 -13
- package/skills/beauty-salon-suite/src/SKILL.md +18 -18
- package/skills/beauty-salon-suite/src/beauty_db/__init__.py +2 -2
- package/skills/beauty-salon-suite/src/beauty_db/db.py +249 -249
- package/skills/beauty-salon-traffic/skill.json +20 -20
- package/skills/beauty-salon-traffic/src/SKILL.md +84 -84
- package/skills/bing-image-search/skill.json +20 -20
- package/skills/bing-image-search/src/SKILL.md +105 -105
- package/skills/bot-api-status/skill.json +44 -44
- package/skills/bot-api-status/src/SKILL.md +99 -99
- package/skills/bot-api-status/src/pyproject.toml +5 -5
- package/skills/bot-api-status/src/scripts/secret.py +496 -496
- package/skills/bot-secret/skill.json +35 -35
- package/skills/bot-secret/src/SKILL.md +51 -51
- package/skills/bot-secret/src/pyproject.toml +5 -5
- package/skills/bot-secret/src/scripts/secret.py +120 -120
- package/skills/cake-flower-holiday-campaign/skill.json +20 -20
- package/skills/cake-flower-holiday-campaign/src/SKILL.md +68 -68
- package/skills/cake-flower-order-sop/skill.json +20 -20
- package/skills/cake-flower-order-sop/src/SKILL.md +65 -65
- package/skills/claw-agent-get-send/skill.json +32 -32
- package/skills/claw-agent-get-send/src/SKILL.md +43 -43
- package/skills/claw-agent-get-send/src/pyproject.toml +5 -5
- package/skills/claw-agent-get-send/src/scripts/appia_claw.py +379 -379
- package/skills/compact-context/skill.json +20 -20
- package/skills/compact-context/src/SKILL.md +133 -133
- package/skills/compact-context/src/scripts/check.sh +381 -381
- package/skills/compact-context/src/scripts/set-keep-recent.mjs +1337 -1337
- package/skills/compact-context/src/scripts/setup.sh +96 -96
- package/skills/consensus/skill.json +20 -20
- package/skills/consensus/src/SKILL.md +93 -93
- package/skills/deepwiki/skill.json +20 -20
- package/skills/deepwiki/src/SKILL.md +45 -45
- package/skills/deepwiki/src/_meta.json +5 -5
- package/skills/deepwiki/src/scripts/deepwiki.js +135 -135
- package/skills/didi-ride/skill.json +20 -20
- package/skills/didi-ride/src/SKILL.md +309 -309
- package/skills/didi-ride/src/_meta.json +5 -5
- package/skills/didi-ride/src/assets/PREFERENCE.md +58 -58
- package/skills/didi-ride/src/package.json +15 -15
- package/skills/didi-ride/src/references/api_references.md +171 -171
- package/skills/didi-ride/src/references/error_handling.md +68 -68
- package/skills/didi-ride/src/references/setup.md +73 -73
- package/skills/didi-ride/src/references/workflow.md +150 -150
- package/skills/feishu-bitable/skill.json +20 -20
- package/skills/feishu-bitable/src/CHECKLIST.md +149 -149
- package/skills/feishu-bitable/src/README.md +177 -177
- package/skills/feishu-bitable/src/SKILL.md +113 -113
- package/skills/feishu-bitable/src/_meta.json +5 -5
- package/skills/feishu-bitable/src/api.js +380 -380
- package/skills/feishu-bitable/src/bin/cli.js +283 -283
- package/skills/feishu-bitable/src/description.md +142 -142
- package/skills/feishu-bitable/src/examples/create-records.json +51 -51
- package/skills/feishu-bitable/src/examples/create-table.json +63 -63
- package/skills/feishu-bitable/src/package-lock.json +324 -324
- package/skills/feishu-bitable/src/package.json +32 -32
- package/skills/feishu-bitable/src/publish-config.json +13 -13
- package/skills/feishu-bitable/src/test-simple.js +60 -60
- package/skills/feishu-bitable/src/utils.js +260 -260
- package/skills/feishu-notes-assistant-universal/skill.json +20 -20
- package/skills/feishu-notes-assistant-universal/src/README.md +55 -55
- package/skills/feishu-notes-assistant-universal/src/SKILL.md +159 -159
- package/skills/feishu-notes-assistant-universal/src/scripts/_resolve_lark_cli.py +58 -58
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_meeting_minutes.py +462 -462
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_notes_crud.py +547 -547
- package/skills/feishu-notes-assistant-universal/src/scripts/openclaw_notes_crud_test.py +181 -181
- package/skills/feishu-notes-assistant-universal/src/scripts/run_meeting_minutes.py +80 -80
- package/skills/feishu-notes-assistant-universal/src/scripts/run_meeting_minutes.sh +5 -5
- package/skills/feishu-notes-assistant-universal/src/scripts/run_note_crud.py +32 -32
- package/skills/feishu-notes-assistant-universal/src/scripts/run_note_crud.sh +5 -5
- package/skills/flight-booking/skill.json +36 -36
- package/skills/flight-booking/src/SKILL.md +288 -288
- package/skills/flight-booking/src/scripts/flight_booking.py +1237 -1237
- package/skills/flyai/skill.json +20 -20
- package/skills/flyai/src/SKILL.md +119 -119
- package/skills/flyai/src/references/fliggy-fast-search.md +53 -53
- package/skills/flyai/src/references/search-flight.md +89 -89
- package/skills/flyai/src/references/search-hotels.md +57 -57
- package/skills/flyai/src/references/search-poi.md +48 -48
- package/skills/google-maps/skill.json +20 -20
- package/skills/google-maps/src/SKILL.md +237 -237
- package/skills/google-maps/src/_meta.json +5 -5
- package/skills/google-maps/src/lib/map_helper.py +912 -912
- package/skills/image-classify/skill.json +42 -42
- package/skills/image-classify/src/SKILL.md +368 -368
- package/skills/image-classify/src/references/config.json +4 -4
- package/skills/image-classify/src/scripts/face_search.py +1276 -1276
- package/skills/image-description/skill.json +34 -34
- package/skills/image-description/src/SKILL.md +33 -33
- package/skills/image-description/src/pyproject.toml +8 -8
- package/skills/image-description/src/scripts/ana_image.py +112 -112
- package/skills/image-identify-world/skill.json +20 -20
- package/skills/image-identify-world/src/SKILL.md +40 -40
- package/skills/image-identify-world/src/pyproject.toml +8 -8
- package/skills/image-identify-world/src/scripts/identify_world.py +115 -115
- package/skills/insurance-policy-review/skill.json +27 -27
- package/skills/insurance-policy-review/src/SKILL.md +75 -75
- package/skills/insurance-sales-playbook/skill.json +20 -20
- package/skills/insurance-sales-playbook/src/SKILL.md +58 -58
- package/skills/inventory-management/skill.json +20 -20
- package/skills/inventory-management/src/SKILL.md +241 -241
- package/skills/inventory-management/src/scripts/inventory.py +1844 -1844
- package/skills/large-task-router/skill.json +20 -20
- package/skills/large-task-router/src/SKILL.md +79 -79
- package/skills/large-task-router/src/templates/plan.md +74 -74
- package/skills/lawding-contract-review/skill.json +20 -20
- package/skills/lawding-contract-review/src/SKILL.md +284 -284
- package/skills/lawding-contract-review/src/references/legal-language-library.md +1385 -1385
- package/skills/lawding-contract-review/src/scripts/build_reminders.py +471 -471
- package/skills/lawding-contract-review/src/scripts/register_contract_cron.py +457 -457
- package/skills/md2pdf-converter/skill.json +20 -20
- package/skills/md2pdf-converter/src/SKILL.md +244 -244
- package/skills/md2pdf-converter/src/_meta.json +5 -5
- package/skills/md2pdf-converter/src/scripts/generate_emoji_mapping.py +74 -74
- package/skills/md2pdf-converter/src/scripts/md2pdf-local.sh +291 -291
- package/skills/notes-hub-assistant/skill.json +20 -20
- package/skills/notes-hub-assistant/src/SKILL.md +233 -233
- package/skills/notes-hub-assistant/src/scripts/_resolve_lark_cli.py +48 -48
- package/skills/notes-hub-assistant/src/scripts/openclaw_meeting_minutes.py +473 -473
- package/skills/notes-hub-assistant/src/scripts/openclaw_notes_crud.py +596 -596
- package/skills/notes-hub-assistant/src/scripts/openclaw_wolai_notes_crud.py +364 -364
- package/skills/notes-hub-assistant/src/scripts/run_meeting_minutes.py +79 -79
- package/skills/notes-hub-assistant/src/scripts/run_note_crud.py +37 -37
- package/skills/notes-hub-assistant/src/scripts/run_notionbot.py +36 -36
- package/skills/notes-hub-assistant/src/scripts/run_wolai_note_crud.py +27 -27
- package/skills/schedule-reminder/skill.json +20 -20
- package/skills/schedule-reminder/src/SKILL.md +619 -619
- package/skills/schedule-reminder/src/schedule_template.md +68 -68
- package/skills/schedule-reminder/src/scripts/append_event.py +204 -204
- package/skills/schedule-reminder/src/scripts/create_reminders.sh +163 -163
- package/skills/schedule-reminder/src/scripts/daily_activate.sh +175 -175
- package/skills/schedule-reminder/src/scripts/parse_schedule.py +704 -704
- package/skills/schedule-reminder/src/scripts/setup.sh +242 -242
- package/skills/schedule-reminder/src//347/224/250/346/210/267/346/214/207/345/215/227.md +311 -311
- package/skills/sessions-analysis/skill.json +34 -34
- package/skills/sessions-analysis/src/SKILL.md +81 -81
- package/skills/sessions-analysis/src/pyproject.toml +5 -5
- package/skills/sessions-analysis/src/scripts/ana_logs.py +205 -205
- package/skills/share-skill/skill.json +20 -20
- package/skills/share-skill/src/SKILL.md +261 -261
- package/skills/share-skill/src/scripts/share_skill_to_friend.py +1031 -1031
- package/skills/skill-creator/skill.json +20 -20
- package/skills/skill-creator/src/SKILL.md +370 -370
- package/skills/skill-creator/src/license.txt +202 -202
- package/skills/skill-creator/src/scripts/init_skill.py +378 -378
- package/skills/skill-creator/src/scripts/package_skill.py +111 -111
- package/skills/skill-creator/src/scripts/quick_validate.py +101 -101
- package/skills/skillhub/skill.json +27 -27
- package/skills/skillhub/src/SKILL.md +121 -121
- package/skills/sophnet-age-appearance/skill.json +20 -20
- package/skills/sophnet-age-appearance/src/SKILL.md +83 -83
- package/skills/sophnet-age-appearance/src/pyproject.toml +10 -10
- package/skills/sophnet-age-appearance/src/scripts/age_appearance.py +395 -395
- package/skills/sophnet-age-appearance/src/scripts/age_face_crop.py +313 -313
- package/skills/sophnet-bot-client/skill.json +20 -20
- package/skills/sophnet-bot-client/src/SKILL.md +255 -255
- package/skills/sophnet-bot-client/src/pyproject.toml +13 -13
- package/skills/sophnet-bot-client/src/scripts/bot_client_proxy.py +165 -165
- package/skills/sophnet-bot-client/src/scripts/bot_client_safe.sh +29 -29
- package/skills/sophnet-bot-client/src/scripts/bot_client_setup.py +502 -502
- package/skills/sophnet-bot-client/src/tests/test_bot_client_proxy.py +255 -255
- package/skills/sophnet-bot-client/src/tests/test_bot_client_setup.py +679 -679
- package/skills/sophnet-bot-client/src/uv.lock +8 -8
- package/skills/sophnet-customer-management/skill.json +20 -20
- package/skills/sophnet-customer-management/src/SKILL.md +270 -270
- package/skills/sophnet-customer-management/src/pyproject.toml +15 -15
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/__init__.py +2 -2
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/__main__.py +5 -5
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/cli.py +67 -67
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/__init__.py +2 -2
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/customer.py +60 -60
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/export_file.py +18 -18
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/import_file.py +15 -15
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/reminder.py +26 -26
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/commands/schema.py +28 -28
- package/skills/sophnet-customer-management/src/src/customer_mgmt_cli/config.py +54 -54
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/__init__.py +2 -2
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/exporter.py +85 -85
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/models.py +84 -84
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/normalizer.py +144 -144
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/parser.py +241 -241
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/query.py +109 -109
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/reminder.py +121 -121
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/repository.py +397 -397
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/schema.py +106 -106
- package/skills/sophnet-customer-management/src/src/customer_mgmt_core/service.py +565 -565
- package/skills/sophnet-customer-management/src/uv.lock +48 -48
- package/skills/sophnet-customized-marketing/skill.json +28 -28
- package/skills/sophnet-customized-marketing/src/SKILL.md +144 -144
- package/skills/sophnet-customized-marketing/src/playbooks/campaign-planning.md +187 -187
- package/skills/sophnet-customized-marketing/src/playbooks/content-generation.md +124 -124
- package/skills/sophnet-customized-marketing/src/playbooks/marketing-calendar.md +59 -59
- package/skills/sophnet-customized-marketing/src/playbooks/multi-channel-bundle.md +94 -94
- package/skills/sophnet-customized-marketing/src/playbooks/poster-generation.md +182 -182
- package/skills/sophnet-customized-marketing/src/playbooks/style-profile-workflow.md +103 -103
- package/skills/sophnet-customized-marketing/src/pyproject.toml +8 -8
- package/skills/sophnet-customized-marketing/src/references/campaign-mechanics.md +168 -168
- package/skills/sophnet-customized-marketing/src/references/content-safety.md +26 -26
- package/skills/sophnet-customized-marketing/src/references/marketing-date-checklist.md +99 -99
- package/skills/sophnet-customized-marketing/src/references/platform-writing-guidelines.md +88 -88
- package/skills/sophnet-customized-marketing/src/references/quality-checklist.md +44 -44
- package/skills/sophnet-customized-marketing/src/scripts/generate_poster.py +572 -572
- package/skills/sophnet-customized-marketing/src/scripts/style_profile.py +215 -215
- package/skills/sophnet-dailynews/skill.json +20 -20
- package/skills/sophnet-dailynews/src/SKILL.md +179 -179
- package/skills/sophnet-dailynews/src/cache.json +150 -150
- package/skills/sophnet-dailynews/src/sources.json +230 -230
- package/skills/sophnet-docx/skill.json +20 -20
- package/skills/sophnet-docx/src/SKILL.md +463 -463
- package/skills/sophnet-docx/src/package-lock.json +208 -208
- package/skills/sophnet-docx/src/package.json +16 -16
- package/skills/sophnet-docx/src/pyproject.toml +11 -11
- package/skills/sophnet-docx/src/scripts/__init__.py +1 -1
- package/skills/sophnet-docx/src/scripts/accept_changes.py +135 -135
- package/skills/sophnet-docx/src/scripts/comment.py +318 -318
- package/skills/sophnet-docx/src/scripts/ensure_uv_env.sh +68 -68
- package/skills/sophnet-docx/src/scripts/office/helpers/merge_runs.py +199 -199
- package/skills/sophnet-docx/src/scripts/office/helpers/simplify_redlines.py +197 -197
- package/skills/sophnet-docx/src/scripts/office/pack.py +159 -159
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -1499
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -146
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -1085
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -11
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -3081
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -23
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -185
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -287
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -1676
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -28
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -144
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -174
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -25
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -18
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -59
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -56
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -195
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -582
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -25
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -4439
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -570
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -509
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -12
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -108
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -96
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -3646
- package/skills/sophnet-docx/src/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -116
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -42
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -50
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -49
- package/skills/sophnet-docx/src/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -33
- package/skills/sophnet-docx/src/scripts/office/schemas/mce/mc.xsd +75 -75
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2010.xsd +560 -560
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2012.xsd +67 -67
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-2018.xsd +14 -14
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -20
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -13
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -4
- package/skills/sophnet-docx/src/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -8
- package/skills/sophnet-docx/src/scripts/office/soffice.py +183 -183
- package/skills/sophnet-docx/src/scripts/office/unpack.py +132 -132
- package/skills/sophnet-docx/src/scripts/office/validate.py +111 -111
- package/skills/sophnet-docx/src/scripts/office/validators/__init__.py +15 -15
- package/skills/sophnet-docx/src/scripts/office/validators/base.py +847 -847
- package/skills/sophnet-docx/src/scripts/office/validators/docx.py +446 -446
- package/skills/sophnet-docx/src/scripts/office/validators/pptx.py +275 -275
- package/skills/sophnet-docx/src/scripts/office/validators/redlining.py +247 -247
- package/skills/sophnet-docx/src/scripts/templates/comments.xml +3 -3
- package/skills/sophnet-docx/src/scripts/templates/commentsExtended.xml +3 -3
- package/skills/sophnet-docx/src/scripts/templates/commentsExtensible.xml +3 -3
- package/skills/sophnet-docx/src/scripts/templates/commentsIds.xml +3 -3
- package/skills/sophnet-docx/src/scripts/templates/people.xml +3 -3
- package/skills/sophnet-docx/src/scripts/upload_file.sh +96 -96
- package/skills/sophnet-docx/src/uv.lock +320 -320
- package/skills/sophnet-face-search/skill.json +20 -20
- package/skills/sophnet-face-search/src/SKILL.md +115 -115
- package/skills/sophnet-face-search/src/pyproject.toml +11 -11
- package/skills/sophnet-face-search/src/scripts/face_search.py +335 -335
- package/skills/sophnet-face-search/src/uv.lock +508 -508
- package/skills/sophnet-id-photo/skill.json +20 -20
- package/skills/sophnet-id-photo/src/SKILL.md +107 -107
- package/skills/sophnet-id-photo/src/pyproject.toml +10 -10
- package/skills/sophnet-id-photo/src/scripts/id_photo.py +540 -540
- package/skills/sophnet-id-photo/src/scripts/id_photo_compliance.py +215 -215
- package/skills/sophnet-id-photo/src/scripts/id_photo_face_crop.py +313 -313
- package/skills/sophnet-image-edit/skill.json +20 -20
- package/skills/sophnet-image-edit/src/SKILL.md +140 -140
- package/skills/sophnet-image-edit/src/pyproject.toml +9 -9
- package/skills/sophnet-image-edit/src/scripts/edit_and_preview.sh +68 -68
- package/skills/sophnet-image-edit/src/scripts/edit_image.py +279 -279
- package/skills/sophnet-image-edit/src/uv.lock +234 -234
- package/skills/sophnet-image-generate/skill.json +20 -20
- package/skills/sophnet-image-generate/src/SKILL.md +62 -62
- package/skills/sophnet-image-generate/src/pyproject.toml +9 -9
- package/skills/sophnet-image-generate/src/scripts/generate_image.py +156 -156
- package/skills/sophnet-image-generate/src/uv.lock +234 -234
- package/skills/sophnet-image-ocr/skill.json +20 -20
- package/skills/sophnet-image-ocr/src/SKILL.md +167 -167
- package/skills/sophnet-image-ocr/src/pyproject.toml +13 -13
- package/skills/sophnet-image-ocr/src/scripts/ocr.py +225 -225
- package/skills/sophnet-image-ocr/src/uv.lock +234 -234
- package/skills/sophnet-infinite-talk/skill.json +20 -20
- package/skills/sophnet-infinite-talk/src/SKILL.md +140 -140
- package/skills/sophnet-infinite-talk/src/pyproject.toml +9 -9
- package/skills/sophnet-infinite-talk/src/scripts/gen.py +172 -172
- package/skills/sophnet-oss/skill.json +27 -27
- package/skills/sophnet-oss/src/SKILL.md +118 -118
- package/skills/sophnet-oss/src/pyproject.toml +8 -8
- package/skills/sophnet-oss/src/scripts/upload_file.py +43 -43
- package/skills/sophnet-pdf/skill.json +20 -20
- package/skills/sophnet-pdf/src/SKILL.md +413 -413
- package/skills/sophnet-pdf/src/forms.md +297 -297
- package/skills/sophnet-pdf/src/pyproject.toml +14 -14
- package/skills/sophnet-pdf/src/reference.md +611 -611
- package/skills/sophnet-pdf/src/scripts/check_bounding_boxes.py +65 -65
- package/skills/sophnet-pdf/src/scripts/check_fillable_fields.py +11 -11
- package/skills/sophnet-pdf/src/scripts/convert_pdf_to_images.py +33 -33
- package/skills/sophnet-pdf/src/scripts/create_validation_image.py +37 -37
- package/skills/sophnet-pdf/src/scripts/enhance_tutorial.py +557 -557
- package/skills/sophnet-pdf/src/scripts/ensure_uv_env.sh +68 -68
- package/skills/sophnet-pdf/src/scripts/extract_form_field_info.py +122 -122
- package/skills/sophnet-pdf/src/scripts/extract_form_structure.py +115 -115
- package/skills/sophnet-pdf/src/scripts/extract_pdf_content.py +34 -34
- package/skills/sophnet-pdf/src/scripts/fill_fillable_fields.py +98 -98
- package/skills/sophnet-pdf/src/scripts/fill_pdf_form_with_annotations.py +107 -107
- package/skills/sophnet-pdf/src/scripts/upload_file.sh +88 -88
- package/skills/sophnet-pdf/src/uv.lock +537 -537
- package/skills/sophnet-qa-install/skill.json +27 -27
- package/skills/sophnet-qa-install/src/SKILL.md +210 -210
- package/skills/sophnet-qa-install/src/pyproject.toml +6 -6
- package/skills/sophnet-qa-install/src/scripts/backup_md.py +35 -35
- package/skills/sophnet-qa-install/src/scripts/check_installed.py +143 -143
- package/skills/sophnet-qa-install/src/scripts/update_config.py +142 -142
- package/skills/sophnet-qa-install/src/scripts/update_md.py +73 -73
- package/skills/sophnet-schedule/skill.json +20 -20
- package/skills/sophnet-schedule/src/ARCHITECTURE.md +321 -321
- package/skills/sophnet-schedule/src/IMPROVEMENTS.md +145 -145
- package/skills/sophnet-schedule/src/SKILL.md +1050 -1050
- package/skills/sophnet-schedule/src/_meta.json +6 -6
- package/skills/sophnet-schedule/src/api/models.py +245 -245
- package/skills/sophnet-schedule/src/apps/add_event.py +237 -237
- package/skills/sophnet-schedule/src/apps/check_reminders.py +112 -112
- package/skills/sophnet-schedule/src/apps/check_roc.py +246 -246
- package/skills/sophnet-schedule/src/apps/generate_daily_plan.py +342 -342
- package/skills/sophnet-schedule/src/apps/import_events.py +216 -216
- package/skills/sophnet-schedule/src/apps/monitor_calendar_changes.py +140 -140
- package/skills/sophnet-schedule/src/apps/register_tasks.py +169 -169
- package/skills/sophnet-schedule/src/apps/sync_roc_to_gcal.py +174 -174
- package/skills/sophnet-schedule/src/compat.py +66 -66
- package/skills/sophnet-schedule/src/config/reminder_rules.yaml +96 -96
- package/skills/sophnet-schedule/src/config/roc_events.yaml +44 -44
- package/skills/sophnet-schedule/src/config/settings.py +133 -133
- package/skills/sophnet-schedule/src/config/task_registry.yaml +92 -92
- package/skills/sophnet-schedule/src/docs/FRONTEND_INTEGRATION_GUIDE.md +437 -437
- package/skills/sophnet-schedule/src/gcal/client.py +374 -374
- package/skills/sophnet-schedule/src/gcal/models.py +91 -91
- package/skills/sophnet-schedule/src/requirements.txt +6 -6
- package/skills/sophnet-schedule/src/scripts/setup_gcal_token.py +85 -85
- package/skills/sophnet-schedule/src/server.py +669 -669
- package/skills/sophnet-schedule/src/services/calendar_backend.py +139 -139
- package/skills/sophnet-schedule/src/services/conflict_detector.py +96 -96
- package/skills/sophnet-schedule/src/services/datetime_utils.py +117 -117
- package/skills/sophnet-schedule/src/services/event_classifier.py +100 -100
- package/skills/sophnet-schedule/src/services/event_diff.py +160 -160
- package/skills/sophnet-schedule/src/services/google_integration.py +500 -500
- package/skills/sophnet-schedule/src/services/job_store.py +100 -100
- package/skills/sophnet-schedule/src/services/local_event_store.py +266 -266
- package/skills/sophnet-schedule/src/services/reminder_planner.py +116 -116
- package/skills/sophnet-schedule/src/services/runtime_utils.py +31 -31
- package/skills/sophnet-schedule/src/services/table_parser.py +286 -286
- package/skills/sophnet-schedule/src/services/task_builder.py +167 -167
- package/skills/sophnet-schedule/src/services/time_window.py +72 -72
- package/skills/sophnet-sticker-edit/skill.json +27 -27
- package/skills/sophnet-sticker-edit/src/SKILL.md +80 -80
- package/skills/sophnet-sticker-edit/src/pyproject.toml +9 -9
- package/skills/sophnet-sticker-edit/src/scripts/edit_sticker_image.py +403 -403
- package/skills/sophnet-stock/skill.json +20 -20
- package/skills/sophnet-stock/src/App-Plan.md +442 -442
- package/skills/sophnet-stock/src/README.md +214 -214
- package/skills/sophnet-stock/src/SKILL.md +236 -236
- package/skills/sophnet-stock/src/TODO.md +394 -394
- package/skills/sophnet-stock/src/_meta.json +5 -5
- package/skills/sophnet-stock/src/docs/ARCHITECTURE.md +408 -408
- package/skills/sophnet-stock/src/docs/CONCEPT.md +233 -233
- package/skills/sophnet-stock/src/docs/HOT_SCANNER.md +288 -288
- package/skills/sophnet-stock/src/docs/README.md +95 -95
- package/skills/sophnet-stock/src/docs/USAGE.md +465 -465
- package/skills/sophnet-stock/src/scripts/analyze_stock.py +2565 -2565
- package/skills/sophnet-stock/src/scripts/dividends.py +365 -365
- package/skills/sophnet-stock/src/scripts/hot_scanner.py +582 -582
- package/skills/sophnet-stock/src/scripts/portfolio.py +548 -548
- package/skills/sophnet-stock/src/scripts/rumor_scanner.py +342 -342
- package/skills/sophnet-stock/src/scripts/test_stock_analysis.py +409 -409
- package/skills/sophnet-stock/src/scripts/watchlist.py +336 -336
- package/skills/sophnet-training-install/skill.json +27 -27
- package/skills/sophnet-training-install/src/SKILL.md +211 -211
- package/skills/sophnet-training-install/src/pyproject.toml +6 -6
- package/skills/sophnet-training-install/src/scripts/backup_md.py +35 -35
- package/skills/sophnet-training-install/src/scripts/check_installed.py +144 -144
- package/skills/sophnet-training-install/src/scripts/update_config.py +142 -142
- package/skills/sophnet-training-install/src/scripts/update_md.py +73 -73
- package/skills/sophnet-tts/skill.json +20 -20
- package/skills/sophnet-tts/src/SKILL.md +79 -79
- package/skills/sophnet-tts/src/pyproject.toml +9 -9
- package/skills/sophnet-tts/src/scripts/gen_tts.py +130 -130
- package/skills/sophnet-video-generate/skill.json +37 -37
- package/skills/sophnet-video-generate/src/SKILL.md +117 -117
- package/skills/sophnet-video-generate/src/scripts/gen_video.py +321 -321
- package/skills/sophnet-xlsx/skill.json +20 -20
- package/skills/sophnet-xlsx/src/SKILL.md +399 -399
- package/skills/sophnet-xlsx/src/pyproject.toml +11 -11
- package/skills/sophnet-xlsx/src/scripts/ensure_uv_env.sh +68 -68
- package/skills/sophnet-xlsx/src/scripts/office/helpers/merge_runs.py +199 -199
- package/skills/sophnet-xlsx/src/scripts/office/helpers/simplify_redlines.py +197 -197
- package/skills/sophnet-xlsx/src/scripts/office/pack.py +159 -159
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -1499
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -146
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -1085
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -11
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -3081
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -23
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -185
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -287
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -1676
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -28
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -144
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -174
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -25
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -18
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -59
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -56
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -195
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -582
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -25
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -4439
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -570
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -509
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -12
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -108
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -96
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -3646
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -116
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -42
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -50
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -49
- package/skills/sophnet-xlsx/src/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -33
- package/skills/sophnet-xlsx/src/scripts/office/schemas/mce/mc.xsd +75 -75
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2010.xsd +560 -560
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2012.xsd +67 -67
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-2018.xsd +14 -14
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -20
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -13
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -4
- package/skills/sophnet-xlsx/src/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -8
- package/skills/sophnet-xlsx/src/scripts/office/soffice.py +183 -183
- package/skills/sophnet-xlsx/src/scripts/office/unpack.py +132 -132
- package/skills/sophnet-xlsx/src/scripts/office/validate.py +111 -111
- package/skills/sophnet-xlsx/src/scripts/office/validators/__init__.py +15 -15
- package/skills/sophnet-xlsx/src/scripts/office/validators/base.py +847 -847
- package/skills/sophnet-xlsx/src/scripts/office/validators/docx.py +446 -446
- package/skills/sophnet-xlsx/src/scripts/office/validators/pptx.py +275 -275
- package/skills/sophnet-xlsx/src/scripts/office/validators/redlining.py +247 -247
- package/skills/sophnet-xlsx/src/scripts/recalc.py +184 -184
- package/skills/sophnet-xlsx/src/scripts/upload_file.sh +96 -96
- package/skills/sophnet-xlsx/src/uv.lock +319 -319
- package/skills/ui-ux-pro-max/skill.json +20 -20
- package/skills/ui-ux-pro-max/src/SKILL.md +377 -377
- package/skills/ui-ux-pro-max/src/data/icons.csv +101 -101
- package/skills/ui-ux-pro-max/src/data/react-performance.csv +45 -45
- package/skills/ui-ux-pro-max/src/data/stacks/astro.csv +54 -54
- package/skills/ui-ux-pro-max/src/data/stacks/jetpack-compose.csv +53 -53
- package/skills/ui-ux-pro-max/src/data/stacks/nuxt-ui.csv +51 -51
- package/skills/ui-ux-pro-max/src/data/stacks/nuxtjs.csv +59 -59
- package/skills/ui-ux-pro-max/src/data/stacks/shadcn.csv +61 -61
- package/skills/ui-ux-pro-max/src/data/typography.csv +57 -57
- package/skills/ui-ux-pro-max/src/data/ui-reasoning.csv +101 -101
- package/skills/ui-ux-pro-max/src/data/web-interface.csv +31 -31
- package/skills/ui-ux-pro-max/src/scripts/core.py +253 -253
- package/skills/ui-ux-pro-max/src/scripts/design_system.py +1067 -1067
- package/skills/video-understand/skill.json +20 -20
- package/skills/video-understand/src/SKILL.md +79 -79
- package/skills/video-understand/src/scripts/video_understand.py +204 -204
- package/skills/weather/skill.json +19 -19
- package/skills/weather/src/SKILL.md +112 -112
- package/skills/web-scraper/skill.json +20 -20
- package/skills/web-scraper/src/SKILL.md +101 -101
- package/skills/web-scraper/src/scripts/scrape.py +270 -270
- package/skills/website-builder/skill.json +20 -20
- package/skills/website-builder/src/SKILL.md +266 -266
- package/skills/website-builder/src/scripts/deploy_site.sh +46 -46
- package/skills/wechat-article-publisher/skill.json +20 -20
- package/skills/wechat-article-publisher/src/SKILL.md +60 -60
- package/skills/wechat-article-publisher/src/config.json +6 -6
- package/skills/wechat-article-publisher/src/pyproject.toml +12 -12
- package/skills/wechat-article-publisher/src/scripts/publish_wechat.py +825 -825
- package/skills/xiaohongshu/skill.json +20 -20
- package/skills/xiaohongshu/src/SKILL.md +91 -91
- package/skills/xiaohongshu/src/_meta.json +5 -5
- package/skills/xiaohongshu/src/assets/card.html +216 -216
- package/skills/xiaohongshu/src/assets/cover.html +82 -82
- package/skills/xiaohongshu/src/assets/example.md +84 -84
- package/skills/xiaohongshu/src/assets/styles.css +318 -318
- package/skills/xiaohongshu/src/scripts/render_xhs_v2.py +737 -737
- package/skills/xiaohongshu/src/scripts/sign_server.py +158 -158
- package/skills/xiaohongshu/src/scripts/stealth.min.js +6 -6
- package/skills/xiaohongshu/src/scripts/xhs_tool.py +186 -186
- package/skills/xiaohongshu/src/workflow.py +185 -185
- package/src/commands/agent.js +112 -112
- package/src/commands/download.js +101 -101
- package/src/commands/info.js +58 -58
- package/src/commands/list.js +71 -71
- package/src/utils/agents.js +36 -36
- package/src/utils/config.js +22 -22
- package/src/utils/paths.js +31 -31
- package/src/utils/versions.js +57 -57
|
@@ -1,737 +1,737 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
小红书卡片渲染脚本 V2 - 智能分页版
|
|
4
|
-
将 Markdown 文件渲染为小红书风格的图片卡片
|
|
5
|
-
|
|
6
|
-
新特性:
|
|
7
|
-
1. 智能分页:自动检测内容高度,超出时自动拆分到多张卡片
|
|
8
|
-
2. 多种样式:支持多种预设样式主题
|
|
9
|
-
3. 字数预估:基于字数预分配内容,减少渲染次数
|
|
10
|
-
|
|
11
|
-
使用方法:
|
|
12
|
-
python render_xhs_v2.py <markdown_file> [options]
|
|
13
|
-
|
|
14
|
-
依赖安装:
|
|
15
|
-
pip install markdown pyyaml playwright
|
|
16
|
-
playwright install chromium
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
import argparse
|
|
20
|
-
import asyncio
|
|
21
|
-
import os
|
|
22
|
-
import re
|
|
23
|
-
import sys
|
|
24
|
-
import tempfile
|
|
25
|
-
from pathlib import Path
|
|
26
|
-
from typing import List, Dict, Tuple
|
|
27
|
-
|
|
28
|
-
try:
|
|
29
|
-
import markdown
|
|
30
|
-
import yaml
|
|
31
|
-
from playwright.async_api import async_playwright, Page
|
|
32
|
-
except ImportError as e:
|
|
33
|
-
print(f"缺少依赖: {e}")
|
|
34
|
-
print("请运行: pip install markdown pyyaml playwright && playwright install chromium")
|
|
35
|
-
sys.exit(1)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# 获取脚本所在目录
|
|
39
|
-
SCRIPT_DIR = Path(__file__).parent.parent
|
|
40
|
-
ASSETS_DIR = SCRIPT_DIR / "assets"
|
|
41
|
-
|
|
42
|
-
# 卡片尺寸配置 (3:4 比例)
|
|
43
|
-
CARD_WIDTH = 1080
|
|
44
|
-
CARD_HEIGHT = 1440
|
|
45
|
-
|
|
46
|
-
# 内容区域安全高度(考虑 padding 和 margin)
|
|
47
|
-
# card-inner padding: 60px * 2 = 120px
|
|
48
|
-
# card-container padding: 50px * 2 = 100px
|
|
49
|
-
# 页码区域: ~80px
|
|
50
|
-
# 安全边距: ~40px
|
|
51
|
-
SAFE_HEIGHT = CARD_HEIGHT - 120 - 100 - 80 - 40 # ~1100px
|
|
52
|
-
|
|
53
|
-
# 样式配置
|
|
54
|
-
STYLES = {
|
|
55
|
-
"purple": {
|
|
56
|
-
"name": "紫韵",
|
|
57
|
-
"cover_bg": "linear-gradient(180deg, #3450E4 0%, #D266DA 100%)",
|
|
58
|
-
"card_bg": "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
59
|
-
"accent_color": "#6366f1",
|
|
60
|
-
},
|
|
61
|
-
"xiaohongshu": {
|
|
62
|
-
"name": "小红书红",
|
|
63
|
-
"cover_bg": "linear-gradient(180deg, #FF2442 0%, #FF6B81 100%)",
|
|
64
|
-
"card_bg": "linear-gradient(135deg, #FF2442 0%, #FF6B81 100%)",
|
|
65
|
-
"accent_color": "#FF2442",
|
|
66
|
-
},
|
|
67
|
-
"mint": {
|
|
68
|
-
"name": "清新薄荷",
|
|
69
|
-
"cover_bg": "linear-gradient(180deg, #43e97b 0%, #38f9d7 100%)",
|
|
70
|
-
"card_bg": "linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)",
|
|
71
|
-
"accent_color": "#43e97b",
|
|
72
|
-
},
|
|
73
|
-
"sunset": {
|
|
74
|
-
"name": "日落橙",
|
|
75
|
-
"cover_bg": "linear-gradient(180deg, #fa709a 0%, #fee140 100%)",
|
|
76
|
-
"card_bg": "linear-gradient(135deg, #fa709a 0%, #fee140 100%)",
|
|
77
|
-
"accent_color": "#fa709a",
|
|
78
|
-
},
|
|
79
|
-
"ocean": {
|
|
80
|
-
"name": "深海蓝",
|
|
81
|
-
"cover_bg": "linear-gradient(180deg, #4facfe 0%, #00f2fe 100%)",
|
|
82
|
-
"card_bg": "linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",
|
|
83
|
-
"accent_color": "#4facfe",
|
|
84
|
-
},
|
|
85
|
-
"elegant": {
|
|
86
|
-
"name": "优雅白",
|
|
87
|
-
"cover_bg": "linear-gradient(180deg, #f5f5f5 0%, #e0e0e0 100%)",
|
|
88
|
-
"card_bg": "linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%)",
|
|
89
|
-
"accent_color": "#333333",
|
|
90
|
-
"text_light": "#555555",
|
|
91
|
-
},
|
|
92
|
-
"dark": {
|
|
93
|
-
"name": "暗黑模式",
|
|
94
|
-
"cover_bg": "linear-gradient(180deg, #1a1a2e 0%, #16213e 100%)",
|
|
95
|
-
"card_bg": "linear-gradient(135deg, #1a1a2e 0%, #16213e 100%)",
|
|
96
|
-
"accent_color": "#e94560",
|
|
97
|
-
},
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def parse_markdown_file(file_path: str) -> dict:
|
|
102
|
-
"""解析 Markdown 文件,提取 YAML 头部和正文内容"""
|
|
103
|
-
with open(file_path, 'r', encoding='utf-8') as f:
|
|
104
|
-
content = f.read()
|
|
105
|
-
|
|
106
|
-
# 解析 YAML 头部
|
|
107
|
-
yaml_pattern = r'^---\s*\n(.*?)\n---\s*\n'
|
|
108
|
-
yaml_match = re.match(yaml_pattern, content, re.DOTALL)
|
|
109
|
-
|
|
110
|
-
metadata = {}
|
|
111
|
-
body = content
|
|
112
|
-
|
|
113
|
-
if yaml_match:
|
|
114
|
-
try:
|
|
115
|
-
metadata = yaml.safe_load(yaml_match.group(1)) or {}
|
|
116
|
-
except yaml.YAMLError:
|
|
117
|
-
metadata = {}
|
|
118
|
-
body = content[yaml_match.end():]
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
'metadata': metadata,
|
|
122
|
-
'body': body.strip()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
def split_content_by_separator(body: str) -> list:
|
|
127
|
-
"""按照 --- 分隔符拆分正文为多张卡片内容"""
|
|
128
|
-
parts = re.split(r'\n---+\n', body)
|
|
129
|
-
return [part.strip() for part in parts if part.strip()]
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def estimate_content_height(content: str) -> int:
|
|
133
|
-
"""预估内容高度(基于字数和元素类型)"""
|
|
134
|
-
lines = content.split('\n')
|
|
135
|
-
total_height = 0
|
|
136
|
-
|
|
137
|
-
for line in lines:
|
|
138
|
-
line = line.strip()
|
|
139
|
-
if not line:
|
|
140
|
-
total_height += 20 # 空行
|
|
141
|
-
continue
|
|
142
|
-
|
|
143
|
-
# 标题
|
|
144
|
-
if line.startswith('# '):
|
|
145
|
-
total_height += 130 # h1: font-size 72 + margin
|
|
146
|
-
elif line.startswith('## '):
|
|
147
|
-
total_height += 110 # h2
|
|
148
|
-
elif line.startswith('### '):
|
|
149
|
-
total_height += 90 # h3
|
|
150
|
-
# 代码块
|
|
151
|
-
elif line.startswith('```'):
|
|
152
|
-
total_height += 80 # 代码块起始/结束
|
|
153
|
-
# 列表
|
|
154
|
-
elif line.startswith(('- ', '* ', '+ ')):
|
|
155
|
-
total_height += 85 # li: line-height ~1.6, font-size 42
|
|
156
|
-
# 引用
|
|
157
|
-
elif line.startswith('>'):
|
|
158
|
-
total_height += 100 # blockquote padding
|
|
159
|
-
# 图片
|
|
160
|
-
elif line.startswith('!['):
|
|
161
|
-
total_height += 300 # 图片高度估计
|
|
162
|
-
# 普通段落
|
|
163
|
-
else:
|
|
164
|
-
# 估算字数
|
|
165
|
-
char_count = len(line)
|
|
166
|
-
# 一行约25-30个中文字,行高1.7,字体42px
|
|
167
|
-
lines_needed = max(1, char_count / 28)
|
|
168
|
-
total_height += int(lines_needed * 42 * 1.7) + 35 # + margin-bottom
|
|
169
|
-
|
|
170
|
-
return total_height
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def smart_split_content(content: str, max_height: int = SAFE_HEIGHT) -> List[str]:
|
|
174
|
-
"""
|
|
175
|
-
智能拆分内容到多张卡片
|
|
176
|
-
基于预估高度进行拆分,尽量保持段落完整
|
|
177
|
-
"""
|
|
178
|
-
# 首先尝试识别内容块(以标题或空行分隔)
|
|
179
|
-
blocks = []
|
|
180
|
-
current_block = []
|
|
181
|
-
|
|
182
|
-
lines = content.split('\n')
|
|
183
|
-
i = 0
|
|
184
|
-
while i < len(lines):
|
|
185
|
-
line = lines[i]
|
|
186
|
-
|
|
187
|
-
# 新标题开始新块(除非是第一个)
|
|
188
|
-
if line.strip().startswith('#') and current_block:
|
|
189
|
-
blocks.append('\n'.join(current_block))
|
|
190
|
-
current_block = [line]
|
|
191
|
-
# 分隔线
|
|
192
|
-
elif line.strip() == '---':
|
|
193
|
-
if current_block:
|
|
194
|
-
blocks.append('\n'.join(current_block))
|
|
195
|
-
current_block = []
|
|
196
|
-
else:
|
|
197
|
-
current_block.append(line)
|
|
198
|
-
|
|
199
|
-
i += 1
|
|
200
|
-
|
|
201
|
-
if current_block:
|
|
202
|
-
blocks.append('\n'.join(current_block))
|
|
203
|
-
|
|
204
|
-
# 如果没有明显的块边界,按段落拆分
|
|
205
|
-
if len(blocks) <= 1:
|
|
206
|
-
blocks = [b for b in content.split('\n\n') if b.strip()]
|
|
207
|
-
|
|
208
|
-
# 合并块到卡片,确保每张卡片高度不超过限制
|
|
209
|
-
cards = []
|
|
210
|
-
current_card = []
|
|
211
|
-
current_height = 0
|
|
212
|
-
|
|
213
|
-
for block in blocks:
|
|
214
|
-
block_height = estimate_content_height(block)
|
|
215
|
-
|
|
216
|
-
# 如果单个块就超过限制,需要进一步拆分
|
|
217
|
-
if block_height > max_height:
|
|
218
|
-
# 如果当前卡片有内容,先保存
|
|
219
|
-
if current_card:
|
|
220
|
-
cards.append('\n\n'.join(current_card))
|
|
221
|
-
current_card = []
|
|
222
|
-
current_height = 0
|
|
223
|
-
|
|
224
|
-
# 将大块按行拆分
|
|
225
|
-
lines = block.split('\n')
|
|
226
|
-
sub_block = []
|
|
227
|
-
sub_height = 0
|
|
228
|
-
|
|
229
|
-
for line in lines:
|
|
230
|
-
line_height = estimate_content_height(line)
|
|
231
|
-
|
|
232
|
-
if sub_height + line_height > max_height and sub_block:
|
|
233
|
-
cards.append('\n'.join(sub_block))
|
|
234
|
-
sub_block = [line]
|
|
235
|
-
sub_height = line_height
|
|
236
|
-
else:
|
|
237
|
-
sub_block.append(line)
|
|
238
|
-
sub_height += line_height
|
|
239
|
-
|
|
240
|
-
if sub_block:
|
|
241
|
-
cards.append('\n'.join(sub_block))
|
|
242
|
-
|
|
243
|
-
# 如果当前卡片加上这个块会超,先保存当前卡片
|
|
244
|
-
elif current_height + block_height > max_height and current_card:
|
|
245
|
-
cards.append('\n\n'.join(current_card))
|
|
246
|
-
current_card = [block]
|
|
247
|
-
current_height = block_height
|
|
248
|
-
|
|
249
|
-
# 否则加入当前卡片
|
|
250
|
-
else:
|
|
251
|
-
current_card.append(block)
|
|
252
|
-
current_height += block_height
|
|
253
|
-
|
|
254
|
-
# 保存最后一个卡片
|
|
255
|
-
if current_card:
|
|
256
|
-
cards.append('\n\n'.join(current_card))
|
|
257
|
-
|
|
258
|
-
return cards if cards else [content]
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def convert_markdown_to_html(md_content: str, style: dict = None) -> str:
|
|
262
|
-
"""将 Markdown 转换为 HTML"""
|
|
263
|
-
style = style or STYLES["purple"]
|
|
264
|
-
|
|
265
|
-
# 处理 tags(以 # 开头的标签)
|
|
266
|
-
tags_pattern = r'((?:#[\w\u4e00-\u9fa5]+\s*)+)$'
|
|
267
|
-
tags_match = re.search(tags_pattern, md_content, re.MULTILINE)
|
|
268
|
-
tags_html = ""
|
|
269
|
-
|
|
270
|
-
if tags_match:
|
|
271
|
-
tags_str = tags_match.group(1)
|
|
272
|
-
md_content = md_content[:tags_match.start()].strip()
|
|
273
|
-
tags = re.findall(r'#([\w\u4e00-\u9fa5]+)', tags_str)
|
|
274
|
-
if tags:
|
|
275
|
-
accent = style.get('accent_color', '#6366f1')
|
|
276
|
-
tags_html = f'<div class="tags-container">'
|
|
277
|
-
for tag in tags:
|
|
278
|
-
tags_html += f'<span class="tag" style="background: {accent};">#{tag}</span>'
|
|
279
|
-
tags_html += '</div>'
|
|
280
|
-
|
|
281
|
-
# 转换 Markdown 为 HTML
|
|
282
|
-
html = markdown.markdown(
|
|
283
|
-
md_content,
|
|
284
|
-
extensions=['extra', 'codehilite', 'tables', 'nl2br']
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
return html + tags_html
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
|
|
291
|
-
"""生成封面 HTML"""
|
|
292
|
-
style = STYLES.get(style_key, STYLES["purple"])
|
|
293
|
-
|
|
294
|
-
emoji = metadata.get('emoji', '📝')
|
|
295
|
-
title = metadata.get('title', '标题')
|
|
296
|
-
subtitle = metadata.get('subtitle', '')
|
|
297
|
-
|
|
298
|
-
# 限制标题和副标题长度
|
|
299
|
-
if len(title) > 15:
|
|
300
|
-
title = title[:15]
|
|
301
|
-
if len(subtitle) > 15:
|
|
302
|
-
subtitle = subtitle[:15]
|
|
303
|
-
|
|
304
|
-
# 暗黑模式特殊处理
|
|
305
|
-
is_dark = style_key == "dark"
|
|
306
|
-
text_color = "#ffffff" if is_dark else "#000000"
|
|
307
|
-
title_gradient = "linear-gradient(180deg, #ffffff 0%, #cccccc 100%)" if is_dark else "linear-gradient(180deg, #2E67B1 0%, #4C4C4C 100%)"
|
|
308
|
-
inner_bg = "#1a1a2e" if is_dark else "#F3F3F3"
|
|
309
|
-
|
|
310
|
-
return f'''<!DOCTYPE html>
|
|
311
|
-
<html lang="zh-CN">
|
|
312
|
-
<head>
|
|
313
|
-
<meta charset="UTF-8">
|
|
314
|
-
<meta name="viewport" content="width=1080, height=1440">
|
|
315
|
-
<title>小红书封面</title>
|
|
316
|
-
<style>
|
|
317
|
-
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap');
|
|
318
|
-
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
319
|
-
body {{
|
|
320
|
-
font-family: 'Noto Sans SC', 'Source Han Sans CN', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
321
|
-
width: 1080px; height: 1440px; overflow: hidden;
|
|
322
|
-
}}
|
|
323
|
-
.cover-container {{
|
|
324
|
-
width: 1080px; height: 1440px;
|
|
325
|
-
background: {style['cover_bg']};
|
|
326
|
-
position: relative; overflow: hidden;
|
|
327
|
-
}}
|
|
328
|
-
.cover-inner {{
|
|
329
|
-
position: absolute; width: 950px; height: 1310px;
|
|
330
|
-
left: 65px; top: 65px;
|
|
331
|
-
background: {inner_bg};
|
|
332
|
-
border-radius: 25px;
|
|
333
|
-
display: flex; flex-direction: column;
|
|
334
|
-
padding: 80px 85px;
|
|
335
|
-
}}
|
|
336
|
-
.cover-emoji {{ font-size: 180px; line-height: 1.2; margin-bottom: 50px; }}
|
|
337
|
-
.cover-title {{
|
|
338
|
-
font-weight: 900; font-size: 130px; line-height: 1.4;
|
|
339
|
-
background: {title_gradient};
|
|
340
|
-
-webkit-background-clip: text;
|
|
341
|
-
-webkit-text-fill-color: transparent;
|
|
342
|
-
background-clip: text;
|
|
343
|
-
flex: 1;
|
|
344
|
-
display: flex; align-items: flex-start;
|
|
345
|
-
word-break: break-all;
|
|
346
|
-
}}
|
|
347
|
-
.cover-subtitle {{
|
|
348
|
-
font-weight: 350; font-size: 72px; line-height: 1.4;
|
|
349
|
-
color: {text_color};
|
|
350
|
-
margin-top: auto;
|
|
351
|
-
}}
|
|
352
|
-
</style>
|
|
353
|
-
</head>
|
|
354
|
-
<body>
|
|
355
|
-
<div class="cover-container">
|
|
356
|
-
<div class="cover-inner">
|
|
357
|
-
<div class="cover-emoji">{emoji}</div>
|
|
358
|
-
<div class="cover-title">{title}</div>
|
|
359
|
-
<div class="cover-subtitle">{subtitle}</div>
|
|
360
|
-
</div>
|
|
361
|
-
</div>
|
|
362
|
-
</body>
|
|
363
|
-
</html>'''
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
def generate_card_html(content: str, page_number: int = 1, total_pages: int = 1,
|
|
367
|
-
style_key: str = "purple") -> str:
|
|
368
|
-
"""生成正文卡片 HTML"""
|
|
369
|
-
style = STYLES.get(style_key, STYLES["purple"])
|
|
370
|
-
html_content = convert_markdown_to_html(content, style)
|
|
371
|
-
page_text = f"{page_number}/{total_pages}" if total_pages > 1 else ""
|
|
372
|
-
|
|
373
|
-
# 暗黑模式特殊处理
|
|
374
|
-
is_dark = style_key == "dark"
|
|
375
|
-
card_bg = "rgba(30, 30, 46, 0.95)" if is_dark else "rgba(255, 255, 255, 0.95)"
|
|
376
|
-
text_color = "#e0e0e0" if is_dark else "#475569"
|
|
377
|
-
heading_color = "#ffffff" if is_dark else "#1e293b"
|
|
378
|
-
h2_color = "#e0e0e0" if is_dark else "#334155"
|
|
379
|
-
h3_color = "#c0c0c0" if is_dark else "#475569"
|
|
380
|
-
code_bg = "#0f0f23" if is_dark else "#1e293b"
|
|
381
|
-
pre_bg = "#0f0f23" if is_dark else "#1e293b"
|
|
382
|
-
blockquote_bg = "#252540" if is_dark else "#f1f5f9"
|
|
383
|
-
blockquote_border = style['accent_color']
|
|
384
|
-
blockquote_color = "#a0a0a0" if is_dark else "#64748b"
|
|
385
|
-
|
|
386
|
-
return f'''<!DOCTYPE html>
|
|
387
|
-
<html lang="zh-CN">
|
|
388
|
-
<head>
|
|
389
|
-
<meta charset="UTF-8">
|
|
390
|
-
<meta name="viewport" content="width=1080">
|
|
391
|
-
<title>小红书卡片</title>
|
|
392
|
-
<style>
|
|
393
|
-
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap');
|
|
394
|
-
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
395
|
-
body {{
|
|
396
|
-
font-family: 'Noto Sans SC', 'Source Han Sans CN', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
397
|
-
width: 1080px; min-height: 1440px; overflow: hidden; background: transparent;
|
|
398
|
-
}}
|
|
399
|
-
.card-container {{
|
|
400
|
-
width: 1080px; min-height: 1440px;
|
|
401
|
-
background: {style['card_bg']};
|
|
402
|
-
position: relative; padding: 50px; overflow: hidden;
|
|
403
|
-
}}
|
|
404
|
-
.card-inner {{
|
|
405
|
-
background: {card_bg};
|
|
406
|
-
border-radius: 20px;
|
|
407
|
-
padding: 60px;
|
|
408
|
-
min-height: calc(1440px - 100px);
|
|
409
|
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
410
|
-
backdrop-filter: blur(10px);
|
|
411
|
-
}}
|
|
412
|
-
.card-content {{
|
|
413
|
-
color: {text_color};
|
|
414
|
-
font-size: 42px;
|
|
415
|
-
line-height: 1.7;
|
|
416
|
-
}}
|
|
417
|
-
.card-content h1 {{
|
|
418
|
-
font-size: 72px; font-weight: 700; color: {heading_color};
|
|
419
|
-
margin-bottom: 40px; line-height: 1.3;
|
|
420
|
-
}}
|
|
421
|
-
.card-content h2 {{
|
|
422
|
-
font-size: 56px; font-weight: 600; color: {h2_color};
|
|
423
|
-
margin: 50px 0 25px 0; line-height: 1.4;
|
|
424
|
-
}}
|
|
425
|
-
.card-content h3 {{
|
|
426
|
-
font-size: 48px; font-weight: 600; color: {h3_color};
|
|
427
|
-
margin: 40px 0 20px 0;
|
|
428
|
-
}}
|
|
429
|
-
.card-content p {{ margin-bottom: 35px; }}
|
|
430
|
-
.card-content strong {{ font-weight: 700; color: {heading_color}; }}
|
|
431
|
-
.card-content em {{ font-style: italic; color: {style['accent_color']}; }}
|
|
432
|
-
.card-content a {{
|
|
433
|
-
color: {style['accent_color']}; text-decoration: none;
|
|
434
|
-
border-bottom: 2px solid {style['accent_color']};
|
|
435
|
-
}}
|
|
436
|
-
.card-content ul, .card-content ol {{
|
|
437
|
-
margin: 30px 0; padding-left: 60px;
|
|
438
|
-
}}
|
|
439
|
-
.card-content li {{ margin-bottom: 20px; line-height: 1.6; }}
|
|
440
|
-
.card-content blockquote {{
|
|
441
|
-
border-left: 8px solid {blockquote_border};
|
|
442
|
-
padding-left: 40px;
|
|
443
|
-
background: {blockquote_bg};
|
|
444
|
-
padding-top: 25px; padding-bottom: 25px; padding-right: 30px;
|
|
445
|
-
margin: 35px 0;
|
|
446
|
-
color: {blockquote_color};
|
|
447
|
-
font-style: italic;
|
|
448
|
-
border-radius: 0 12px 12px 0;
|
|
449
|
-
}}
|
|
450
|
-
.card-content blockquote p {{ margin: 0; }}
|
|
451
|
-
.card-content code {{
|
|
452
|
-
background: {'#252540' if is_dark else '#f1f5f9'};
|
|
453
|
-
padding: 6px 16px; border-radius: 8px;
|
|
454
|
-
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
|
|
455
|
-
font-size: 38px;
|
|
456
|
-
color: {style['accent_color']};
|
|
457
|
-
}}
|
|
458
|
-
.card-content pre {{
|
|
459
|
-
background: {pre_bg};
|
|
460
|
-
color: {'#e0e0e0' if is_dark else '#e2e8f0'};
|
|
461
|
-
padding: 40px; border-radius: 16px;
|
|
462
|
-
margin: 35px 0;
|
|
463
|
-
overflow-x: visible;
|
|
464
|
-
overflow-wrap: break-word;
|
|
465
|
-
word-wrap: break-word;
|
|
466
|
-
word-break: break-all;
|
|
467
|
-
white-space: pre-wrap;
|
|
468
|
-
font-size: 36px; line-height: 1.5;
|
|
469
|
-
}}
|
|
470
|
-
.card-content pre code {{
|
|
471
|
-
background: transparent; color: inherit; padding: 0; font-size: inherit;
|
|
472
|
-
}}
|
|
473
|
-
.card-content img {{
|
|
474
|
-
max-width: 100%; height: auto; border-radius: 16px;
|
|
475
|
-
margin: 35px auto; display: block;
|
|
476
|
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
|
477
|
-
}}
|
|
478
|
-
.card-content hr {{
|
|
479
|
-
border: none; height: 2px;
|
|
480
|
-
background: {'#333355' if is_dark else '#e2e8f0'};
|
|
481
|
-
margin: 50px 0;
|
|
482
|
-
}}
|
|
483
|
-
.tags-container {{
|
|
484
|
-
margin-top: 50px; padding-top: 30px;
|
|
485
|
-
border-top: 2px solid {'#333355' if is_dark else '#e2e8f0'};
|
|
486
|
-
}}
|
|
487
|
-
.tag {{
|
|
488
|
-
display: inline-block;
|
|
489
|
-
background: {style['accent_color']};
|
|
490
|
-
color: white;
|
|
491
|
-
padding: 12px 28px; border-radius: 30px;
|
|
492
|
-
font-size: 34px;
|
|
493
|
-
margin: 10px 15px 10px 0;
|
|
494
|
-
font-weight: 500;
|
|
495
|
-
}}
|
|
496
|
-
.page-number {{
|
|
497
|
-
position: absolute;
|
|
498
|
-
bottom: 80px; right: 80px;
|
|
499
|
-
font-size: 36px;
|
|
500
|
-
color: rgba(255, 255, 255, 0.8);
|
|
501
|
-
font-weight: 500;
|
|
502
|
-
}}
|
|
503
|
-
</style>
|
|
504
|
-
</head>
|
|
505
|
-
<body>
|
|
506
|
-
<div class="card-container">
|
|
507
|
-
<div class="card-inner">
|
|
508
|
-
<div class="card-content">
|
|
509
|
-
{html_content}
|
|
510
|
-
</div>
|
|
511
|
-
</div>
|
|
512
|
-
<div class="page-number">{page_text}</div>
|
|
513
|
-
</div>
|
|
514
|
-
</body>
|
|
515
|
-
</html>'''
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
async def measure_content_height(page: Page, html_content: str) -> int:
|
|
519
|
-
"""使用 Playwright 测量实际内容高度"""
|
|
520
|
-
await page.set_content(html_content, wait_until='networkidle')
|
|
521
|
-
await page.wait_for_timeout(300) # 等待字体渲染
|
|
522
|
-
|
|
523
|
-
height = await page.evaluate('''() => {
|
|
524
|
-
const inner = document.querySelector('.card-inner');
|
|
525
|
-
if (inner) {
|
|
526
|
-
return inner.scrollHeight;
|
|
527
|
-
}
|
|
528
|
-
const container = document.querySelector('.card-container');
|
|
529
|
-
return container ? container.scrollHeight : document.body.scrollHeight;
|
|
530
|
-
}''')
|
|
531
|
-
|
|
532
|
-
return height
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
async def render_html_to_image(html_content: str, output_path: str,
|
|
536
|
-
width: int = CARD_WIDTH, height: int = CARD_HEIGHT):
|
|
537
|
-
"""使用 Playwright 将 HTML 渲染为图片"""
|
|
538
|
-
async with async_playwright() as p:
|
|
539
|
-
browser = await p.chromium.launch()
|
|
540
|
-
page = await browser.new_page(viewport={'width': width, 'height': height})
|
|
541
|
-
|
|
542
|
-
try:
|
|
543
|
-
await page.set_content(html_content, wait_until='networkidle')
|
|
544
|
-
await page.wait_for_timeout(300)
|
|
545
|
-
|
|
546
|
-
# 截图固定尺寸
|
|
547
|
-
await page.screenshot(
|
|
548
|
-
path=output_path,
|
|
549
|
-
clip={'x': 0, 'y': 0, 'width': width, 'height': height},
|
|
550
|
-
type='png'
|
|
551
|
-
)
|
|
552
|
-
|
|
553
|
-
print(f" ✅ 已生成: {output_path}")
|
|
554
|
-
|
|
555
|
-
finally:
|
|
556
|
-
await browser.close()
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
async def process_and_render_cards(card_contents: List[str], output_dir: str,
|
|
560
|
-
style_key: str) -> List[str]:
|
|
561
|
-
"""
|
|
562
|
-
处理卡片内容,检测高度并自动分页,然后渲染
|
|
563
|
-
返回最终生成的所有卡片文件路径
|
|
564
|
-
"""
|
|
565
|
-
async with async_playwright() as p:
|
|
566
|
-
browser = await p.chromium.launch()
|
|
567
|
-
page = await browser.new_page(viewport={'width': CARD_WIDTH, 'height': CARD_HEIGHT})
|
|
568
|
-
|
|
569
|
-
all_cards = []
|
|
570
|
-
|
|
571
|
-
try:
|
|
572
|
-
for content in card_contents:
|
|
573
|
-
# 预估内容高度
|
|
574
|
-
estimated_height = estimate_content_height(content)
|
|
575
|
-
|
|
576
|
-
# 如果预估高度超过安全高度,尝试拆分
|
|
577
|
-
if estimated_height > SAFE_HEIGHT:
|
|
578
|
-
split_contents = smart_split_content(content, SAFE_HEIGHT)
|
|
579
|
-
else:
|
|
580
|
-
split_contents = [content]
|
|
581
|
-
|
|
582
|
-
# 验证每个拆分后的内容
|
|
583
|
-
for split_content in split_contents:
|
|
584
|
-
# 生成临时 HTML 测量
|
|
585
|
-
temp_html = generate_card_html(split_content, 1, 1, style_key)
|
|
586
|
-
actual_height = await measure_content_height(page, temp_html)
|
|
587
|
-
|
|
588
|
-
# 如果仍然超出,进一步按行拆分
|
|
589
|
-
if actual_height > CARD_HEIGHT - 100:
|
|
590
|
-
lines = split_content.split('\n')
|
|
591
|
-
sub_contents = []
|
|
592
|
-
sub_lines = []
|
|
593
|
-
sub_height = 0
|
|
594
|
-
|
|
595
|
-
for line in lines:
|
|
596
|
-
test_lines = sub_lines + [line]
|
|
597
|
-
test_html = generate_card_html('\n'.join(test_lines), 1, 1, style_key)
|
|
598
|
-
test_height = await measure_content_height(page, test_html)
|
|
599
|
-
|
|
600
|
-
if test_height > CARD_HEIGHT - 100 and sub_lines:
|
|
601
|
-
sub_contents.append('\n'.join(sub_lines))
|
|
602
|
-
sub_lines = [line]
|
|
603
|
-
else:
|
|
604
|
-
sub_lines = test_lines
|
|
605
|
-
|
|
606
|
-
if sub_lines:
|
|
607
|
-
sub_contents.append('\n'.join(sub_lines))
|
|
608
|
-
|
|
609
|
-
all_cards.extend(sub_contents)
|
|
610
|
-
else:
|
|
611
|
-
all_cards.append(split_content)
|
|
612
|
-
|
|
613
|
-
finally:
|
|
614
|
-
await browser.close()
|
|
615
|
-
|
|
616
|
-
return all_cards
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
async def render_markdown_to_cards(md_file: str, output_dir: str, style_key: str = "purple"):
|
|
620
|
-
"""主渲染函数:将 Markdown 文件渲染为多张卡片图片"""
|
|
621
|
-
print(f"\n🎨 开始渲染: {md_file}")
|
|
622
|
-
print(f"🎨 使用样式: {STYLES[style_key]['name']}")
|
|
623
|
-
|
|
624
|
-
# 确保输出目录存在
|
|
625
|
-
os.makedirs(output_dir, exist_ok=True)
|
|
626
|
-
|
|
627
|
-
# 解析 Markdown 文件
|
|
628
|
-
data = parse_markdown_file(md_file)
|
|
629
|
-
metadata = data['metadata']
|
|
630
|
-
body = data['body']
|
|
631
|
-
|
|
632
|
-
# 分割正文内容(基于用户手动分隔符)
|
|
633
|
-
card_contents = split_content_by_separator(body)
|
|
634
|
-
print(f" 📄 检测到 {len(card_contents)} 个内容块")
|
|
635
|
-
|
|
636
|
-
# 处理内容,智能分页
|
|
637
|
-
print(" 🔍 分析内容高度并智能分页...")
|
|
638
|
-
processed_cards = await process_and_render_cards(card_contents, output_dir, style_key)
|
|
639
|
-
total_cards = len(processed_cards)
|
|
640
|
-
print(f" 📄 将生成 {total_cards} 张卡片")
|
|
641
|
-
|
|
642
|
-
# 生成封面
|
|
643
|
-
if metadata.get('emoji') or metadata.get('title'):
|
|
644
|
-
print(" 📷 生成封面...")
|
|
645
|
-
cover_html = generate_cover_html(metadata, style_key)
|
|
646
|
-
cover_path = os.path.join(output_dir, 'cover.png')
|
|
647
|
-
await render_html_to_image(cover_html, cover_path)
|
|
648
|
-
|
|
649
|
-
# 生成正文卡片
|
|
650
|
-
async with async_playwright() as p:
|
|
651
|
-
browser = await p.chromium.launch()
|
|
652
|
-
page = await browser.new_page(viewport={'width': CARD_WIDTH, 'height': CARD_HEIGHT})
|
|
653
|
-
|
|
654
|
-
try:
|
|
655
|
-
for i, content in enumerate(processed_cards, 1):
|
|
656
|
-
print(f" 📷 生成卡片 {i}/{total_cards}...")
|
|
657
|
-
card_html = generate_card_html(content, i, total_cards, style_key)
|
|
658
|
-
card_path = os.path.join(output_dir, f'card_{i}.png')
|
|
659
|
-
|
|
660
|
-
await page.set_content(card_html, wait_until='networkidle')
|
|
661
|
-
await page.wait_for_timeout(300)
|
|
662
|
-
|
|
663
|
-
await page.screenshot(
|
|
664
|
-
path=card_path,
|
|
665
|
-
clip={'x': 0, 'y': 0, 'width': CARD_WIDTH, 'height': CARD_HEIGHT},
|
|
666
|
-
type='png'
|
|
667
|
-
)
|
|
668
|
-
print(f" ✅ 已生成: {card_path}")
|
|
669
|
-
|
|
670
|
-
finally:
|
|
671
|
-
await browser.close()
|
|
672
|
-
|
|
673
|
-
print(f"\n✨ 渲染完成!共生成 {total_cards} 张卡片,保存到: {output_dir}")
|
|
674
|
-
return total_cards
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
def list_styles():
|
|
678
|
-
"""列出所有可用样式"""
|
|
679
|
-
print("\n📋 可用样式列表:")
|
|
680
|
-
print("-" * 40)
|
|
681
|
-
for key, style in STYLES.items():
|
|
682
|
-
print(f" {key:12} - {style['name']}")
|
|
683
|
-
print("-" * 40)
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
def main():
|
|
687
|
-
parser = argparse.ArgumentParser(
|
|
688
|
-
description='将 Markdown 文件渲染为小红书风格的图片卡片(智能分页版)',
|
|
689
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
690
|
-
epilog='''
|
|
691
|
-
示例:
|
|
692
|
-
python render_xhs_v2.py note.md
|
|
693
|
-
python render_xhs_v2.py note.md -o ./output --style xiaohongshu
|
|
694
|
-
python render_xhs_v2.py --list-styles
|
|
695
|
-
'''
|
|
696
|
-
)
|
|
697
|
-
parser.add_argument(
|
|
698
|
-
'markdown_file',
|
|
699
|
-
nargs='?',
|
|
700
|
-
help='Markdown 文件路径'
|
|
701
|
-
)
|
|
702
|
-
parser.add_argument(
|
|
703
|
-
'--output-dir', '-o',
|
|
704
|
-
default=os.getcwd(),
|
|
705
|
-
help='输出目录(默认为当前工作目录)'
|
|
706
|
-
)
|
|
707
|
-
parser.add_argument(
|
|
708
|
-
'--style', '-s',
|
|
709
|
-
default='purple',
|
|
710
|
-
choices=list(STYLES.keys()),
|
|
711
|
-
help='样式主题(默认: purple)'
|
|
712
|
-
)
|
|
713
|
-
parser.add_argument(
|
|
714
|
-
'--list-styles',
|
|
715
|
-
action='store_true',
|
|
716
|
-
help='列出所有可用样式'
|
|
717
|
-
)
|
|
718
|
-
|
|
719
|
-
args = parser.parse_args()
|
|
720
|
-
|
|
721
|
-
if args.list_styles:
|
|
722
|
-
list_styles()
|
|
723
|
-
return
|
|
724
|
-
|
|
725
|
-
if not args.markdown_file:
|
|
726
|
-
parser.print_help()
|
|
727
|
-
sys.exit(1)
|
|
728
|
-
|
|
729
|
-
if not os.path.exists(args.markdown_file):
|
|
730
|
-
print(f"❌ 错误: 文件不存在 - {args.markdown_file}")
|
|
731
|
-
sys.exit(1)
|
|
732
|
-
|
|
733
|
-
asyncio.run(render_markdown_to_cards(args.markdown_file, args.output_dir, args.style))
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
if __name__ == '__main__':
|
|
737
|
-
main()
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
小红书卡片渲染脚本 V2 - 智能分页版
|
|
4
|
+
将 Markdown 文件渲染为小红书风格的图片卡片
|
|
5
|
+
|
|
6
|
+
新特性:
|
|
7
|
+
1. 智能分页:自动检测内容高度,超出时自动拆分到多张卡片
|
|
8
|
+
2. 多种样式:支持多种预设样式主题
|
|
9
|
+
3. 字数预估:基于字数预分配内容,减少渲染次数
|
|
10
|
+
|
|
11
|
+
使用方法:
|
|
12
|
+
python render_xhs_v2.py <markdown_file> [options]
|
|
13
|
+
|
|
14
|
+
依赖安装:
|
|
15
|
+
pip install markdown pyyaml playwright
|
|
16
|
+
playwright install chromium
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import asyncio
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sys
|
|
24
|
+
import tempfile
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import List, Dict, Tuple
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
import markdown
|
|
30
|
+
import yaml
|
|
31
|
+
from playwright.async_api import async_playwright, Page
|
|
32
|
+
except ImportError as e:
|
|
33
|
+
print(f"缺少依赖: {e}")
|
|
34
|
+
print("请运行: pip install markdown pyyaml playwright && playwright install chromium")
|
|
35
|
+
sys.exit(1)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# 获取脚本所在目录
|
|
39
|
+
SCRIPT_DIR = Path(__file__).parent.parent
|
|
40
|
+
ASSETS_DIR = SCRIPT_DIR / "assets"
|
|
41
|
+
|
|
42
|
+
# 卡片尺寸配置 (3:4 比例)
|
|
43
|
+
CARD_WIDTH = 1080
|
|
44
|
+
CARD_HEIGHT = 1440
|
|
45
|
+
|
|
46
|
+
# 内容区域安全高度(考虑 padding 和 margin)
|
|
47
|
+
# card-inner padding: 60px * 2 = 120px
|
|
48
|
+
# card-container padding: 50px * 2 = 100px
|
|
49
|
+
# 页码区域: ~80px
|
|
50
|
+
# 安全边距: ~40px
|
|
51
|
+
SAFE_HEIGHT = CARD_HEIGHT - 120 - 100 - 80 - 40 # ~1100px
|
|
52
|
+
|
|
53
|
+
# 样式配置
|
|
54
|
+
STYLES = {
|
|
55
|
+
"purple": {
|
|
56
|
+
"name": "紫韵",
|
|
57
|
+
"cover_bg": "linear-gradient(180deg, #3450E4 0%, #D266DA 100%)",
|
|
58
|
+
"card_bg": "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
59
|
+
"accent_color": "#6366f1",
|
|
60
|
+
},
|
|
61
|
+
"xiaohongshu": {
|
|
62
|
+
"name": "小红书红",
|
|
63
|
+
"cover_bg": "linear-gradient(180deg, #FF2442 0%, #FF6B81 100%)",
|
|
64
|
+
"card_bg": "linear-gradient(135deg, #FF2442 0%, #FF6B81 100%)",
|
|
65
|
+
"accent_color": "#FF2442",
|
|
66
|
+
},
|
|
67
|
+
"mint": {
|
|
68
|
+
"name": "清新薄荷",
|
|
69
|
+
"cover_bg": "linear-gradient(180deg, #43e97b 0%, #38f9d7 100%)",
|
|
70
|
+
"card_bg": "linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)",
|
|
71
|
+
"accent_color": "#43e97b",
|
|
72
|
+
},
|
|
73
|
+
"sunset": {
|
|
74
|
+
"name": "日落橙",
|
|
75
|
+
"cover_bg": "linear-gradient(180deg, #fa709a 0%, #fee140 100%)",
|
|
76
|
+
"card_bg": "linear-gradient(135deg, #fa709a 0%, #fee140 100%)",
|
|
77
|
+
"accent_color": "#fa709a",
|
|
78
|
+
},
|
|
79
|
+
"ocean": {
|
|
80
|
+
"name": "深海蓝",
|
|
81
|
+
"cover_bg": "linear-gradient(180deg, #4facfe 0%, #00f2fe 100%)",
|
|
82
|
+
"card_bg": "linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",
|
|
83
|
+
"accent_color": "#4facfe",
|
|
84
|
+
},
|
|
85
|
+
"elegant": {
|
|
86
|
+
"name": "优雅白",
|
|
87
|
+
"cover_bg": "linear-gradient(180deg, #f5f5f5 0%, #e0e0e0 100%)",
|
|
88
|
+
"card_bg": "linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%)",
|
|
89
|
+
"accent_color": "#333333",
|
|
90
|
+
"text_light": "#555555",
|
|
91
|
+
},
|
|
92
|
+
"dark": {
|
|
93
|
+
"name": "暗黑模式",
|
|
94
|
+
"cover_bg": "linear-gradient(180deg, #1a1a2e 0%, #16213e 100%)",
|
|
95
|
+
"card_bg": "linear-gradient(135deg, #1a1a2e 0%, #16213e 100%)",
|
|
96
|
+
"accent_color": "#e94560",
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def parse_markdown_file(file_path: str) -> dict:
|
|
102
|
+
"""解析 Markdown 文件,提取 YAML 头部和正文内容"""
|
|
103
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
104
|
+
content = f.read()
|
|
105
|
+
|
|
106
|
+
# 解析 YAML 头部
|
|
107
|
+
yaml_pattern = r'^---\s*\n(.*?)\n---\s*\n'
|
|
108
|
+
yaml_match = re.match(yaml_pattern, content, re.DOTALL)
|
|
109
|
+
|
|
110
|
+
metadata = {}
|
|
111
|
+
body = content
|
|
112
|
+
|
|
113
|
+
if yaml_match:
|
|
114
|
+
try:
|
|
115
|
+
metadata = yaml.safe_load(yaml_match.group(1)) or {}
|
|
116
|
+
except yaml.YAMLError:
|
|
117
|
+
metadata = {}
|
|
118
|
+
body = content[yaml_match.end():]
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
'metadata': metadata,
|
|
122
|
+
'body': body.strip()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def split_content_by_separator(body: str) -> list:
|
|
127
|
+
"""按照 --- 分隔符拆分正文为多张卡片内容"""
|
|
128
|
+
parts = re.split(r'\n---+\n', body)
|
|
129
|
+
return [part.strip() for part in parts if part.strip()]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def estimate_content_height(content: str) -> int:
|
|
133
|
+
"""预估内容高度(基于字数和元素类型)"""
|
|
134
|
+
lines = content.split('\n')
|
|
135
|
+
total_height = 0
|
|
136
|
+
|
|
137
|
+
for line in lines:
|
|
138
|
+
line = line.strip()
|
|
139
|
+
if not line:
|
|
140
|
+
total_height += 20 # 空行
|
|
141
|
+
continue
|
|
142
|
+
|
|
143
|
+
# 标题
|
|
144
|
+
if line.startswith('# '):
|
|
145
|
+
total_height += 130 # h1: font-size 72 + margin
|
|
146
|
+
elif line.startswith('## '):
|
|
147
|
+
total_height += 110 # h2
|
|
148
|
+
elif line.startswith('### '):
|
|
149
|
+
total_height += 90 # h3
|
|
150
|
+
# 代码块
|
|
151
|
+
elif line.startswith('```'):
|
|
152
|
+
total_height += 80 # 代码块起始/结束
|
|
153
|
+
# 列表
|
|
154
|
+
elif line.startswith(('- ', '* ', '+ ')):
|
|
155
|
+
total_height += 85 # li: line-height ~1.6, font-size 42
|
|
156
|
+
# 引用
|
|
157
|
+
elif line.startswith('>'):
|
|
158
|
+
total_height += 100 # blockquote padding
|
|
159
|
+
# 图片
|
|
160
|
+
elif line.startswith('!['):
|
|
161
|
+
total_height += 300 # 图片高度估计
|
|
162
|
+
# 普通段落
|
|
163
|
+
else:
|
|
164
|
+
# 估算字数
|
|
165
|
+
char_count = len(line)
|
|
166
|
+
# 一行约25-30个中文字,行高1.7,字体42px
|
|
167
|
+
lines_needed = max(1, char_count / 28)
|
|
168
|
+
total_height += int(lines_needed * 42 * 1.7) + 35 # + margin-bottom
|
|
169
|
+
|
|
170
|
+
return total_height
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def smart_split_content(content: str, max_height: int = SAFE_HEIGHT) -> List[str]:
|
|
174
|
+
"""
|
|
175
|
+
智能拆分内容到多张卡片
|
|
176
|
+
基于预估高度进行拆分,尽量保持段落完整
|
|
177
|
+
"""
|
|
178
|
+
# 首先尝试识别内容块(以标题或空行分隔)
|
|
179
|
+
blocks = []
|
|
180
|
+
current_block = []
|
|
181
|
+
|
|
182
|
+
lines = content.split('\n')
|
|
183
|
+
i = 0
|
|
184
|
+
while i < len(lines):
|
|
185
|
+
line = lines[i]
|
|
186
|
+
|
|
187
|
+
# 新标题开始新块(除非是第一个)
|
|
188
|
+
if line.strip().startswith('#') and current_block:
|
|
189
|
+
blocks.append('\n'.join(current_block))
|
|
190
|
+
current_block = [line]
|
|
191
|
+
# 分隔线
|
|
192
|
+
elif line.strip() == '---':
|
|
193
|
+
if current_block:
|
|
194
|
+
blocks.append('\n'.join(current_block))
|
|
195
|
+
current_block = []
|
|
196
|
+
else:
|
|
197
|
+
current_block.append(line)
|
|
198
|
+
|
|
199
|
+
i += 1
|
|
200
|
+
|
|
201
|
+
if current_block:
|
|
202
|
+
blocks.append('\n'.join(current_block))
|
|
203
|
+
|
|
204
|
+
# 如果没有明显的块边界,按段落拆分
|
|
205
|
+
if len(blocks) <= 1:
|
|
206
|
+
blocks = [b for b in content.split('\n\n') if b.strip()]
|
|
207
|
+
|
|
208
|
+
# 合并块到卡片,确保每张卡片高度不超过限制
|
|
209
|
+
cards = []
|
|
210
|
+
current_card = []
|
|
211
|
+
current_height = 0
|
|
212
|
+
|
|
213
|
+
for block in blocks:
|
|
214
|
+
block_height = estimate_content_height(block)
|
|
215
|
+
|
|
216
|
+
# 如果单个块就超过限制,需要进一步拆分
|
|
217
|
+
if block_height > max_height:
|
|
218
|
+
# 如果当前卡片有内容,先保存
|
|
219
|
+
if current_card:
|
|
220
|
+
cards.append('\n\n'.join(current_card))
|
|
221
|
+
current_card = []
|
|
222
|
+
current_height = 0
|
|
223
|
+
|
|
224
|
+
# 将大块按行拆分
|
|
225
|
+
lines = block.split('\n')
|
|
226
|
+
sub_block = []
|
|
227
|
+
sub_height = 0
|
|
228
|
+
|
|
229
|
+
for line in lines:
|
|
230
|
+
line_height = estimate_content_height(line)
|
|
231
|
+
|
|
232
|
+
if sub_height + line_height > max_height and sub_block:
|
|
233
|
+
cards.append('\n'.join(sub_block))
|
|
234
|
+
sub_block = [line]
|
|
235
|
+
sub_height = line_height
|
|
236
|
+
else:
|
|
237
|
+
sub_block.append(line)
|
|
238
|
+
sub_height += line_height
|
|
239
|
+
|
|
240
|
+
if sub_block:
|
|
241
|
+
cards.append('\n'.join(sub_block))
|
|
242
|
+
|
|
243
|
+
# 如果当前卡片加上这个块会超,先保存当前卡片
|
|
244
|
+
elif current_height + block_height > max_height and current_card:
|
|
245
|
+
cards.append('\n\n'.join(current_card))
|
|
246
|
+
current_card = [block]
|
|
247
|
+
current_height = block_height
|
|
248
|
+
|
|
249
|
+
# 否则加入当前卡片
|
|
250
|
+
else:
|
|
251
|
+
current_card.append(block)
|
|
252
|
+
current_height += block_height
|
|
253
|
+
|
|
254
|
+
# 保存最后一个卡片
|
|
255
|
+
if current_card:
|
|
256
|
+
cards.append('\n\n'.join(current_card))
|
|
257
|
+
|
|
258
|
+
return cards if cards else [content]
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def convert_markdown_to_html(md_content: str, style: dict = None) -> str:
|
|
262
|
+
"""将 Markdown 转换为 HTML"""
|
|
263
|
+
style = style or STYLES["purple"]
|
|
264
|
+
|
|
265
|
+
# 处理 tags(以 # 开头的标签)
|
|
266
|
+
tags_pattern = r'((?:#[\w\u4e00-\u9fa5]+\s*)+)$'
|
|
267
|
+
tags_match = re.search(tags_pattern, md_content, re.MULTILINE)
|
|
268
|
+
tags_html = ""
|
|
269
|
+
|
|
270
|
+
if tags_match:
|
|
271
|
+
tags_str = tags_match.group(1)
|
|
272
|
+
md_content = md_content[:tags_match.start()].strip()
|
|
273
|
+
tags = re.findall(r'#([\w\u4e00-\u9fa5]+)', tags_str)
|
|
274
|
+
if tags:
|
|
275
|
+
accent = style.get('accent_color', '#6366f1')
|
|
276
|
+
tags_html = f'<div class="tags-container">'
|
|
277
|
+
for tag in tags:
|
|
278
|
+
tags_html += f'<span class="tag" style="background: {accent};">#{tag}</span>'
|
|
279
|
+
tags_html += '</div>'
|
|
280
|
+
|
|
281
|
+
# 转换 Markdown 为 HTML
|
|
282
|
+
html = markdown.markdown(
|
|
283
|
+
md_content,
|
|
284
|
+
extensions=['extra', 'codehilite', 'tables', 'nl2br']
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
return html + tags_html
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def generate_cover_html(metadata: dict, style_key: str = "purple") -> str:
|
|
291
|
+
"""生成封面 HTML"""
|
|
292
|
+
style = STYLES.get(style_key, STYLES["purple"])
|
|
293
|
+
|
|
294
|
+
emoji = metadata.get('emoji', '📝')
|
|
295
|
+
title = metadata.get('title', '标题')
|
|
296
|
+
subtitle = metadata.get('subtitle', '')
|
|
297
|
+
|
|
298
|
+
# 限制标题和副标题长度
|
|
299
|
+
if len(title) > 15:
|
|
300
|
+
title = title[:15]
|
|
301
|
+
if len(subtitle) > 15:
|
|
302
|
+
subtitle = subtitle[:15]
|
|
303
|
+
|
|
304
|
+
# 暗黑模式特殊处理
|
|
305
|
+
is_dark = style_key == "dark"
|
|
306
|
+
text_color = "#ffffff" if is_dark else "#000000"
|
|
307
|
+
title_gradient = "linear-gradient(180deg, #ffffff 0%, #cccccc 100%)" if is_dark else "linear-gradient(180deg, #2E67B1 0%, #4C4C4C 100%)"
|
|
308
|
+
inner_bg = "#1a1a2e" if is_dark else "#F3F3F3"
|
|
309
|
+
|
|
310
|
+
return f'''<!DOCTYPE html>
|
|
311
|
+
<html lang="zh-CN">
|
|
312
|
+
<head>
|
|
313
|
+
<meta charset="UTF-8">
|
|
314
|
+
<meta name="viewport" content="width=1080, height=1440">
|
|
315
|
+
<title>小红书封面</title>
|
|
316
|
+
<style>
|
|
317
|
+
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap');
|
|
318
|
+
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
319
|
+
body {{
|
|
320
|
+
font-family: 'Noto Sans SC', 'Source Han Sans CN', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
321
|
+
width: 1080px; height: 1440px; overflow: hidden;
|
|
322
|
+
}}
|
|
323
|
+
.cover-container {{
|
|
324
|
+
width: 1080px; height: 1440px;
|
|
325
|
+
background: {style['cover_bg']};
|
|
326
|
+
position: relative; overflow: hidden;
|
|
327
|
+
}}
|
|
328
|
+
.cover-inner {{
|
|
329
|
+
position: absolute; width: 950px; height: 1310px;
|
|
330
|
+
left: 65px; top: 65px;
|
|
331
|
+
background: {inner_bg};
|
|
332
|
+
border-radius: 25px;
|
|
333
|
+
display: flex; flex-direction: column;
|
|
334
|
+
padding: 80px 85px;
|
|
335
|
+
}}
|
|
336
|
+
.cover-emoji {{ font-size: 180px; line-height: 1.2; margin-bottom: 50px; }}
|
|
337
|
+
.cover-title {{
|
|
338
|
+
font-weight: 900; font-size: 130px; line-height: 1.4;
|
|
339
|
+
background: {title_gradient};
|
|
340
|
+
-webkit-background-clip: text;
|
|
341
|
+
-webkit-text-fill-color: transparent;
|
|
342
|
+
background-clip: text;
|
|
343
|
+
flex: 1;
|
|
344
|
+
display: flex; align-items: flex-start;
|
|
345
|
+
word-break: break-all;
|
|
346
|
+
}}
|
|
347
|
+
.cover-subtitle {{
|
|
348
|
+
font-weight: 350; font-size: 72px; line-height: 1.4;
|
|
349
|
+
color: {text_color};
|
|
350
|
+
margin-top: auto;
|
|
351
|
+
}}
|
|
352
|
+
</style>
|
|
353
|
+
</head>
|
|
354
|
+
<body>
|
|
355
|
+
<div class="cover-container">
|
|
356
|
+
<div class="cover-inner">
|
|
357
|
+
<div class="cover-emoji">{emoji}</div>
|
|
358
|
+
<div class="cover-title">{title}</div>
|
|
359
|
+
<div class="cover-subtitle">{subtitle}</div>
|
|
360
|
+
</div>
|
|
361
|
+
</div>
|
|
362
|
+
</body>
|
|
363
|
+
</html>'''
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def generate_card_html(content: str, page_number: int = 1, total_pages: int = 1,
|
|
367
|
+
style_key: str = "purple") -> str:
|
|
368
|
+
"""生成正文卡片 HTML"""
|
|
369
|
+
style = STYLES.get(style_key, STYLES["purple"])
|
|
370
|
+
html_content = convert_markdown_to_html(content, style)
|
|
371
|
+
page_text = f"{page_number}/{total_pages}" if total_pages > 1 else ""
|
|
372
|
+
|
|
373
|
+
# 暗黑模式特殊处理
|
|
374
|
+
is_dark = style_key == "dark"
|
|
375
|
+
card_bg = "rgba(30, 30, 46, 0.95)" if is_dark else "rgba(255, 255, 255, 0.95)"
|
|
376
|
+
text_color = "#e0e0e0" if is_dark else "#475569"
|
|
377
|
+
heading_color = "#ffffff" if is_dark else "#1e293b"
|
|
378
|
+
h2_color = "#e0e0e0" if is_dark else "#334155"
|
|
379
|
+
h3_color = "#c0c0c0" if is_dark else "#475569"
|
|
380
|
+
code_bg = "#0f0f23" if is_dark else "#1e293b"
|
|
381
|
+
pre_bg = "#0f0f23" if is_dark else "#1e293b"
|
|
382
|
+
blockquote_bg = "#252540" if is_dark else "#f1f5f9"
|
|
383
|
+
blockquote_border = style['accent_color']
|
|
384
|
+
blockquote_color = "#a0a0a0" if is_dark else "#64748b"
|
|
385
|
+
|
|
386
|
+
return f'''<!DOCTYPE html>
|
|
387
|
+
<html lang="zh-CN">
|
|
388
|
+
<head>
|
|
389
|
+
<meta charset="UTF-8">
|
|
390
|
+
<meta name="viewport" content="width=1080">
|
|
391
|
+
<title>小红书卡片</title>
|
|
392
|
+
<style>
|
|
393
|
+
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap');
|
|
394
|
+
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
|
395
|
+
body {{
|
|
396
|
+
font-family: 'Noto Sans SC', 'Source Han Sans CN', 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
397
|
+
width: 1080px; min-height: 1440px; overflow: hidden; background: transparent;
|
|
398
|
+
}}
|
|
399
|
+
.card-container {{
|
|
400
|
+
width: 1080px; min-height: 1440px;
|
|
401
|
+
background: {style['card_bg']};
|
|
402
|
+
position: relative; padding: 50px; overflow: hidden;
|
|
403
|
+
}}
|
|
404
|
+
.card-inner {{
|
|
405
|
+
background: {card_bg};
|
|
406
|
+
border-radius: 20px;
|
|
407
|
+
padding: 60px;
|
|
408
|
+
min-height: calc(1440px - 100px);
|
|
409
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
410
|
+
backdrop-filter: blur(10px);
|
|
411
|
+
}}
|
|
412
|
+
.card-content {{
|
|
413
|
+
color: {text_color};
|
|
414
|
+
font-size: 42px;
|
|
415
|
+
line-height: 1.7;
|
|
416
|
+
}}
|
|
417
|
+
.card-content h1 {{
|
|
418
|
+
font-size: 72px; font-weight: 700; color: {heading_color};
|
|
419
|
+
margin-bottom: 40px; line-height: 1.3;
|
|
420
|
+
}}
|
|
421
|
+
.card-content h2 {{
|
|
422
|
+
font-size: 56px; font-weight: 600; color: {h2_color};
|
|
423
|
+
margin: 50px 0 25px 0; line-height: 1.4;
|
|
424
|
+
}}
|
|
425
|
+
.card-content h3 {{
|
|
426
|
+
font-size: 48px; font-weight: 600; color: {h3_color};
|
|
427
|
+
margin: 40px 0 20px 0;
|
|
428
|
+
}}
|
|
429
|
+
.card-content p {{ margin-bottom: 35px; }}
|
|
430
|
+
.card-content strong {{ font-weight: 700; color: {heading_color}; }}
|
|
431
|
+
.card-content em {{ font-style: italic; color: {style['accent_color']}; }}
|
|
432
|
+
.card-content a {{
|
|
433
|
+
color: {style['accent_color']}; text-decoration: none;
|
|
434
|
+
border-bottom: 2px solid {style['accent_color']};
|
|
435
|
+
}}
|
|
436
|
+
.card-content ul, .card-content ol {{
|
|
437
|
+
margin: 30px 0; padding-left: 60px;
|
|
438
|
+
}}
|
|
439
|
+
.card-content li {{ margin-bottom: 20px; line-height: 1.6; }}
|
|
440
|
+
.card-content blockquote {{
|
|
441
|
+
border-left: 8px solid {blockquote_border};
|
|
442
|
+
padding-left: 40px;
|
|
443
|
+
background: {blockquote_bg};
|
|
444
|
+
padding-top: 25px; padding-bottom: 25px; padding-right: 30px;
|
|
445
|
+
margin: 35px 0;
|
|
446
|
+
color: {blockquote_color};
|
|
447
|
+
font-style: italic;
|
|
448
|
+
border-radius: 0 12px 12px 0;
|
|
449
|
+
}}
|
|
450
|
+
.card-content blockquote p {{ margin: 0; }}
|
|
451
|
+
.card-content code {{
|
|
452
|
+
background: {'#252540' if is_dark else '#f1f5f9'};
|
|
453
|
+
padding: 6px 16px; border-radius: 8px;
|
|
454
|
+
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
|
|
455
|
+
font-size: 38px;
|
|
456
|
+
color: {style['accent_color']};
|
|
457
|
+
}}
|
|
458
|
+
.card-content pre {{
|
|
459
|
+
background: {pre_bg};
|
|
460
|
+
color: {'#e0e0e0' if is_dark else '#e2e8f0'};
|
|
461
|
+
padding: 40px; border-radius: 16px;
|
|
462
|
+
margin: 35px 0;
|
|
463
|
+
overflow-x: visible;
|
|
464
|
+
overflow-wrap: break-word;
|
|
465
|
+
word-wrap: break-word;
|
|
466
|
+
word-break: break-all;
|
|
467
|
+
white-space: pre-wrap;
|
|
468
|
+
font-size: 36px; line-height: 1.5;
|
|
469
|
+
}}
|
|
470
|
+
.card-content pre code {{
|
|
471
|
+
background: transparent; color: inherit; padding: 0; font-size: inherit;
|
|
472
|
+
}}
|
|
473
|
+
.card-content img {{
|
|
474
|
+
max-width: 100%; height: auto; border-radius: 16px;
|
|
475
|
+
margin: 35px auto; display: block;
|
|
476
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
|
477
|
+
}}
|
|
478
|
+
.card-content hr {{
|
|
479
|
+
border: none; height: 2px;
|
|
480
|
+
background: {'#333355' if is_dark else '#e2e8f0'};
|
|
481
|
+
margin: 50px 0;
|
|
482
|
+
}}
|
|
483
|
+
.tags-container {{
|
|
484
|
+
margin-top: 50px; padding-top: 30px;
|
|
485
|
+
border-top: 2px solid {'#333355' if is_dark else '#e2e8f0'};
|
|
486
|
+
}}
|
|
487
|
+
.tag {{
|
|
488
|
+
display: inline-block;
|
|
489
|
+
background: {style['accent_color']};
|
|
490
|
+
color: white;
|
|
491
|
+
padding: 12px 28px; border-radius: 30px;
|
|
492
|
+
font-size: 34px;
|
|
493
|
+
margin: 10px 15px 10px 0;
|
|
494
|
+
font-weight: 500;
|
|
495
|
+
}}
|
|
496
|
+
.page-number {{
|
|
497
|
+
position: absolute;
|
|
498
|
+
bottom: 80px; right: 80px;
|
|
499
|
+
font-size: 36px;
|
|
500
|
+
color: rgba(255, 255, 255, 0.8);
|
|
501
|
+
font-weight: 500;
|
|
502
|
+
}}
|
|
503
|
+
</style>
|
|
504
|
+
</head>
|
|
505
|
+
<body>
|
|
506
|
+
<div class="card-container">
|
|
507
|
+
<div class="card-inner">
|
|
508
|
+
<div class="card-content">
|
|
509
|
+
{html_content}
|
|
510
|
+
</div>
|
|
511
|
+
</div>
|
|
512
|
+
<div class="page-number">{page_text}</div>
|
|
513
|
+
</div>
|
|
514
|
+
</body>
|
|
515
|
+
</html>'''
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
async def measure_content_height(page: Page, html_content: str) -> int:
|
|
519
|
+
"""使用 Playwright 测量实际内容高度"""
|
|
520
|
+
await page.set_content(html_content, wait_until='networkidle')
|
|
521
|
+
await page.wait_for_timeout(300) # 等待字体渲染
|
|
522
|
+
|
|
523
|
+
height = await page.evaluate('''() => {
|
|
524
|
+
const inner = document.querySelector('.card-inner');
|
|
525
|
+
if (inner) {
|
|
526
|
+
return inner.scrollHeight;
|
|
527
|
+
}
|
|
528
|
+
const container = document.querySelector('.card-container');
|
|
529
|
+
return container ? container.scrollHeight : document.body.scrollHeight;
|
|
530
|
+
}''')
|
|
531
|
+
|
|
532
|
+
return height
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
async def render_html_to_image(html_content: str, output_path: str,
|
|
536
|
+
width: int = CARD_WIDTH, height: int = CARD_HEIGHT):
|
|
537
|
+
"""使用 Playwright 将 HTML 渲染为图片"""
|
|
538
|
+
async with async_playwright() as p:
|
|
539
|
+
browser = await p.chromium.launch()
|
|
540
|
+
page = await browser.new_page(viewport={'width': width, 'height': height})
|
|
541
|
+
|
|
542
|
+
try:
|
|
543
|
+
await page.set_content(html_content, wait_until='networkidle')
|
|
544
|
+
await page.wait_for_timeout(300)
|
|
545
|
+
|
|
546
|
+
# 截图固定尺寸
|
|
547
|
+
await page.screenshot(
|
|
548
|
+
path=output_path,
|
|
549
|
+
clip={'x': 0, 'y': 0, 'width': width, 'height': height},
|
|
550
|
+
type='png'
|
|
551
|
+
)
|
|
552
|
+
|
|
553
|
+
print(f" ✅ 已生成: {output_path}")
|
|
554
|
+
|
|
555
|
+
finally:
|
|
556
|
+
await browser.close()
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
async def process_and_render_cards(card_contents: List[str], output_dir: str,
|
|
560
|
+
style_key: str) -> List[str]:
|
|
561
|
+
"""
|
|
562
|
+
处理卡片内容,检测高度并自动分页,然后渲染
|
|
563
|
+
返回最终生成的所有卡片文件路径
|
|
564
|
+
"""
|
|
565
|
+
async with async_playwright() as p:
|
|
566
|
+
browser = await p.chromium.launch()
|
|
567
|
+
page = await browser.new_page(viewport={'width': CARD_WIDTH, 'height': CARD_HEIGHT})
|
|
568
|
+
|
|
569
|
+
all_cards = []
|
|
570
|
+
|
|
571
|
+
try:
|
|
572
|
+
for content in card_contents:
|
|
573
|
+
# 预估内容高度
|
|
574
|
+
estimated_height = estimate_content_height(content)
|
|
575
|
+
|
|
576
|
+
# 如果预估高度超过安全高度,尝试拆分
|
|
577
|
+
if estimated_height > SAFE_HEIGHT:
|
|
578
|
+
split_contents = smart_split_content(content, SAFE_HEIGHT)
|
|
579
|
+
else:
|
|
580
|
+
split_contents = [content]
|
|
581
|
+
|
|
582
|
+
# 验证每个拆分后的内容
|
|
583
|
+
for split_content in split_contents:
|
|
584
|
+
# 生成临时 HTML 测量
|
|
585
|
+
temp_html = generate_card_html(split_content, 1, 1, style_key)
|
|
586
|
+
actual_height = await measure_content_height(page, temp_html)
|
|
587
|
+
|
|
588
|
+
# 如果仍然超出,进一步按行拆分
|
|
589
|
+
if actual_height > CARD_HEIGHT - 100:
|
|
590
|
+
lines = split_content.split('\n')
|
|
591
|
+
sub_contents = []
|
|
592
|
+
sub_lines = []
|
|
593
|
+
sub_height = 0
|
|
594
|
+
|
|
595
|
+
for line in lines:
|
|
596
|
+
test_lines = sub_lines + [line]
|
|
597
|
+
test_html = generate_card_html('\n'.join(test_lines), 1, 1, style_key)
|
|
598
|
+
test_height = await measure_content_height(page, test_html)
|
|
599
|
+
|
|
600
|
+
if test_height > CARD_HEIGHT - 100 and sub_lines:
|
|
601
|
+
sub_contents.append('\n'.join(sub_lines))
|
|
602
|
+
sub_lines = [line]
|
|
603
|
+
else:
|
|
604
|
+
sub_lines = test_lines
|
|
605
|
+
|
|
606
|
+
if sub_lines:
|
|
607
|
+
sub_contents.append('\n'.join(sub_lines))
|
|
608
|
+
|
|
609
|
+
all_cards.extend(sub_contents)
|
|
610
|
+
else:
|
|
611
|
+
all_cards.append(split_content)
|
|
612
|
+
|
|
613
|
+
finally:
|
|
614
|
+
await browser.close()
|
|
615
|
+
|
|
616
|
+
return all_cards
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
async def render_markdown_to_cards(md_file: str, output_dir: str, style_key: str = "purple"):
|
|
620
|
+
"""主渲染函数:将 Markdown 文件渲染为多张卡片图片"""
|
|
621
|
+
print(f"\n🎨 开始渲染: {md_file}")
|
|
622
|
+
print(f"🎨 使用样式: {STYLES[style_key]['name']}")
|
|
623
|
+
|
|
624
|
+
# 确保输出目录存在
|
|
625
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
626
|
+
|
|
627
|
+
# 解析 Markdown 文件
|
|
628
|
+
data = parse_markdown_file(md_file)
|
|
629
|
+
metadata = data['metadata']
|
|
630
|
+
body = data['body']
|
|
631
|
+
|
|
632
|
+
# 分割正文内容(基于用户手动分隔符)
|
|
633
|
+
card_contents = split_content_by_separator(body)
|
|
634
|
+
print(f" 📄 检测到 {len(card_contents)} 个内容块")
|
|
635
|
+
|
|
636
|
+
# 处理内容,智能分页
|
|
637
|
+
print(" 🔍 分析内容高度并智能分页...")
|
|
638
|
+
processed_cards = await process_and_render_cards(card_contents, output_dir, style_key)
|
|
639
|
+
total_cards = len(processed_cards)
|
|
640
|
+
print(f" 📄 将生成 {total_cards} 张卡片")
|
|
641
|
+
|
|
642
|
+
# 生成封面
|
|
643
|
+
if metadata.get('emoji') or metadata.get('title'):
|
|
644
|
+
print(" 📷 生成封面...")
|
|
645
|
+
cover_html = generate_cover_html(metadata, style_key)
|
|
646
|
+
cover_path = os.path.join(output_dir, 'cover.png')
|
|
647
|
+
await render_html_to_image(cover_html, cover_path)
|
|
648
|
+
|
|
649
|
+
# 生成正文卡片
|
|
650
|
+
async with async_playwright() as p:
|
|
651
|
+
browser = await p.chromium.launch()
|
|
652
|
+
page = await browser.new_page(viewport={'width': CARD_WIDTH, 'height': CARD_HEIGHT})
|
|
653
|
+
|
|
654
|
+
try:
|
|
655
|
+
for i, content in enumerate(processed_cards, 1):
|
|
656
|
+
print(f" 📷 生成卡片 {i}/{total_cards}...")
|
|
657
|
+
card_html = generate_card_html(content, i, total_cards, style_key)
|
|
658
|
+
card_path = os.path.join(output_dir, f'card_{i}.png')
|
|
659
|
+
|
|
660
|
+
await page.set_content(card_html, wait_until='networkidle')
|
|
661
|
+
await page.wait_for_timeout(300)
|
|
662
|
+
|
|
663
|
+
await page.screenshot(
|
|
664
|
+
path=card_path,
|
|
665
|
+
clip={'x': 0, 'y': 0, 'width': CARD_WIDTH, 'height': CARD_HEIGHT},
|
|
666
|
+
type='png'
|
|
667
|
+
)
|
|
668
|
+
print(f" ✅ 已生成: {card_path}")
|
|
669
|
+
|
|
670
|
+
finally:
|
|
671
|
+
await browser.close()
|
|
672
|
+
|
|
673
|
+
print(f"\n✨ 渲染完成!共生成 {total_cards} 张卡片,保存到: {output_dir}")
|
|
674
|
+
return total_cards
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
def list_styles():
|
|
678
|
+
"""列出所有可用样式"""
|
|
679
|
+
print("\n📋 可用样式列表:")
|
|
680
|
+
print("-" * 40)
|
|
681
|
+
for key, style in STYLES.items():
|
|
682
|
+
print(f" {key:12} - {style['name']}")
|
|
683
|
+
print("-" * 40)
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def main():
|
|
687
|
+
parser = argparse.ArgumentParser(
|
|
688
|
+
description='将 Markdown 文件渲染为小红书风格的图片卡片(智能分页版)',
|
|
689
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
690
|
+
epilog='''
|
|
691
|
+
示例:
|
|
692
|
+
python render_xhs_v2.py note.md
|
|
693
|
+
python render_xhs_v2.py note.md -o ./output --style xiaohongshu
|
|
694
|
+
python render_xhs_v2.py --list-styles
|
|
695
|
+
'''
|
|
696
|
+
)
|
|
697
|
+
parser.add_argument(
|
|
698
|
+
'markdown_file',
|
|
699
|
+
nargs='?',
|
|
700
|
+
help='Markdown 文件路径'
|
|
701
|
+
)
|
|
702
|
+
parser.add_argument(
|
|
703
|
+
'--output-dir', '-o',
|
|
704
|
+
default=os.getcwd(),
|
|
705
|
+
help='输出目录(默认为当前工作目录)'
|
|
706
|
+
)
|
|
707
|
+
parser.add_argument(
|
|
708
|
+
'--style', '-s',
|
|
709
|
+
default='purple',
|
|
710
|
+
choices=list(STYLES.keys()),
|
|
711
|
+
help='样式主题(默认: purple)'
|
|
712
|
+
)
|
|
713
|
+
parser.add_argument(
|
|
714
|
+
'--list-styles',
|
|
715
|
+
action='store_true',
|
|
716
|
+
help='列出所有可用样式'
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
args = parser.parse_args()
|
|
720
|
+
|
|
721
|
+
if args.list_styles:
|
|
722
|
+
list_styles()
|
|
723
|
+
return
|
|
724
|
+
|
|
725
|
+
if not args.markdown_file:
|
|
726
|
+
parser.print_help()
|
|
727
|
+
sys.exit(1)
|
|
728
|
+
|
|
729
|
+
if not os.path.exists(args.markdown_file):
|
|
730
|
+
print(f"❌ 错误: 文件不存在 - {args.markdown_file}")
|
|
731
|
+
sys.exit(1)
|
|
732
|
+
|
|
733
|
+
asyncio.run(render_markdown_to_cards(args.markdown_file, args.output_dir, args.style))
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
if __name__ == '__main__':
|
|
737
|
+
main()
|