markshell
Version:
markshell allows you to output any markdown file formatted and style to the console
101 lines (77 loc) ⢠2.9 kB
JavaScript
/**
* Interactive demonstration of dynamic PrismJS language loading
* Shows syntax highlighting output AND loading statistics
*/
const path = require('path');
const markshell = require(path.join(__dirname, '../lib/index.js'));
const syntaxHighlighter = require(path.join(__dirname, '../lib/syntaxhighlighter'));
const fs = require('fs');
console.log('\nšØ ===== SYNTAX HIGHLIGHTING DEMO WITH DYNAMIC LOADING =====\n');
// Show initial state
console.log('š Initial State:');
console.log(' Loaded languages:', syntaxHighlighter.getLoadedLanguagesInfo());
console.log('');
// Create a test file with multiple languages
const testContent = `# Code Examples
## JavaScript
\`\`\`javascript
const greeting = "Hello World";
console.log(greeting);
\`\`\`
## Python
\`\`\`py
def hello():
print("Hello World")
\`\`\`
## Shell
\`\`\`sh
echo "Hello World"
ls -la
\`\`\`
`;
// Write test file
const testFile = '/tmp/markshell-test.md';
fs.writeFileSync(testFile, testContent);
console.log('š Rendering markdown with syntax highlighting...\n');
console.log('ā'.repeat(80));
// Render the file (this will trigger dynamic loading)
const output = markshell.toConsole(testFile);
console.log('ā'.repeat(80));
console.log('');
// Show what got loaded
console.log('š After Rendering:');
const info = syntaxHighlighter.getLoadedLanguagesInfo();
console.log(' Loaded languages:', info);
console.log(` Total: ${info.count} languages loaded dynamically`);
console.log('');
// Test alias resolution
console.log('š Language Alias Resolution Examples:');
console.log(' js ā', syntaxHighlighter.resolveLanguageAlias('js'));
console.log(' py ā', syntaxHighlighter.resolveLanguageAlias('py'));
console.log(' sh ā', syntaxHighlighter.resolveLanguageAlias('sh'));
console.log(' ts ā', syntaxHighlighter.resolveLanguageAlias('ts'));
console.log(' yml ā', syntaxHighlighter.resolveLanguageAlias('yml'));
console.log('');
// Test highlighting individual code blocks with different themes
console.log('šØ Theme Examples:\n');
const jsCode = 'const x = 42;\nconsole.log(x);';
console.log(' Theme: okaidia (dark)');
console.log(' ā'.repeat(40));
console.log(syntaxHighlighter.highlight(jsCode, 'javascript', 'okaidia'));
console.log('');
console.log(' Theme: tomorrow');
console.log(' ā'.repeat(40));
console.log(syntaxHighlighter.highlight(jsCode, 'javascript', 'tomorrow'));
console.log('');
console.log(' Theme: solarizelight');
console.log(' ā'.repeat(40));
console.log(syntaxHighlighter.highlight(jsCode, 'javascript', 'solarizelight'));
console.log('');
// Final stats
console.log('ā
Demo Complete!');
console.log(` Languages now loaded: ${syntaxHighlighter.getLoadedLanguagesInfo().count}`);
console.log(' All languages loaded on-demand (not at startup)');
console.log('');
// Cleanup
fs.unlinkSync(testFile);