X Articles - Detailed Guide

Publish Markdown articles to X Articles editor with rich text formatting and images.

Prerequisites

  • X Premium subscription (required for Articles)

  • Google Chrome installed

  • bun installed

Usage

# Publish markdown article (preview mode)
npx -y bun ${SKILL_DIR}/scripts/x-article.ts article.md

# With custom cover image
npx -y bun ${SKILL_DIR}/scripts/x-article.ts article.md --cover ./cover.jpg

# Actually publish
npx -y bun ${SKILL_DIR}/scripts/x-article.ts article.md --submit

Markdown Format

---
title: My Article Title
cover_image: /path/to/cover.jpg
---

# Title (becomes article title)

Regular paragraph text with **bold** and *italic*.

## Section Header

More content here.

![Image alt text](./image.png)

- List item 1
- List item 2

1. Numbered item
2. Another item

> Blockquote text

[Link text](https://example.com)

\`\`\`
Code blocks become blockquotes (X doesn't support code)
\`\`\`

Frontmatter Fields

Field
Description

title

Article title (or uses first H1)

cover_image

Cover image path or URL

cover

Alias for cover_image

image

Alias for cover_image

Image Handling

  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

  4. Insertion: Placeholders are found, selected, and replaced with actual images

Markdown to HTML Script

Convert markdown and inspect structure:

JSON output:

Supported Formatting

Markdown
HTML Output

# H1

Title only (not in body)

## H2 - ###### H6

<h2>

**bold**

<strong>

*italic*

<em>

[text](url)

<a href>

> quote

<blockquote>

`code`

<code>

```

<blockquote> (X limitation)

- item

<ul><li>

1. item

<ol><li>

![](img)

Image placeholder

Workflow

  1. Parse Markdown: Extract title, cover, content images, generate HTML

  2. Launch Chrome: Real browser with CDP, persistent login

  3. Navigate: Open x.com/compose/articles

  4. Create Article: Click create button if on list page

  5. Upload Cover: Use file input for cover image

  6. Fill Title: Type title into title field

  7. Paste Content: Copy HTML to clipboard, paste into editor

  8. Insert Images: For each placeholder (reverse order):

    • Find placeholder text in editor

    • Select the placeholder

    • Copy image to clipboard

    • Paste to replace selection

  9. Review: Browser stays open for 60s preview

  10. Publish: Only with --submit flag

Example Session

Troubleshooting

  • No create button: Ensure X Premium subscription is active

  • Cover upload fails: Check file path and format (PNG, JPEG)

  • Images not inserting: Verify placeholders exist in pasted content

  • Content not pasting: Check HTML clipboard: npx -y bun ${SKILL_DIR}/scripts/copy-to-clipboard.ts html --file /tmp/test.html

How It Works

  1. md-to-html.ts converts Markdown to HTML:

    • Extracts frontmatter (title, cover)

    • Converts markdown to HTML

    • Replaces images with unique placeholders

    • Downloads remote images locally

    • Returns structured JSON

  2. x-article.ts publishes via CDP:

    • Launches real Chrome (bypasses detection)

    • Uses persistent profile (saved login)

    • Navigates and fills editor via DOM manipulation

    • Pastes HTML from system clipboard

    • Finds/selects/replaces each image placeholder

Last updated