Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Post text, images, videos, and long-form articles to X (Twitter) via real Chrome browser automation.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/md-to-html.test.ts
1import assert from 'node:assert/strict';2import fs from 'node:fs/promises';3import os from 'node:os';4import path from 'node:path';5import test from 'node:test';67import { parseMarkdown } from './md-to-html.ts';89async function makeTempDir(prefix: string): Promise<string> {10return fs.mkdtemp(path.join(os.tmpdir(), prefix));11}1213test('parseMarkdown preserves mixed markdown and Obsidian wikilink image order', async (t) => {14const root = await makeTempDir('x-md-to-html-wikilinks-');15t.after(() => fs.rm(root, { recursive: true, force: true }));1617const articleDir = path.join(root, 'article');18const attachmentsDir = path.join(articleDir, 'Attachments');19const tempDir = path.join(root, 'tmp');20await fs.mkdir(attachmentsDir, { recursive: true });21await fs.mkdir(tempDir, { recursive: true });22await fs.writeFile(path.join(articleDir, 'a.png'), 'a');23await fs.writeFile(path.join(articleDir, 'b.jpg'), 'b');24await fs.writeFile(path.join(attachmentsDir, 'c.webp'), 'c');2526const markdownPath = path.join(articleDir, 'post.md');27await fs.writeFile(28markdownPath,29[30'# Title',31'',32'![[a.png]]',33'',34'',35'',36'![[c.webp|C alt]]',37'',38'![[note]]',39].join('\n'),40);4142const result = await parseMarkdown(markdownPath, { tempDir });4344assert.deepEqual(45result.contentImages.map(({ placeholder, originalPath, alt, localPath }) => ({46placeholder,47originalPath,48alt,49localPath,50})),51[52{53placeholder: 'XIMGPH_1',54originalPath: 'a.png',55alt: '',56localPath: path.join(articleDir, 'a.png'),57},58{59placeholder: 'XIMGPH_2',60originalPath: 'b.jpg',61alt: 'B alt',62localPath: path.join(articleDir, 'b.jpg'),63},64{65placeholder: 'XIMGPH_3',66originalPath: 'c.webp',67alt: 'C alt',68localPath: path.join(attachmentsDir, 'c.webp'),69},70],71);72assert.match(result.html, /XIMGPH_1[\s\S]*XIMGPH_2[\s\S]*XIMGPH_3/);73assert.match(result.html, /!\[\[note\]\]/);74});7576test('parseMarkdown resolves encoded spaces and literal percent image paths', async (t) => {77const root = await makeTempDir('baoyu-post-to-x-images-');78t.after(() => fs.rm(root, { recursive: true, force: true }));7980const articlePath = path.join(root, 'article.md');81const tempDir = path.join(root, 'tmp');82await fs.mkdir(tempDir, { recursive: true });83await fs.writeFile(path.join(root, 'Pasted image.png'), 'png');84await fs.writeFile(path.join(root, '100%.png'), 'png');85await fs.writeFile(86articlePath,87[88'# Title',89'',90'',91'',92'',93].join('\n'),94);9596const result = await parseMarkdown(articlePath, { tempDir });9798assert.equal(result.contentImages[0]?.localPath, path.join(root, 'Pasted image.png'));99assert.equal(result.contentImages[1]?.localPath, path.join(root, '100%.png'));100});101