Skip to content

fix: improve CSDN sync formatting - #231

Open
Jennifer-ra wants to merge 2 commits into
wechatsync:v2from
Jennifer-ra:codex/fix-csdn-sync-format
Open

fix: improve CSDN sync formatting#231
Jennifer-ra wants to merge 2 commits into
wechatsync:v2from
Jennifer-ra:codex/fix-csdn-sync-format

Conversation

@Jennifer-ra

Copy link
Copy Markdown

Background

When syncing articles from CSDN browser pages to Zhihu, Juejin and WeChat Official Account, several formatting issues appeared even though the original CSDN page rendered correctly:

  • Code block languages were lost or normalized incorrectly.
  • Juejin code blocks without a detected language became bash.
  • WeChat imported CSDN TOC/list structures with wrong order, empty list items, lost indentation, extra line breaks, inconsistent font sizes, and collapsed code line breaks.
  • Juejin draft cover and summary were not populated.

Root Cause

CSDN-rendered HTML is display-friendly but not always editor-friendly. Some TOC/list structures contain nested or adjacent list markup that rich-text editors reinterpret differently. WeChat editor also sanitizes list styles and treats simple p/div/br blocks inside list items as separate paragraphs, which can create extra line breaks or flatten indentation during import.

Changes

  • Preserve code block language from pre/code attributes and class names.
  • Stop defaulting unknown fenced code language to bash.
  • Add CSDN-specific extraction selectors and cleanup rules.
  • Add list normalization for platform preprocessing.
  • For WeChat:
    • Normalize list structures.
    • Convert CSDN TOC nested lists into stable single-level list items.
    • Preserve TOC visual indentation with text-level full-width spacing instead of editor-sanitized CSS indentation.
    • Flatten simple p/div/section/br wrappers inside list items.
    • Add stable font sizing for list and table content.
    • Normalize code blocks into line-preserving rich-text-friendly markup.
    • Use extension runtime fetch when downloading remote images before upload.
  • For Zhihu:
    • Preserve code block language attributes.
    • Add list normalization.
    • Preserve blockquote semantics for Draft.js.
  • For Juejin:
    • Upload and set draft cover image when available.
    • Fill brief_content from extracted article summary.
  • Add tests for code language preservation and unknown-language handling.

Verification

  • pnpm --filter @wechatsync/core typecheck
  • pnpm --filter @wechatsync/extension typecheck
  • pnpm --filter @wechatsync/core test -- --run
  • pnpm --filter @wechatsync/extension build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant