# Code Converter Toolkit (`moving_beacon-owner1/my-actor-64`) Actor

A universal code conversion actor that transforms between 6 popular code formats in a single run. Supports both single and batch conversions with structured JSON output.

- **URL**: https://apify.com/moving\_beacon-owner1/my-actor-64.md
- **Developed by:** [Jamshaid Arif](https://apify.com/moving_beacon-owner1) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## 🔄 Code Converter Toolkit — Apify Actor

A universal code conversion actor that transforms between **6 popular code formats** in a single run. Supports both single and batch conversions with structured JSON output.

***

### Supported Conversions

| # | From | To | Key |
|---|------|----|-----|
| 1 | HTML | Markdown | `html_to_markdown` |
| 2 | Markdown | HTML | `markdown_to_html` |
| 3 | CSS | Tailwind Classes | `css_to_tailwind` |
| 4 | SQL DDL | ORM Models (Python + JS) | `sql_to_orm` |
| 5 | JSON | TypeScript Interfaces | `json_to_typescript` |
| 6 | JSON | Python Dataclasses | `json_to_dataclass` |

***

### Input Schema

#### Single Conversion (Default)

```json
{
    "conversion_type": "html_to_markdown",
    "source_code": "<h1>Hello</h1><p>World</p>",
    "root_class_name": "Root",
    "orm_target": "both"
}
```

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `conversion_type` | string (enum) | ✅ | `"html_to_markdown"` | Which conversion to run |
| `source_code` | string | ✅ | *(HTML demo)* | The source code to convert |
| `root_class_name` | string | ❌ | `"Root"` | Class/interface name (JSON converters only) |
| `orm_target` | string (enum) | ❌ | `"both"` | `"both"` / `"sqlalchemy"` / `"sequelize"` |

#### Batch Conversion

Provide `batch_conversions` to run multiple conversions in one actor call.\
When batch is provided, the single-mode fields are **ignored**.

```json
{
    "batch_conversions": [
        {
            "conversion_type": "html_to_markdown",
            "source_code": "<h1>Title</h1><p>Paragraph</p>"
        },
        {
            "conversion_type": "json_to_typescript",
            "source_code": "{\"name\": \"Alice\", \"age\": 30}",
            "root_class_name": "User"
        },
        {
            "conversion_type": "css_to_tailwind",
            "source_code": ".box { display: flex; padding: 1rem; gap: 0.5rem; }"
        },
        {
            "conversion_type": "sql_to_orm",
            "source_code": "CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL);",
            "orm_target": "sqlalchemy"
        }
    ]
}
```

***

### Output

Each conversion produces a structured result in the **default dataset**:

```json
{
    "index": 0,
    "conversion_type": "html_to_markdown",
    "label": "HTML → Markdown",
    "input_lang": "html",
    "output_lang": "markdown",
    "source_code": "<h1>Hello</h1>...",
    "converted_output": "# Hello\n\n...",
    "success": true,
    "error": null,
    "timestamp": "2025-01-15T12:00:00+00:00"
}
```

Additionally:

- **Key-Value Store → `RUN_SUMMARY`**: Aggregated stats (total, success, fail counts)
- **Key-Value Store → `OUTPUT_0_html_to_markdown.md`**: Individual output files with correct extensions

***

### Conversion Details

#### 1. HTML → Markdown

Converts semantic HTML into clean Markdown. Handles headings, bold/italic, links, images, code blocks, blockquotes, ordered/unordered lists, horizontal rules, and GFM-style tables.

#### 2. Markdown → HTML

Parses Markdown syntax into semantic HTML5. Supports headings, inline formatting, fenced code blocks with language hints, blockquotes, lists, pipe tables, links, images, and horizontal rules.

#### 3. CSS → Tailwind Classes

Maps 50+ CSS properties to Tailwind utility classes including display, position, flexbox, grid, spacing (margin/padding), typography, colors, borders, shadows, transforms, and more. Uses Tailwind's arbitrary value syntax `[value]` for unmapped values.

#### 4. SQL → ORM Models

Parses `CREATE TABLE` DDL statements and generates:

- **Python SQLAlchemy** ORM model classes
- **JavaScript Sequelize** model definitions

Supports: INT, VARCHAR, TEXT, BOOLEAN, TIMESTAMP, SERIAL, JSON, UUID, BLOB, etc.\
Constraints: PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, REFERENCES (foreign keys).

#### 5. JSON → TypeScript Interfaces

Recursively infers TypeScript `export interface` definitions from JSON objects/arrays. Detects nested objects, arrays of objects (with singular naming), union types for mixed arrays, and optional fields for null values.

#### 6. JSON → Python Dataclass

Generates Python `@dataclass` definitions with:

- Recursive nested class generation
- `Optional[]` typing for nullable fields
- `from_dict()` classmethod with nested object reconstruction
- `to_dict()` method (via `dataclasses.asdict`)
- `from_json()` classmethod for direct string deserialization

***

### Running Locally

```bash
## Install the Apify CLI
npm install -g apify-cli

## Navigate to the actor directory
cd apify-actor

## Create local storage
apify init

## Run with default input
apify run

## Run with custom input
apify run --input='{"conversion_type":"css_to_tailwind","source_code":".card{display:flex;padding:1rem;}"}'
```

***

### Example Inputs by Type

#### HTML → Markdown

```json
{
    "conversion_type": "html_to_markdown",
    "source_code": "<h1>Blog Post</h1><p>Hello <strong>world</strong>!</p><ul><li>Item 1</li><li>Item 2</li></ul>"
}
```

#### CSS → Tailwind

```json
{
    "conversion_type": "css_to_tailwind",
    "source_code": ".container { display: flex; flex-direction: column; align-items: center; padding: 2rem; gap: 1rem; background-color: #ffffff; border-radius: 0.5rem; }"
}
```

#### SQL → ORM

```json
{
    "conversion_type": "sql_to_orm",
    "source_code": "CREATE TABLE products (id SERIAL PRIMARY KEY, name VARCHAR(200) NOT NULL, price DECIMAL(10,2), category_id INTEGER REFERENCES categories(id), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
    "orm_target": "both"
}
```

#### JSON → TypeScript

```json
{
    "conversion_type": "json_to_typescript",
    "source_code": "{\"id\": 1, \"name\": \"Widget\", \"price\": 29.99, \"tags\": [\"sale\", \"new\"], \"dimensions\": {\"width\": 10, \"height\": 20}}",
    "root_class_name": "Product"
}
```

#### JSON → Dataclass

```json
{
    "conversion_type": "json_to_dataclass",
    "source_code": "{\"id\": 1, \"name\": \"Widget\", \"price\": 29.99, \"in_stock\": true, \"metadata\": null}",
    "root_class_name": "Product"
}
```

***

### Tech Stack

- **Runtime**: Python 3.11
- **Platform**: Apify SDK v2
- **Dependencies**: Zero external deps for converters (stdlib only)
- **Docker**: `apify/actor-python:3.11`

***

### License

MIT

# Actor input Schema

## `conversion_type` (type: `string`):

Select which code conversion to perform.

## `source_code` (type: `string`):

Paste the source code you want to convert. The format must match the selected Conversion Type.

## `root_class_name` (type: `string`):

Name for the root TypeScript interface or Python dataclass. Only used for JSON→TypeScript and JSON→Dataclass conversions.

## `orm_target` (type: `string`):

Which ORM output to generate for SQL conversion. 'both' produces SQLAlchemy (Python) + Sequelize (JavaScript).

## `batch_conversions` (type: `array`):

Run multiple conversions in a single actor call. Provide a JSON array of objects, each with 'conversion\_type', 'source\_code', and optionally 'root\_class\_name' / 'orm\_target'. When provided, the single inputs above are ignored.

## `proxy_configuration` (type: `object`):

Not required for this actor (no web requests), but included for Apify platform compatibility.

## Actor input object example

```json
{
  "conversion_type": "html_to_markdown",
  "source_code": "<h1>Hello World</h1>\n<p>This is a <strong>demo paragraph</strong> with <em>italic text</em> and a <a href=\"https://example.com\">link</a>.</p>\n<h2>Features</h2>\n<ul>\n  <li>Fast conversion</li>\n  <li>Supports <code>inline code</code></li>\n  <li>Tables and lists</li>\n</ul>\n<blockquote>This is a blockquote.</blockquote>\n<pre><code>console.log('Hello!');</code></pre>",
  "root_class_name": "Root",
  "orm_target": "both",
  "batch_conversions": [],
  "proxy_configuration": {}
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "conversion_type": "html_to_markdown",
    "source_code": `<h1>Hello World</h1>
<p>This is a <strong>demo paragraph</strong> with <em>italic text</em> and a <a href="https://example.com">link</a>.</p>
<h2>Features</h2>
<ul>
  <li>Fast conversion</li>
  <li>Supports <code>inline code</code></li>
  <li>Tables and lists</li>
</ul>
<blockquote>This is a blockquote.</blockquote>
<pre><code>console.log('Hello!');</code></pre>`,
    "root_class_name": "Root",
    "orm_target": "both",
    "batch_conversions": [],
    "proxy_configuration": {}
};

// Run the Actor and wait for it to finish
const run = await client.actor("moving_beacon-owner1/my-actor-64").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "conversion_type": "html_to_markdown",
    "source_code": """<h1>Hello World</h1>
<p>This is a <strong>demo paragraph</strong> with <em>italic text</em> and a <a href=\"https://example.com\">link</a>.</p>
<h2>Features</h2>
<ul>
  <li>Fast conversion</li>
  <li>Supports <code>inline code</code></li>
  <li>Tables and lists</li>
</ul>
<blockquote>This is a blockquote.</blockquote>
<pre><code>console.log('Hello!');</code></pre>""",
    "root_class_name": "Root",
    "orm_target": "both",
    "batch_conversions": [],
    "proxy_configuration": {},
}

# Run the Actor and wait for it to finish
run = client.actor("moving_beacon-owner1/my-actor-64").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "conversion_type": "html_to_markdown",
  "source_code": "<h1>Hello World</h1>\\n<p>This is a <strong>demo paragraph</strong> with <em>italic text</em> and a <a href=\\"https://example.com\\">link</a>.</p>\\n<h2>Features</h2>\\n<ul>\\n  <li>Fast conversion</li>\\n  <li>Supports <code>inline code</code></li>\\n  <li>Tables and lists</li>\\n</ul>\\n<blockquote>This is a blockquote.</blockquote>\\n<pre><code>console.log('\''Hello!'\'');</code></pre>",
  "root_class_name": "Root",
  "orm_target": "both",
  "batch_conversions": [],
  "proxy_configuration": {}
}' |
apify call moving_beacon-owner1/my-actor-64 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=moving_beacon-owner1/my-actor-64",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/0jaFW8cSD0omsasNc/builds/9VkLTkfOBKuHT7iFu/openapi.json
