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>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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("");
|
||||
});
|
||||
|
||||
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(
|
||||
"",
|
||||
);
|
||||
expect(result).not.toContain("<img");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user