Files
geo/apps/desktop-client/src/main/adapters/jianshu.test.ts
T
root dbce8515e7 feat(publish): render jianshu html images as markdown
Jianshu's HTML editor strips uploaded <img> tags during save, so previously
uploaded images vanished from the rendered article. After image upload,
convert each <img> (and surrounding <p> wrappers) to a markdown image block
in both the desktop and extension publish paths so the references survive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 11:02:50 +08:00

26 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { renderJianshuHtmlImagesAsMarkdown } from "../../../../../packages/publisher-platforms/src/jianshu";
describe("jianshu article content", () => {
it("converts editor image paragraphs to markdown image syntax", () => {
const result = renderJianshuHtmlImagesAsMarkdown(
'<p class="article-editor-image article-editor-image--center" align="center"><img src="https://upload-images.jianshu.io/upload_images/2370478-707abbd68000b249.png" alt="" width="365" height="521" data-asset-id="14" /></p>',
);
expect(result).toBe("![](https://upload-images.jianshu.io/upload_images/2370478-707abbd68000b249.png)");
});
it("keeps normal text while replacing raw image tags", () => {
const result = renderJianshuHtmlImagesAsMarkdown(
'<p>正文段落</p><img src="https://upload-images.jianshu.io/upload_images/2370478-0e05fd986e33dae9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="微信图片_2026-04-18_141100_730.jpg">',
);
expect(result).toContain("<p>正文段落</p>");
expect(result).toContain(
"![微信图片_2026-04-18_141100_730.jpg](https://upload-images.jianshu.io/upload_images/2370478-0e05fd986e33dae9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)",
);
expect(result).not.toContain("<img");
});
});