create-remark-deflist-revisited
Version:
Remark plugin for demonstrating nested definition lists in action. Create a skeleton project with @verikami/remark-deflist-revisited – interactive template selection.
46 lines (40 loc) • 13.8 kB
JavaScript
import { writeFile, mkdir } from "node:fs/promises";
import { join, dirname } from "node:path";
const files = {
".gitignore": "#: --------------------------------\n#: veriKami\n\nnode_modules\n\n**/•*\n*~\nIcon*\n",
".npmrc": "#: npm\npackage-lock=true\n\n#: pnpm\nlockfile-dir=.\nlockfile=true\n",
"LICENSE": "MIT License\n\nCopyright (c) 2025 °// veriKami °// Weronika Kami\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"README.md": "# Remark Deflist Revisited °// Cloudflare Worker Example\n\n[![GH][GH Badge]][GH]\n[![NPM][NPM Badge]][NPM]\n[![JSR][JSR Badge]][JSR]\n[![Downloads][Downloads Badge]][Downloads]\n[![Socket][Socket Badge]][Socket]\n\nCloudflare Worker implementation of the **`@verikami/remark-deflist-revisited`** module, demonstrating enhanced definition lists processing in markdown with full HTML output on the edge.\n\n**[Remark Deflist Revisited][module]** is a **[Remark]** plugin. A wrapper around **`remark-deflist`** with improved support for nested definition lists. It preserves all the original functionality and performs additional processing. \n\n## Overview\n\nThis project provides a Cloudflare Worker example showcasing how to use **`remark-deflist-revisited`** in serverless edge environment. **[Express.js][+:express]**, **[Astro][+:astro]** and **[Simple][+:simple]** examples are also available.\n\n## Features\n\n- **Enhanced Definition Lists**: Support for complex nested structures\n- **Serverless Architecture**: No server management, automatic scaling\n- **Fast Cold Starts**: Optimized for edge computing\n- **Beautiful Styling**: Professional CSS styling with gradient background\n- **Error Handling**: Comprehensive error handling and validation\n\n## Quick Start\n\n### Prerequisites\n\n- Node.js 20 or higher\n- npm, pnpm or yarn\n- Cloudflare account\n- Wrangler CLI\n\n### Installation\n\n```bash\n## Clone or download this project\nツ git clone git@github.com:veriKami/remark-deflist-revisited-worker.git\n\n## Install dependencies\nツ npm install\n```\n\n### Local Development\n\n```bash\n## Start local development server\nツ npm run dev\n\n## Deploy to Cloudflare Workers\nツ npm run deploy\n```\n\nThe worker will be available at your Cloudflare Workers URL.\n\n## API Endpoint\n\n### GET `/`\n\n- **Edge Location**: Processes markdown closest to the user\n- **Description**: Returns a demo page with pre-processed markdown\n- **Response**: HTML page with styled content\n\n## Usage Examples\n\n### Accessing the Worker\n\n```bash\n## Access your deployed worker\nツ curl https://your-worker.your-subdomain.workers.dev\n\n## Test locally\nツ curl http://localhost:8787\n```\n\n### Worker Code Structure\n\n```javascript\nexport default {\n async fetch(request, env, ctx) {\n const markdown = `\n # Example\n \n Cloudflare Workers\n : Serverless platform\n : Runs on the edge\n `;\n\n const output = await remark()\n .use(deflist)\n .use(html)\n .process(markdown);\n\n return new Response(htmlResponse, {\n headers: { \"Content-Type\": \"text/html\" }\n });\n }\n}\n```\n\n## Project Structure\n\n```\n.\n├── src/\n│ └── index.js # Cloudflare Worker handler\n├── package.json # Dependencies and scripts\n├── wrangler.toml # Worker configuration\n└── README.md # This file\n```\n\n## Dependencies\n\n### Production Dependencies\n\n- `@verikami/remark-deflist-revisited` → Enhanced definition lists for remark\n- `remark` → Markdown processor\n- `remark-html` → HTML serializer for remark\n- `dedent` → Dedent template strings\n\n### Development Dependencies\n\n- `wrangler` → Cloudflare Workers CLI\n\n## Comparison with Other Implementations\n\n| Feature | Express.js | Astro Integration | Cloudflare Worker |\n|-----------------|--------------|---------------------|-------------------|\n| **Rendering** | Server-side | SSG/SSR | Edge |\n| **Build Time** | Runtime | Pre-built at deploy | Runtime |\n| **Performance** | Good | Excellent (static) | Excellent (edge) |\n| **Complexity** | Medium | Low | Low |\n| **Use Case** | Dynamic apps | Documentation sites | API endpoints |\n\n## Development\n\n### Local Testing\n\n```bash\n## Develop locally with Wrangler\nツ npx wrangler dev\n\n## Deploy to production\nツ npx wrangler deploy\n```\n\n### Customizing Markdown Content\n\nEdit the `markdown` variable in `src/index.js`:\n\n```javascript\nconst markdown = `\n # Your Custom Title\n \n Your Term\n : Your definition here\n : - Nested item 1\n - Nested item 2\n`;\n```\n\n### Custom Styling\n\nModify the CSS in the HTML template:\n\n```javascript\nconst htmlResponse = `\n <style>\n /* Your custom CSS here */\n body { \n background: your-gradient; \n font-family: your-font;\n }\n </style>\n ...\n`;\n```\n\n## Edge Computing Benefits\n\n- **Reduced Latency**: Process markdown closer to users\n- **High Availability**: Automatic failover between locations\n- **Zero Maintenance**: No server management required\n- **Cost Effective**: Pay only for what you use\n\n## License\n\nThis project is Open Source and available under the MIT License \n2025 © MIT °// [veriKami] °// [Weronika Kami]\n\n[veriKami]: https://verikami.com\n[Weronika Kami]: https://linkedin.com/in/verikami\n\n[module]: https://github.com/veriKami/remark-deflist-revisited\n[+:simple]: https://github.com/veriKami/remark-deflist-revisited-simple\n[+:express]: https://github.com/veriKami/remark-deflist-revisited-express\n[+:worker]: https://github.com/veriKami/remark-deflist-revisited-worker\n[+:astro]: https://github.com/veriKami/remark-deflist-revisited-astro\n\n[Remark]: https://remark.js.org\n[Astro]: https://astro.build\n\n[GH Badge]: https://img.shields.io/badge/GitHub-Repository-blue?logo=github\n[GH]: https://github.com/veriKami/remark-deflist-revisited\n\n[NPM Badge]: https://img.shields.io/npm/v/@verikami/remark-deflist-revisited?logo=npm&logoColor=white&labelColor=red&color=black\n[NPM]: https://www.npmjs.com/package/@verikami/remark-deflist-revisited\n\n[JSR Badge]: https://jsr.io/badges/@verikami/remark-deflist-revisited\n[JSR]: https://jsr.io/@verikami/remark-deflist-revisited\n\n[Downloads Badge]: https://img.shields.io/npm/dm/@verikami/remark-deflist-revisited.svg\n[Downloads]: https://www.npmjs.com/package/@verikami/remark-deflist-revisited\n\n[Socket Badge]: https://badge.socket.dev/npm/package/@verikami/remark-deflist-revisited\n[Socket]: https://socket.dev/npm/package/@verikami/remark-deflist-revisited\n",
"package.json": "{\n \"name\": \"remark-deflist-revisited-worker\",\n \"version\": \"0.1.0\",\n \"description\": \"Cloudflare Worker example for @verikami/remark-deflist-revisited\",\n \"keywords\": [\n \"remark\",\n \"remark-plugin\",\n \"remark-deflist\",\n \"markdown\",\n \"markdown-plugin\",\n \"definition-list\",\n \"deflist\",\n \"parser\",\n \"veriKami\"\n ],\n \"author\": \"veriKami <verikami@gmail.com> (https://verikami.com/)\",\n \"license\": \"MIT\",\n \"repository\": \"github:veriKami/remark-deflist-revisited-worker\",\n \"homepage\": \"https://github.com/veriKami/remark-deflist-revisited-worker#readme\",\n \"type\": \"module\",\n \"main\": \"src/index.js\",\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"scripts\": {\n \"dev\": \"wrangler dev\",\n \"deploy\": \"wrangler deploy\"\n },\n \"dependencies\": {\n \"@verikami/remark-deflist-revisited\": \"^0.6.4\",\n \"dedent\": \"^1.7.0\",\n \"remark\": \"^15.0.1\",\n \"remark-html\": \"^16.0.1\"\n },\n \"devDependencies\": {\n \"wrangler\": \"^4.41.0\"\n }\n}\n",
"src/index.js": "import { remark } from \"remark\";\nimport html from \"remark-html\";\nimport dedent from \"dedent\";\nimport deflist from \"@verikami/remark-deflist-revisited\";\n\nexport default {\n async fetch(request, env, ctx) {\n const markdown = dedent`\n # Remark Deflist Revisited Worker Example\n\n Cloudflare Worker\n : Serverless platform on the edge\n : Runs code close to users worldwide\n\n Remark Deflist Revisited\n : Compatible with Bun, Deno and Cloudflare Workers\n : Enhanced definition lists support\n : Supports nested lists\n\n Markdown\n : Lightweight markup language\n : Easy to write and read\n\n ## Features\n\n Nested Lists\n : Support for complex structures\n : - Item A\n - Item B\n - Item C\n\n Compatibility\n : Works with modern runtimes\n : - Cloudflare Workers\n - Node.js\n - Deno\n - Bun\n `;\n\n try {\n const output = await remark()\n .use(deflist)\n .use(html)\n .process(markdown);\n\n const htmlResponse = dedent`\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Remark Deflist Revisited Worker Example</title>\n <meta name=\"author\" content=\"veriKami °// Weronika Kami\">\n <style>\n body {\n font-family: -apple-system, BlinkMacSystemFont, sans-serif;\n max-width: 800px;\n margin: 0 auto;\n padding: 20px;\n line-height: 1.6;\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: #333;\n }\n .container {\n background: white;\n border-radius: 12px;\n padding: 30px;\n box-shadow: 0 10px 30px rgba(0,0,0,0.1);\n }\n h1 { color: #667eea; margin-top: 0; }\n dl { margin: 20px 0; }\n dt {\n font-weight: bold;\n margin: 20px 0 0;\n color: #667eea;\n font-size: 1.1em;\n }\n dd {\n margin: 5px 0 0 40px;\n color: #666;\n }\n ul { margin: 0 10px; }\n li { margin: 0; }\n </style>\n </head>\n <body>\n <div class=\"container\">\n ${String(output)}\n <hr style=\"margin: 40px 0; border: none; border-top: 1px solid #ddd;\">\n <p style=\"text-align: center; color: #888; font-size: 0.9em;\">\n Created by <a href=\"https://verikami.com\" target=\"_blank\">veriKami</a> °//\n <a href=\"https://linkedin.com/in/verikami\" target=\"_blank\">Weronika Kami</a> °//\n <a href=\"https://github.com/veriKami/remark-deflist-revisited\" target=\"_blank\">\n @verikami/remark-deflist-revisited</a>\n </p>\n </div>\n </body>\n </html>\n `;\n\n return new Response(htmlResponse, {\n headers: {\n \"Content-Type\": \"text/html; charset=utf-8\",\n \"X-Powered-By\": \"Cloudflare Workers + Remark Deflist Revisited\"\n }\n });\n }\n catch (error) {\n return new Response(\n JSON.stringify({\n error: \"Failed to process markdown\",\n details: error.message\n }),\n {\n status: 500,\n headers: { \"Content-Type\": \"application/json\" }\n }\n );\n }\n }\n};\n",
"wrangler.toml": "name = \"remark-deflist-revisited-worker\"\ncompatibility_date = \"2025-09-23\"\ncompatibility_flags = [\"nodejs_compat\"]\nworkers_dev = true\nmain = \"src/index.js\"\n"
};
async function ensureDir(dir) {
try {
await mkdir(dir, { recursive: true });
}
catch (err) {
if (err.code !== "EEXIST") throw err;
}
}
async function generate(target = ".", $ = true) {
if ($) console.log("\n🚺 CREATING PROJECT\n");
for (const [filePath, content] of Object.entries(files)) {
const fullPath = join(target, filePath);
await ensureDir(dirname(fullPath));
await writeFile(fullPath, content);
if ($) console.log(" 📄", filePath)
else console.log(" ↳ Created:", filePath)
}
if ($) console.log("\n✅ PROJECT READY");
}
if (import.meta.url.endsWith(process.argv[1])) {
if (!process.argv[2]) {
console.log("\nUSAGE: node pack/bundle.worker.js <path>");
console.log("USING (default): remark-deflist-revisited-worker");
}
const target = process.argv[2] || "remark-deflist-revisited-worker";
const $ = process.argv[3] === "false" ? false : true;
generate(target, $).catch(console.error);
}
export default generate;