-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmarkdown-basic.js
More file actions
executable file
·143 lines (116 loc) · 3.45 KB
/
markdown-basic.js
File metadata and controls
executable file
·143 lines (116 loc) · 3.45 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
#!/usr/bin/env node
/**
* Basic Markdown rendering example
*
* This example demonstrates how to use cli-html as a library
* to render Markdown content with GitHub Flavored Markdown support.
*/
import { renderMarkdown } from '../../index.js';
// Example 1: Basic Markdown formatting
console.log('=== Example 1: Basic Markdown ===\n');
const basicMarkdown = `
# Welcome to cli-html
This is a **powerful** library for rendering Markdown in the terminal.
It supports *italic*, **bold**, \`inline code\`, and much more!
`;
console.log(renderMarkdown(basicMarkdown));
// Example 2: GitHub Flavored Markdown Alerts
console.log('\n=== Example 2: GFM Alerts ===\n');
const alertsMarkdown = `
> [!NOTE]
> Useful information that users should know, even when skimming content.
> [!TIP]
> Helpful advice for doing things better or more easily.
> [!IMPORTANT]
> Key information users need to know to achieve their goal.
> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.
> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.
`;
console.log(renderMarkdown(alertsMarkdown));
// Example 3: Task Lists
console.log('\n=== Example 3: Task Lists ===\n');
const taskListMarkdown = `
## My Tasks
- [x] Complete the documentation
- [x] Write unit tests
- [ ] Deploy to production
- [ ] Send release notes
`;
console.log(renderMarkdown(taskListMarkdown));
// Example 4: Tables
console.log('\n=== Example 4: Tables ===\n');
const tableMarkdown = `
## Team Members
| Name | Role | Email |
|--------------|------------|-------------------|
| John Doe | Developer | john@example.com |
| Jane Smith | Designer | jane@example.com |
| Bob Johnson | Manager | bob@example.com |
`;
console.log(renderMarkdown(tableMarkdown));
// Example 5: Code Blocks with Syntax Highlighting
console.log('\n=== Example 5: Code Blocks ===\n');
const codeMarkdown = `
## JavaScript Example
\`\`\`javascript
async function fetchUser(id) {
const response = await fetch(\`/api/users/\${id}\`);
const user = await response.json();
return user;
}
const user = await fetchUser(123);
console.log(user);
\`\`\`
## Python Example
\`\`\`python
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
for i in range(10):
print(f"fib({i}) = {fibonacci(i)}")
\`\`\`
`;
console.log(renderMarkdown(codeMarkdown));
// Example 6: Lists and Nested Items
console.log('\n=== Example 6: Nested Lists ===\n');
const nestedListMarkdown = `
## Project Structure
1. Frontend
- React components
- CSS modules
- Redux store
2. Backend
- API routes
- Database models
- Middleware
3. DevOps
- CI/CD pipeline
- Docker configuration
- Monitoring setup
`;
console.log(renderMarkdown(nestedListMarkdown));
// Example 7: Strikethrough and Links
console.log('\n=== Example 7: Strikethrough & Links ===\n');
const mixedMarkdown = `
## Release Notes v2.0
- ~~Old feature removed~~
- New authentication system
- Check out our [documentation](https://github.com/grigorii-horos/cli-html)
- Visit [npm package](https://www.npmjs.com/package/cli-html)
`;
console.log(renderMarkdown(mixedMarkdown));
// Example 8: Blockquotes
console.log('\n=== Example 8: Blockquotes ===\n');
const quoteMarkdown = `
## Inspiration
> "Code is like humor. When you have to explain it, it's bad."
>
> — Cory House
> "First, solve the problem. Then, write the code."
>
> — John Johnson
`;
console.log(renderMarkdown(quoteMarkdown));