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.
47 lines (41 loc) • 14.2 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\noutput.html\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 °// Simple 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\nMinimalist example of using **`@verikami/remark-deflist-revisited`** in Node.js.\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\nSee also examples of **[Express.js][+:express]**, **[Astro][+:astro]** and **[Cloudflare Worker][+:worker]** implementations.\n\n## Features\n\n- Pure Node.js with minimal dependencies\n- Exportable functions for reuse\n- File output capability\n- Basic HTML styling\n- Error handling\n\n## Requirements\n\n- Node.js 20 or higher\n- npm, pnpm or yarn\n\n## Quick Start\n\n```bash\n## Install dependencies\nツ npm install\n\n## Run server with main example\nツ npm start\n\n## Run server with file watching\nツ npm run dev\n\n## Run the main generation example\nツ npm run gen\n\n## Run with file watching\nツ npm run watch\n\n## See example html output\nツ npm run example\n\n## Run tests\nツ npm test\n```\n\n## Usage Examples\n\n### As a Script\n\n```bash\nツ node index.js\n```\n\n### As a Module\n\n```javascript\nimport { processMarkdown, createHTMLPage } from './index.js';\n\nconst html = await processMarkdown('Your **markdown** content');\nconst page = createHTMLPage(html, 'Page Title');\n```\n\n## Files\n\n- `index.js` → Main processor with exportable functions\n- `example.js` → How to use as a module\n- `test.js` → Basic functionality tests\n\n## Output\n\nRunning `npm start` generates `output.html` file with:\n\n- Processed markdown → HTML conversion\n- Definition lists support\n- Basic CSS styling\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[GH]: https://github.com/veriKami/remark-deflist-revisited\n[GH Badge]: https://img.shields.io/badge/GitHub-Repository-blue?logo=github\n\n[Remark]: https://remark.js.org\n[Express.js]: https://expressjs.com\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",
"example.js": "//: example.js\n//: -----------------------------------------\nimport { processMarkdown, createHTMLPage } from \"./index.js\";\n\nconst markdown = `\n# Custom Example\n\nAPI Endpoint\n: /api/v1/users\n: Methods: GET, POST, PUT\n\nResponse Format\n: JSON\n: Includes status and data fields\n`;\n\n//: MAIN\n//: -----------------------------------------\nasync function runExample() {\n const content = await processMarkdown(markdown);\n const page = createHTMLPage(content, \"API Documentation\");\n\n console.log(\"👄 Generated HTML:\\n\");\n console.log(\"\\x1b[33m%s\\x1b[0m\", content);\n console.log(\"🌐 Page length:\", page.length);\n}\n\nrunExample();\n",
"index.js": "//: index.js\n//: -----------------------------------------\nimport { writeFile } from \"node:fs/promises\";\nimport { remark } from \"remark\";\nimport html from \"remark-html\";\nimport deflist from \"@verikami/remark-deflist-revisited\";\n\n//: Simple markdown to process\n//: -----------------------------------------\nconst markdown = `\n# Remark Deflist Revisited °// Simple Example\n\nNode.js\n: JavaScript runtime\n: Built on V8 engine\n\nDefinition Lists\n: Support nested content\n: - Item 1\n - Item 2\n - Item 3\n\n## Usage\n\nSimply run this script to see markdown converted to HTML with definition lists support.\n`;\n\n//: Processing function\n//: -----------------------------------------\nasync function processMarkdown(markdown) {\n const result = await remark()\n .use(deflist)\n .use(html)\n .process(markdown);\n \n return String(result);\n}\n\n//: Function that creates an HTML page\n//: -----------------------------------------\nfunction createHTMLPage(content, title = \"Markdown Processor\") {\n return `<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"UTF-8\">\n <title>${title}</title>\n <style>\n body {\n font-family: system-ui, sans-serif;\n max-width: 800px;\n margin: 0 auto;\n padding: 20px;\n line-height: 1.6;\n background: #f5f5f5;\n }\n .container {\n background: white;\n padding: 30px;\n border-radius: 8px;\n box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n }\n dt {\n font-weight: bold;\n color: #2563eb;\n margin-top: 15px;\n }\n dd {\n margin-left: 20px;\n color: #4b5563;\n }\n h1, h2 { color: #1e40af; }\n </style>\n </head>\n<body>\n <div class=\"container\">\n ${content}\n <hr>\n <p style=\"text-align: center; color: #6b7280; font-size: 0.9em;\">\n Powered by @verikami/remark-deflist-revisited\n </p>\n </div>\n</body>\n</html>`;\n}\n\n//: MAIN\n//: -----------------------------------------\nasync function main() {\n try {\n console.log(\"👄 Processing markdown\");\n \n const content = await processMarkdown(markdown);\n const page = createHTMLPage(content, \"Simple Markdown Processor\");\n\n await writeFile(\"output.html\", page);\n \n console.log(\"✅ HTML generated successfully\");\n console.log(\"🌐 Generated file: output.html\");\n }\n catch (err) {\n console.error(\"❌ Error:\", err.message);\n }\n}\n\n//: Direct execution\n//: -----------------------------------------\nif (import.meta.url === `file://${process.argv[1]}`) {\n main();\n}\n\n//: EXPORT\n//: -----------------------------------------\nexport { processMarkdown, createHTMLPage };\n",
"package.json": "{\n \"name\": \"remark-deflist-revisited-simple\",\n \"version\": \"0.1.0\",\n \"description\": \"Simple 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-simple\",\n \"homepage\": \"https://github.com/veriKami/remark-deflist-revisited-simple#readme\",\n \"type\": \"module\",\n \"main\": \"server.js\",\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"scripts\": {\n \"start\": \"node server.js\",\n \"dev\": \"node --watch server.js\",\n \"gen\": \"node index.js\",\n \"watch\": \"node --watch index.js\",\n \"example\": \"node example.js\",\n \"test\": \"node test.js\"\n },\n \"dependencies\": {\n \"@verikami/remark-deflist-revisited\": \"^0.6.4\",\n \"remark\": \"^15.0.1\",\n \"remark-html\": \"^16.0.1\"\n }\n}\n",
"server.js": "//: server.js\n//: -----------------------------------------\nimport { createServer } from \"http\";\nimport { remark } from \"remark\";\nimport html from \"remark-html\";\nimport deflist from \"@verikami/remark-deflist-revisited\";\n\nconst PORT = process.env.PORT || 3000;\n\n//: Simple markdown to process\n//: -----------------------------------------\nconst markdown = `\n# Remark Deflist Revisited °// Simple Example\n\nNode.js\n: JavaScript runtime\n: Built on V8 engine\n\nDefinition Lists\n: Support nested content\n: - Item 1\n - Item 2\n - Item 3\n\n## Usage\n\nSimply run this script to see markdown converted to HTML with definition lists support.\n`;\n\n//: Processing function\n//: -----------------------------------------\nasync function processMarkdown(markdown) {\n const result = await remark()\n .use(deflist)\n .use(html)\n .process(markdown);\n\n return String(result);\n}\n\n//: Function that creates an HTML page\n//: -----------------------------------------\nfunction createHTMLPage(content, title = \"Markdown Processor\") {\n return `<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"UTF-8\">\n <title>${title}</title>\n <style>\n body {\n font-family: system-ui, sans-serif;\n max-width: 800px;\n margin: 0 auto;\n padding: 20px;\n line-height: 1.6;\n background: #f5f5f5;\n }\n .container {\n background: white;\n padding: 30px;\n border-radius: 8px;\n box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n }\n dt {\n font-weight: bold;\n color: #2563eb;\n margin-top: 15px;\n }\n dd {\n margin-left: 20px;\n color: #4b5563;\n }\n h1, h2 { color: #1e40af; }\n </style>\n </head>\n<body>\n <div class=\"container\">\n ${content}\n <hr>\n <p style=\"text-align: center; color: #6b7280; font-size: 0.9em;\">\n Powered by @verikami/remark-deflist-revisited\n </p>\n </div>\n</body>\n</html>`;\n}\n\n//: CONTENT\n//: -----------------------------------------\nconsole.log(\"\\n👄 Processing Markdown\");\n\nconst content = await processMarkdown(markdown);\nconst page = createHTMLPage(content, \"Simple Markdown Processor\");\n\n//: SERVER\n//: -----------------------------------------\nconst server = createServer((req, res) => {\n console.log(\"✅ Serving Content\");\n res.writeHead(200, { \"Content-Type\": \"text/html\" });\n res.end(page);\n});\n\n//: MAIN\n//: -----------------------------------------\nserver.listen(PORT, () => {\n console.log(`🌐 http://localhost:${PORT}\\n`);\n});\n",
"test.js": "//: test.js\n//: -----------------------------------------\nimport { processMarkdown } from \"./index.js\";\n\nconst markdown = `\n# Test Definition Lists\n\nTerm A\n: Definition A1\n: Definition A2\n\nTerm B\n: Single definition\n`;\n\n//: MAIN\n//: -----------------------------------------\nasync function runTests() {\n console.log(\"👄 Running tests\");\n \n try {\n const result = await processMarkdown(markdown);\n\n const tests = {\n \"Contains Term A\": result.includes(\"Term A\"),\n \"Contains Definition A1\": result.includes(\"Definition A1\"),\n \"Contains Term B\": result.includes(\"Term B\"),\n \"Is valid HTML\": result.startsWith(\"<h1>\") && result.includes(\"</dl>\")\n };\n \n console.log(\"👄 Test results:\\n\");\n\n Object.entries(tests).forEach(([test, passed]) => {\n console.log(`${passed ? \"✅\" : \"❌\"} ${test}`);\n });\n \n console.log(`\\n🌐 HTML output length: ${result.length} characters`);\n \n }\n catch (err) {\n console.error(\"💥 Test failed:\", err.message);\n }\n}\n\nrunTests();\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.simple.js <path>");
console.log("USING (default): remark-deflist-revisited-simple");
}
const target = process.argv[2] || "remark-deflist-revisited-simple";
const $ = process.argv[3] === "false" ? false : true;
generate(target, $).catch(console.error);
}
export default generate;