From 60cd68dbbc96c83293096fff6a6fdb98e4d1cdb7 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:50:16 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 12 + README.md | 3 + plugin.lock.json | 60 ++++ skills/figlet-text-converter/SKILL.md | 216 ++++++++++++ skills/figlet-text-converter/plugin.json | 15 + .../references/usage-guide.md | 324 ++++++++++++++++++ .../scripts/list-fonts.js | 54 +++ .../scripts/process-file.js | 192 +++++++++++ 8 files changed, 876 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 plugin.lock.json create mode 100644 skills/figlet-text-converter/SKILL.md create mode 100644 skills/figlet-text-converter/plugin.json create mode 100644 skills/figlet-text-converter/references/usage-guide.md create mode 100644 skills/figlet-text-converter/scripts/list-fonts.js create mode 100644 skills/figlet-text-converter/scripts/process-file.js diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..f0c3060 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "figlet-text-converter", + "description": "Converts marked text in files to ASCII art using figlet tag syntax.", + "version": "0.0.0-2025.11.28", + "author": { + "name": "Tim Green", + "email": "rawveg@gmail.com" + }, + "skills": [ + "./skills/figlet-text-converter" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7a0196 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# figlet-text-converter + +Converts marked text in files to ASCII art using figlet tag syntax. diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..4c571cf --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,60 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:rawveg/skillsforge-marketplace:figlet-text-converter", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "a997b3245f9fa04918258c7341d8ee279ec03ef3", + "treeHash": "87e5d454f077dbca39c39bef8939d4bf61da4cab6466654dc2066f174be1b6f4", + "generatedAt": "2025-11-28T10:27:50.619987Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "figlet-text-converter", + "description": "Converts marked text in files to ASCII art using figlet tag syntax." + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "4268154b78d102b15395520cf434da5271ffeb471e4afa3bc86549a56143cc73" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "889e591a1a43e41641fe55bb62f5fdc401bee1c81f641769fb5cdb059833a309" + }, + { + "path": "skills/figlet-text-converter/plugin.json", + "sha256": "33a27fa15c5b9b835e9dad57e2dac9abdfed9aaff99d1ae7f3d091d8be3f878a" + }, + { + "path": "skills/figlet-text-converter/SKILL.md", + "sha256": "b88438dfbce5794258dc70d675ba7f479a256bbf053cc627d423b87f77a74981" + }, + { + "path": "skills/figlet-text-converter/references/usage-guide.md", + "sha256": "135e6c7c37cf4c851117ac3507a027aa1c9caf9f8af07457ebdc06d6422ff55a" + }, + { + "path": "skills/figlet-text-converter/scripts/list-fonts.js", + "sha256": "a01bb9db4dd4ed9c7f2db9cabd8349ed28cd7e141e59eb7962816b589ae78446" + }, + { + "path": "skills/figlet-text-converter/scripts/process-file.js", + "sha256": "9b77d6a2a8d87ab353944a2a521c2152b766962d7547ea026e6890f9cc63b458" + } + ], + "dirSha256": "87e5d454f077dbca39c39bef8939d4bf61da4cab6466654dc2066f174be1b6f4" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/figlet-text-converter/SKILL.md b/skills/figlet-text-converter/SKILL.md new file mode 100644 index 0000000..7b35760 --- /dev/null +++ b/skills/figlet-text-converter/SKILL.md @@ -0,0 +1,216 @@ +--- +name: figlet-text-converter +description: This skill processes files containing figlet tags and replaces them with ASCII art representations. It detects and preserves comment styles (forward slash forward slash, hash, double-dash, forward slash asterisk), automatically manages Node.js dependencies, and supports 400+ fonts (defaulting to the standard font). The skill should be used when a user requests converting marked text in a file to ASCII art using figlet tag syntax, or when they want to list available fonts. +--- + +# Figlet Text Converter + +## Overview + +This skill converts marked text in files to ASCII art using the figlet library. It uses a simple, universal tag syntax that works across all file types and intelligently preserves comment formatting when tags are placed in commented sections. The skill handles dependency management automatically and supports 400+ fonts with sensible defaults. + +## When to Use This Skill + +Use this skill when: +- User asks to convert text in a file to ASCII art +- User provides a file containing `` tags +- User requests to list available figlet fonts +- User wants to add visual ASCII art headers or banners to code, documentation, or configuration files + +## Tag Syntax + +### Universal Markup + +Insert `` tags anywhere in a file to mark text for ASCII art conversion: + +**With font specification:** +``` +Text to Convert +``` + +**Using default font (standard):** +``` +Text to Convert +``` + +### Usage in Different Contexts + +#### Markdown Documents +```markdown +# Section Title + +Important Notice + +Content goes here... +``` + +#### Shell Scripts +```bash +#!/bin/bash + +echo 'Deployment Started' + +# Script logic... +``` + +#### Python Code +```python +# Configuration + +config = { + 'setting': 'value' +} +``` + +#### PHP/JavaScript +```php +// Database Connection + +function connectDB() { + // ... +} +``` + +#### Plain Text/Config Files +``` +System Status Report + +This report contains... +``` + +## Workflow + +### Processing a File + +When a user requests ASCII art conversion: + +1. Read the file containing `` tags +2. Validate all font names (error immediately if invalid) +3. For each tag: + - Extract the font name (or use 'standard' if omitted) + - Generate ASCII art for the text + - Detect comment style from the surrounding line (// # -- /*) + - Format output with appropriate comment prefixes +4. Replace tags with formatted ASCII art +5. Write changes back to the file + +### Handling Comments + +The skill automatically detects comment context: + +**Single-line comments:** +```bash +// Section Break +``` +Outputs each line with `// ` prefix: +```bash +// ___ _ _ ____ _ +// / __| ___ | | | | ___ _ _ | __ ) _ _ __| | | +// \__ \/ -_) | |_| |/ _ \| ' \ | _ \| '_|/ _` | | +// |___/\___| \___/ \___/|_|_|_| |_| \_\_| \__,_|_| +``` + +**Hash comments (Python, Shell):** +```python +# Configuration +``` +Outputs with `# ` prefix. + +**SQL/SQL comments:** +```sql +-- Query Section +``` +Outputs with `-- ` prefix. + +**Block comments:** +```java +/* Module Start +``` +Outputs with ` * ` prefix: +```java + * ___ _ _ _ ___ _ _ + * | \/ | ___ __| | _ | | ___ / __| | |_ __ _ _ | |_ + * | |\/| |/ _ \ / _` ||_|| |/ -_) \__ \ | _|/ _` || || _| + * |_| |_|\___/ \__,_| \__/ \___| |___/ |_| \__,_|\__|\__| +``` + +**Plain text (no comment prefix):** +``` +Plain ASCII Art +``` +Outputs raw ASCII art without formatting. + +## Font Selection + +### Default Font + +If no font is specified, 'standard' is used: +``` +Default Font Example +``` + +### Custom Fonts + +Specify any of 400+ available fonts: +``` +Bold Text +3D Effect +Shadowed +``` + +### Finding Fonts + +When user requests to list available fonts, run the font discovery script to show: +- Previews of the first 10 fonts with examples +- Complete alphabetical listing of all 400+ fonts +- Font names for use in tags + +Popular fonts: +- standard (default) +- 3-D +- Block +- Big +- Shadow +- Slant +- Graffiti +- Doom + +## Error Handling + +The skill validates fonts before processing: +- **Invalid font specified**: Error immediately with font name and suggestion to list available fonts +- **File not found**: Error with file path +- **Node.js/npm issues**: Error with installation instructions + +## Bundled Resources + +### scripts/ + +**process-file.js** +- Main processing script that reads files, finds all `` tags, validates fonts, generates ASCII art, detects comment styles, and writes results +- Handles automatic Node.js verification and npm dependency installation on first run +- Usage: `node process-file.js ` + +**list-fonts.js** +- Displays all available figlet fonts with previews and complete listing +- Helps users find the exact font names to use in tags +- Usage: `node list-fonts.js` + +**package.json** +- Node.js project file with figlet v1.7.0+ dependency + +**.gitignore** +- Excludes node_modules from version control + +### references/ + +**usage-guide.md** - Comprehensive reference documentation for all features and edge cases + +## Technical Details + +- **Node.js Requirement**: v14 or higher +- **Figlet Package**: v1.7.0 or higher (auto-installed on first use) +- **Tag Format**: `text` or `text` +- **Comment Styles Supported**: //, #, --, /*, or none +- **Default Font**: standard +- **File Processing**: In-place modification diff --git a/skills/figlet-text-converter/plugin.json b/skills/figlet-text-converter/plugin.json new file mode 100644 index 0000000..b3fa39f --- /dev/null +++ b/skills/figlet-text-converter/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "figlet-text-converter", + "description": "Converts marked text in files to ASCII art using figlet tag syntax.", + "version": "1.0.1", + "author": { + "name": "Tim Green", + "email": "rawveg@gmail.com" + }, + "homepage": "https://github.com/rawveg/claude-skills-marketplace", + "repository": "https://github.com/rawveg/claude-skills-marketplace", + "license": "MIT", + "keywords": ["figlet", "text", "converter", "Claude Code"], + "category": "productivity", + "strict": false +} diff --git a/skills/figlet-text-converter/references/usage-guide.md b/skills/figlet-text-converter/references/usage-guide.md new file mode 100644 index 0000000..f5661be --- /dev/null +++ b/skills/figlet-text-converter/references/usage-guide.md @@ -0,0 +1,324 @@ +# Figlet Text Converter - Usage Guide + +## Overview + +The Figlet Text Converter skill converts marked text in files to ASCII art. It uses a universal `` tag syntax that works across all file types and intelligently preserves comment formatting. + +## Getting Started + +### Installation + +The skill automatically manages Node.js dependencies on first use. When invoked: + +1. Verifies Node.js v14+ is installed +2. Installs the figlet package via npm if needed +3. Processes your file + +### Basic Usage + +Insert `` tags in any file to mark text for conversion: + +``` +Text to Convert +``` + +Then ask Claude to process the file: + +``` +"Convert all figlet tags in this markdown file to ASCII art" +``` + +## Tag Syntax + +### Simple Tag (Uses Default Font) + +``` +Welcome +``` + +Uses 'standard' font (default). + +### Tag with Custom Font + +``` +Welcome +``` + +Uses the specified font. Font names are case-sensitive and must exactly match figlet's font list. + +## Usage Examples + +### Markdown Document + +**Input:** +```markdown +# My Documentation + +Getting Started + +Follow these steps... + +Important Note + +This is critical... +``` + +**Output:** +```markdown +# My Documentation + + ____ _ _ _ _____ _ _ _ _ +/ ___| ___| |_| |_(_)_ __ __ _ / ____| | |_ __ _ _ _| |_| |___ __| | +| | _/ -_| _| _| | '_ \ / _` | / __| _ | __| / _` | | | | _| / _ \/ _` | +| |_| \__ \ _| _| | | | | (_| |/ /____| | |_| (_| | | | | | |_| __/ (_| | + \____|___/\__|\__|_|_| |_|\__, |\_______| \__|\_\__,_\_/_|_|\__|\___|\_\__, + |___/ +Follow these steps... + + ___ _ +|_ _|_ __ ___ _ __ ___| |_ __ _ _ _ | |_ + | | '_ ` _ \| '_ \ / _ \| _| / _` || | | | _| + | | | | | | | |_) | __/ | |_| (_| || | | | | | +|___|_| |_| |_| .__/ \___|_|\__|\_\__|\__,_|_| | + |_| + +This is critical... +``` + +### Python Script + +**Input:** +```python +# Configuration + +DEBUG = True +LOG_LEVEL = "INFO" +``` + +**Output:** +```python +# ____ ___ _ +# / ___|__ _ _ / __| ___ _ _ ___ ___ _ _ __ _ __ __| | __ +# | |__/ _ \ | | | / /__ / _ \ | | | / _ \ / _ \| | | / _` | \ \/ /| |/ / +# | __| | | || | | ___| | | || |_|| (_) || __/ (_| |( _ | > < | __\ +# |_| |_| |_| \_\ \___|_| |_| \__,_|\___/ \___|\__,_| \_/ |_/_/\_\ |_| + +DEBUG = True +LOG_LEVEL = "INFO" +``` + +### Shell Script + +**Input:** +```bash +#!/bin/bash + +echo 'Starting Deployment' + +# Deploy code... +``` + +**Output:** +```bash +#!/bin/bash + +echo ' ___ _ _ _ _ ___ _ _ + / __|_| |_ __ _ | |_| | ___ _ | | __ _ / ___| |___ _ __ | | + \__ \_ _/ _` || __| |/ _ \| | |/ _` | / / | | _ \| '_ \ | |_ + |___/ |_| \__,_| \__|_| \___/|_|_|\__, | \_\__| | |_) | |_) ||___| + |___/ |_.__/ | .__/|___| + |_|' + +# Deploy code... +``` + +### PHP Code + +**Input:** +```php +Database Connection + +$conn = new PDO($dsn); +``` + +**Output:** +```php +Database Settings +host=localhost +port=5432 +``` + +**Output:** +```ini +[database] + ___ __ _ _ ___ __ _ _ _ +| \ / \| |_ __ _ | |__ __ _ ___ / __| |_ _| | | | | |_ __ __ _ ___ +| | || ()| / _` || _ \ / _` | -_) \__ \| _| |_| |_| _| / _` | / _ \ +|__/ \_/\_|\__,_||_|_|_|\__,_|\___| |___/ |_| \___/ |_| \__, | \___/ + |___/ +host=localhost +port=5432 +``` + +## Comment Style Detection + +The skill automatically detects and preserves comment styles: + +| Language | Comment Style | Example | +|----------|---------------|---------| +| C/C++/Java/PHP/JavaScript | `//` | `// Section` | +| Python/Bash | `#` | `# Section` | +| SQL | `--` | `-- Section` | +| C/Java (Block) | `/*` | `/* Section` | +| Plain text | None | `Section` | + +When a tag is on a line with a comment marker, output is formatted with that comment style: + +``` +// Header +``` + +Becomes: + +``` +// ___ _ _ +// | | | |___ ___ __| |__ _ ___ __ +// | |_| // -_)/ _ \/ _` / _` / -_) / _ \ +// \___/ \___|\___/\__,_\__,_|\___| __/ +// |_| +``` + +## Finding Fonts + +To see all available fonts, ask Claude to list them: + +``` +"List all available figlet fonts" +``` + +This will show: +- Previews of popular fonts +- Complete alphabetical listing of 400+ available fonts +- Font names to use in tags + +### Popular Fonts + +- **standard** - Default, traditional figlet style +- **3-D** - 3D effect with shading +- **Block** - Large, blocky characters +- **Big** - Large and simple +- **Shadow** - Shadowed appearance +- **Slant** - Slanted characters +- **Graffiti** - Artistic style +- **Doom** - Heavy, bold style +- **Isometric1/2** - Isometric projection + +## Troubleshooting + +### Invalid Font Error + +``` +āŒ Error: Invalid font "MyFont" in tag: Text + Run 'node list-fonts.js' to see available fonts. +``` + +**Solution:** Use a valid font name from the list. Font names are case-sensitive. + +### File Not Found + +``` +āŒ Error: File not found: /path/to/file.txt +``` + +**Solution:** Verify the file path is correct. + +### Node.js Not Installed + +``` +āŒ Dependencies not installed. Please run: npm install +``` + +**Solution:** Install Node.js v14+ from https://nodejs.org/ + +## Advanced Usage + +### Multiple Tags in One File + +You can use multiple figlet tags in a single file: + +```markdown +Section One + +Content here... + +Section Two + +More content... +``` + +Each tag is processed independently with its own font and style. + +### Mixing Comment Styles + +Different parts of a file can have different comment styles: + +``` +// JavaScript Section + +const x = 10; + +# Python Section + +x = 10 +``` + +Each is formatted appropriately for its comment context. + +### Large Text Conversion + +ASCII art can be quite large. For long text strings: + +``` +A +A +``` + +Use shorter fonts for longer text to keep output manageable. + +## Tips & Tricks + +1. **Preview Before Converting**: Ask Claude to show you the ASCII art for your text before inserting it +2. **Consistent Styling**: Use the same font throughout a file for visual consistency +3. **Comment the Conversion**: Leave a comment explaining what the ASCII art represents +4. **Test Display**: Verify the output displays correctly in your target environment (editor, terminal, web) +5. **Reserve for Impact**: Use ASCII art sparingly for section headers, not inline text + +## Limitations + +- Font names must match figlet's font list exactly (case-sensitive) +- Each tag is processed independently; multi-line ASCII art expands proportionally +- Comment detection is line-based (tag must be on same line as comment marker) +- Very long text may produce large ASCII art output diff --git a/skills/figlet-text-converter/scripts/list-fonts.js b/skills/figlet-text-converter/scripts/list-fonts.js new file mode 100644 index 0000000..15dbf2b --- /dev/null +++ b/skills/figlet-text-converter/scripts/list-fonts.js @@ -0,0 +1,54 @@ +import { execSync } from 'child_process'; + +// Get available fonts via npx figlet +function getAvailableFonts() { + try { + const output = execSync('npx figlet --list', { encoding: 'utf-8' }); + // Skip the "Available fonts:" header and filter out empty lines + return output.trim().split('\n').slice(1).map(line => line.trim()).filter(line => line); + } catch (error) { + console.error('Error retrieving fonts:', error.message); + process.exit(1); + } +} + +// Generate ASCII art via npx figlet +function generateAsciiArt(text, font) { + try { + const output = execSync(`npx figlet -f "${font}" "${text}"`, { encoding: 'utf-8' }); + return output; + } catch (error) { + return '(Preview not available)'; + } +} + +// Main function +function main() { + const fonts = getAvailableFonts(); + + console.log(`\nšŸ“‹ Available Figlet Fonts (${fonts.length} total):\n`); + console.log('='.repeat(60)); + + // Show first 10 fonts with examples + const previewCount = Math.min(10, fonts.length); + + for (let i = 0; i < previewCount; i++) { + const font = fonts[i]; + console.log(`\nšŸ”¤ ${font}`); + console.log('-'.repeat(40)); + const preview = generateAsciiArt('Sample', font); + console.log(preview); + } + + console.log('\n' + '='.repeat(60)); + console.log(`\nšŸ“ All Available Fonts (${fonts.length} total):\n`); + + fonts.forEach((font, index) => { + console.log(` ${(index + 1).toString().padStart(3)}. ${font}`); + }); + + console.log('\nšŸ’” Tip: Use font="font-name" in figlet tags'); + console.log(' Default font: "standard"\n'); +} + +main(); diff --git a/skills/figlet-text-converter/scripts/process-file.js b/skills/figlet-text-converter/scripts/process-file.js new file mode 100644 index 0000000..d9efc48 --- /dev/null +++ b/skills/figlet-text-converter/scripts/process-file.js @@ -0,0 +1,192 @@ +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; + +// Get available fonts via npx figlet +function getAvailableFonts() { + try { + const output = execSync('npx figlet --list', { encoding: 'utf-8' }); + // Skip the "Available fonts:" header and filter out empty lines + return output.trim().split('\n').slice(1).map(line => line.trim()).filter(line => line); + } catch (error) { + throw new Error(`Failed to fetch available fonts: ${error.message}`); + } +} + +// Generate ASCII art via npx figlet +function generateAsciiArt(text, font) { + try { + // If no font specified, let figlet use its default (standard) + const fontFlag = font ? `-f "${font}"` : ''; + const output = execSync(`npx figlet ${fontFlag} "${text}"`, { encoding: 'utf-8' }); + return output; + } catch (error) { + throw new Error(`Failed to generate ASCII art: ${error.message}`); + } +} + +// Parse command line arguments +function parseArguments() { + const args = process.argv.slice(2); + if (args.length === 0) { + console.error('Usage: node process-file.js '); + console.error(''); + console.error('This script processes tags in files and replaces them with ASCII art.'); + console.error(''); + console.error('Syntax: Text to convert'); + console.error(' Text to convert (uses standard font by default)'); + process.exit(1); + } + return args[0]; +} + +// Detect comment style from the line +function detectCommentStyle(line) { + const trimmed = line.trimStart(); + + if (trimmed.startsWith('//')) { + return '//'; + } else if (trimmed.startsWith('#')) { + return '#'; + } else if (trimmed.startsWith('--')) { + return '--'; + } else if (trimmed.startsWith('/*')) { + return '/*'; + } + + return null; // plain text, no comment style +} + +// Format ASCII art with comment prefixes +function formatWithComments(asciiArt, commentStyle) { + // Remove trailing empty lines + const lines = asciiArt.split('\n').filter((line, index, arr) => { + // Keep the line if it's not empty, or if it's not the last line + return line.trim().length > 0 || index < arr.length - 1; + }); + + if (!commentStyle) { + return asciiArt.trimEnd(); + } + + switch (commentStyle) { + case '//': + return lines.map(line => `// ${line}`).join('\n'); + + case '#': + return lines.map(line => `# ${line}`).join('\n'); + + case '--': + return lines.map(line => `-- ${line}`).join('\n'); + + case '/*': + // For block comments, each line gets " * " prefix + return lines.map(line => ` * ${line}`).join('\n'); + + default: + return asciiArt.trimEnd(); + } +} + +// Main function +function main() { + const filePath = parseArguments(); + + // Verify file exists + if (!fs.existsSync(filePath)) { + console.error(`āŒ Error: File not found: ${filePath}`); + process.exit(1); + } + + // Read file content + let content = fs.readFileSync(filePath, 'utf-8'); + + // Get available fonts for validation + let availableFonts; + try { + availableFonts = getAvailableFonts(); + } catch (err) { + console.error(`āŒ Error fetching available fonts: ${err.message}`); + process.exit(1); + } + + // Find all figlet tags: text or text + const tagRegex = /(.+?)<\/figlet>/g; + let match; + const replacements = []; + + // Add 'standard' to available fonts since figlet always accepts it as the default + const validFonts = new Set([...availableFonts, 'standard']); + + while ((match = tagRegex.exec(content)) !== null) { + const fullTag = match[0]; + const fontName = match[1] || null; // null means use figlet's default + const textToConvert = match[2]; + const tagIndex = match.index; + + // Validate font if specified + if (fontName && !validFonts.has(fontName)) { + console.error(`āŒ Error: Invalid font "${fontName}" in tag: ${fullTag}`); + console.error(` Run 'node list-fonts.js' to see available fonts.`); + process.exit(1); + } + + // Detect comment style from the line containing the tag + const lineStart = content.lastIndexOf('\n', tagIndex) + 1; + const lineEnd = content.indexOf('\n', tagIndex); + const endPos = lineEnd === -1 ? content.length : lineEnd; + const line = content.substring(lineStart, endPos); + const commentStyle = detectCommentStyle(line); + + replacements.push({ + tag: fullTag, + font: fontName, + text: textToConvert, + commentStyle + }); + } + + // If no tags found, inform user + if (replacements.length === 0) { + console.log(`ā„¹ļø No figlet tags found in: ${filePath}`); + return; + } + + // Process each replacement + for (const replacement of replacements) { + try { + const asciiArt = generateAsciiArt(replacement.text, replacement.font); + const formatted = formatWithComments(asciiArt, replacement.commentStyle); + + // If there's a comment style and the tag is preceded by that comment on the same line, + // we need to replace the comment prefix + tag together (not just the tag). + // This prevents double comment prefixes (e.g., "# #" instead of "#") + if (replacement.commentStyle) { + const escapedComment = replacement.commentStyle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const escapedTag = replacement.tag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + // Match optional leading whitespace, the comment prefix, optional space, then the tag + const commentPrefixPattern = new RegExp(`(^|\\n)\\s*${escapedComment}\\s*${escapedTag}`); + if (commentPrefixPattern.test(content)) { + // Replace both the comment prefix and tag with the formatted ASCII art + content = content.replace(commentPrefixPattern, `$1${formatted}`); + } else { + // No leading comment prefix, just replace the tag + content = content.replace(replacement.tag, formatted); + } + } else { + // No comment style, just replace the tag + content = content.replace(replacement.tag, formatted); + } + } catch (err) { + console.error(`āŒ Error generating ASCII art for "${replacement.text}": ${err.message}`); + process.exit(1); + } + } + + // Write modified content back to file + fs.writeFileSync(filePath, content, 'utf-8'); + + console.log(`āœ… Successfully processed ${replacements.length} figlet tag(s) in: ${filePath}`); +} + +main();