Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Convert X (Twitter) tweets, threads, and articles to Markdown with YAML front matter via reverse-engineered API.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/markdown.test.ts
1import assert from "node:assert/strict";2import test from "node:test";34import { formatArticleMarkdown } from "./markdown.js";56test("formatArticleMarkdown renders MARKDOWN entities from atomic blocks", () => {7const article = {8title: "Atomic Markdown Example",9content_state: {10blocks: [11{12type: "unstyled",13text: "Before the snippet.",14entityRanges: [],15},16{17type: "atomic",18text: " ",19entityRanges: [{ key: 0, offset: 0, length: 1 }],20},21{22type: "unstyled",23text: "After the snippet.",24entityRanges: [],25},26],27entityMap: {28"0": {29key: "5",30value: {31type: "MARKDOWN",32mutability: "Mutable",33data: {34markdown: "```python\nprint('hello from x article')\n```\n",35},36},37},38},39},40};4142const { markdown } = formatArticleMarkdown(article);4344assert.ok(markdown.includes("Before the snippet."));45assert.ok(markdown.includes("```python\nprint('hello from x article')\n```"));46assert.ok(markdown.includes("After the snippet."));47assert.strictEqual(markdown, `# Atomic Markdown Example4849Before the snippet.5051\`\`\`python52print('hello from x article')53\`\`\`5455After the snippet.`);56});5758test("formatArticleMarkdown renders article video media as poster plus video link", () => {59const posterUrl = "https://pbs.twimg.com/amplify_video_thumb/123/img/poster.jpg";60const videoUrl = "https://video.twimg.com/amplify_video/123/vid/avc1/720x720/demo.mp4?tag=21";61const article = {62title: "Video Example",63content_state: {64blocks: [65{66type: "unstyled",67text: "Intro text.",68entityRanges: [],69},70{71type: "atomic",72text: " ",73entityRanges: [{ key: 0, offset: 0, length: 1 }],74},75],76entityMap: {77"0": {78key: "0",79value: {80type: "MEDIA",81mutability: "Immutable",82data: {83caption: "Demo reel",84mediaItems: [{ mediaId: "vid-1" }],85},86},87},88},89},90media_entities: [91{92media_id: "vid-1",93media_info: {94__typename: "ApiVideo",95preview_image: {96original_img_url: posterUrl,97},98variants: [99{100content_type: "video/mp4",101bit_rate: 256000,102url: videoUrl,103},104],105},106},107],108};109110const { markdown } = formatArticleMarkdown(article);111112assert.ok(markdown.includes("Intro text."));113assert.ok(markdown.includes(``));114assert.ok(markdown.includes(`[video](${videoUrl})`));115assert.ok(!markdown.includes(``));116assert.ok(!markdown.includes("## Media"));117});118119test("formatArticleMarkdown renders unused article videos in trailing media section", () => {120const posterUrl = "https://pbs.twimg.com/amplify_video_thumb/456/img/poster.jpg";121const videoUrl = "https://video.twimg.com/amplify_video/456/vid/avc1/1080x1080/demo.mp4?tag=21";122const article = {123title: "Trailing Media Example",124plain_text: "Body text.",125media_entities: [126{127media_id: "vid-2",128media_info: {129__typename: "ApiVideo",130preview_image: {131original_img_url: posterUrl,132},133variants: [134{135content_type: "video/mp4",136bit_rate: 832000,137url: videoUrl,138},139],140},141},142],143};144145const { markdown, coverUrl } = formatArticleMarkdown(article);146147assert.strictEqual(coverUrl, null);148assert.ok(markdown.includes("## Media"));149assert.ok(markdown.includes(``));150assert.ok(markdown.includes(`[video](${videoUrl})`));151});152153test("formatArticleMarkdown keeps coverUrl as preview image for video cover media", () => {154const posterUrl = "https://pbs.twimg.com/amplify_video_thumb/789/img/poster.jpg";155const videoUrl = "https://video.twimg.com/amplify_video/789/vid/avc1/720x720/demo.mp4?tag=21";156const article = {157title: "Video Cover Example",158plain_text: "Body text.",159cover_media: {160media_info: {161__typename: "ApiVideo",162preview_image: {163original_img_url: posterUrl,164},165variants: [166{167content_type: "video/mp4",168bit_rate: 1280000,169url: videoUrl,170},171],172},173},174};175176const { coverUrl } = formatArticleMarkdown(article);177178assert.strictEqual(coverUrl, posterUrl);179});180