From 1afa6f5a5813f3ee4b6a808bcf59b66e22da3b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Sun, 25 Jan 2026 21:05:08 -0600 Subject: [PATCH] refactor(baoyu-post-to-x): simplify image placeholders from bracket format to XIMGPH --- skills/baoyu-post-to-x/references/articles.md | 4 ++-- skills/baoyu-post-to-x/scripts/md-to-html.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/skills/baoyu-post-to-x/references/articles.md b/skills/baoyu-post-to-x/references/articles.md index 36bbcfc..bca7d03 100644 --- a/skills/baoyu-post-to-x/references/articles.md +++ b/skills/baoyu-post-to-x/references/articles.md @@ -67,7 +67,7 @@ Code blocks become blockquotes (X doesn't support code) 1. **Cover Image**: First image or `cover_image` from frontmatter 2. **Remote Images**: Automatically downloaded to temp directory -3. **Placeholders**: Images in content use `[[IMAGE_PLACEHOLDER_N]]` format +3. **Placeholders**: Images in content use `XIMGPH_N` format 4. **Insertion**: Placeholders are found, selected, and replaced with actual images ## Markdown to HTML Script @@ -92,7 +92,7 @@ JSON output: "coverImage": "/path/to/cover.jpg", "contentImages": [ { - "placeholder": "[[IMAGE_PLACEHOLDER_1]]", + "placeholder": "XIMGPH_1", "localPath": "/tmp/x-article-images/img.png", "blockIndex": 5 } diff --git a/skills/baoyu-post-to-x/scripts/md-to-html.ts b/skills/baoyu-post-to-x/scripts/md-to-html.ts index cea0fc8..9e6e8da 100644 --- a/skills/baoyu-post-to-x/scripts/md-to-html.ts +++ b/skills/baoyu-post-to-x/scripts/md-to-html.ts @@ -280,7 +280,7 @@ export async function parseMarkdown( let imageCounter = 0; const { html, totalBlocks } = convertMarkdownToHtml(body, (src, alt) => { - const placeholder = `[[IMAGE_PLACEHOLDER_${++imageCounter}]]`; + const placeholder = `XIMGPH_${++imageCounter}`; const currentBlockIndex = images.length; // Will be set properly after HTML generation images.push({ src, alt, blockIndex: -1 }); // blockIndex set later @@ -292,7 +292,7 @@ export async function parseMarkdown( let blockIdx = 0; for (const line of htmlLines) { for (let i = 0; i < images.length; i++) { - const placeholder = `[[IMAGE_PLACEHOLDER_${i + 1}]]`; + const placeholder = `XIMGPH_${i + 1}`; if (line.includes(placeholder)) { images[i]!.blockIndex = blockIdx; } @@ -312,7 +312,7 @@ export async function parseMarkdown( // First image becomes cover if no cover specified if (isFirstImage && !coverImagePath) { coverImagePath = localPath; - coverPlaceholder = `[[IMAGE_PLACEHOLDER_${i + 1}]]`; + coverPlaceholder = `XIMGPH_${i + 1}`; isFirstImage = false; // Don't add to contentImages, it's the cover continue; @@ -320,7 +320,7 @@ export async function parseMarkdown( isFirstImage = false; contentImages.push({ - placeholder: `[[IMAGE_PLACEHOLDER_${i + 1}]]`, + placeholder: `XIMGPH_${i + 1}`, localPath, originalPath: img.src, blockIndex: img.blockIndex, @@ -331,7 +331,7 @@ export async function parseMarkdown( let finalHtml = html; if (coverPlaceholder) { // Remove the placeholder and its containing

tag - finalHtml = finalHtml.replace(new RegExp(`

${coverPlaceholder.replace(/[[\]]/g, '\\$&')}

\\n?`, 'g'), ''); + finalHtml = finalHtml.replace(new RegExp(`

${coverPlaceholder}

\\n?`, 'g'), ''); } // Resolve cover image path