-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhtml-basic.js
More file actions
executable file
·144 lines (128 loc) · 3.48 KB
/
html-basic.js
File metadata and controls
executable file
·144 lines (128 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
/**
* Basic HTML rendering example
*
* This example demonstrates how to use cli-html as a library
* to render HTML content in the terminal.
*/
import { renderHTML } from '../../index.js';
// Example 1: Simple HTML with headings and paragraphs
console.log('=== Example 1: Basic HTML ===\n');
const basicHTML = `
<h1>Welcome to cli-html</h1>
<p>This is a <strong>powerful</strong> library for rendering HTML in the terminal.</p>
<p>It supports <em>italic</em>, <strong>bold</strong>, <code>inline code</code>, and much more!</p>
`;
console.log(renderHTML(basicHTML));
// Example 2: Lists
console.log('\n=== Example 2: Lists ===\n');
const listsHTML = `
<h2>Shopping List</h2>
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Bread</li>
</ul>
<h2>Todo List</h2>
<ol>
<li>Wake up</li>
<li>Write code</li>
<li>Deploy to production</li>
</ol>
`;
console.log(renderHTML(listsHTML));
// Example 3: Code blocks with syntax highlighting
console.log('\n=== Example 3: Code Blocks ===\n');
const codeHTML = `
<h2>JavaScript Example</h2>
<pre><code class="language-javascript">
function greet(name) {
console.log(\`Hello, \${name}!\`);
return true;
}
greet('World');
</code></pre>
<h2>Python Example</h2>
<pre><code class="language-python">
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
print(factorial(5))
</code></pre>
`;
console.log(renderHTML(codeHTML));
// Example 4: Tables
console.log('\n=== Example 4: Tables ===\n');
const tableHTML = `
<h2>User Information</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>Admin</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>jane@example.com</td>
<td>User</td>
</tr>
<tr>
<td>Bob Johnson</td>
<td>bob@example.com</td>
<td>Moderator</td>
</tr>
</tbody>
</table>
`;
console.log(renderHTML(tableHTML));
// Example 5: Blockquotes
console.log('\n=== Example 5: Blockquotes ===\n');
const blockquoteHTML = `
<h2>Quote of the Day</h2>
<blockquote>
<p>"The only way to do great work is to love what you do."</p>
<p>— Steve Jobs</p>
</blockquote>
`;
console.log(renderHTML(blockquoteHTML));
// Example 6: Links
console.log('\n=== Example 6: Links ===\n');
const linksHTML = `
<h2>Useful Resources</h2>
<ul>
<li><a href="https://nodejs.org">Node.js Official Site</a></li>
<li><a href="https://github.com">GitHub</a></li>
<li><a href="https://www.npmjs.com">NPM Registry</a></li>
</ul>
`;
console.log(renderHTML(linksHTML));
// Example 7: Custom Inline Styles with data-cli-* attributes
console.log('\n=== Example 7: Custom Inline Styles ===\n');
const customStylesHTML = `
<h2>Custom Colors and Styles</h2>
<p>
This paragraph demonstrates <span data-cli-color="red">red text</span>,
<span data-cli-color="blue bold">blue bold text</span>,
and <span data-cli-color="green italic">green italic text</span>.
</p>
<h1 data-cli-color="magenta bold" data-cli-marker="►">Magenta Bold Header with Triangle</h1>
<h2 data-cli-color="cyan" data-cli-marker="•••">Cyan Header with Dots</h2>
<blockquote data-cli-color="yellow" data-cli-marker="▌ ">
This is a yellow blockquote with custom marker.
</blockquote>
<p>
Text styles: <strong data-cli-color="red">red bold</strong>,
<em data-cli-color="blue italic">blue italic</em>,
<mark data-cli-color="yellowBright">bright yellow mark</mark>
</p>
`;
console.log(renderHTML(customStylesHTML));