-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_md_parser.sh
More file actions
executable file
·136 lines (90 loc) · 2.41 KB
/
example_md_parser.sh
File metadata and controls
executable file
·136 lines (90 loc) · 2.41 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
#!/usr/bin/env bash
# Walk through every feature of the markdown parser with real examples.
# Run this in a terminal to see what each one does.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/board.bash"
source "$SCRIPT_DIR/md_parser.bash"
set_title "md_parser.bash demo"
header "md_parser.bash demo"
center "Rendering all supported markdown elements"
echo
# ------------------------------------------------------------------
title "Source: rendering inline"
echo
info "Render a single string inline:"
echo
rendered="$(_md::inline "This has **bold**, *italic*, \`code\`, and a [link](https://example.com).")"
echo " $rendered"
echo
rendered="$(_md::inline "~~strikethrough~~ and an image  too.")"
echo " $rendered"
echo
# ------------------------------------------------------------------
title "Source: rendering a full document"
echo
info "A markdown document with every supported element:"
echo
cat <<'MARKDOWN' | md::render
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
This is a paragraph with **bold**, *italic*, ~~strikethrough~~, and `inline code`.
Here is a [link to board.bash](https://github.com) and an image .
---
> Blockquotes make text stand out. They can have **bold** and *italic* too.
---
### Lists
Unordered:
- First item
- Second item
- Third item
Ordered:
1. Step one
2. Step two
3. Step three
Task lists:
- [x] Completed task
- [ ] Pending task
- [ ] Another todo
---
### Code blocks
```
#!/bin/bash
echo "Hello, world!"
```
Inline `code` spans work inside paragraphs and headings too.
---
### All headers together
# H1
## H2
### H3
#### H4
##### H5
###### H6
---
### Inline combinations
**Bold with *italic* inside** and *italic with **bold** inside*.
`code with **bold**` and `code with *italic*`.
A [link containing **bold**](https://example.com) and [link with `code`](https://example.com).
That's everything the parser supports.
MARKDOWN
echo
# ------------------------------------------------------------------
title "Source: rendering a file"
echo
info "You can also render a markdown file:"
echo
code " md::render_file README.md"
echo
info "The parser reads from stdin, so piping works too:"
echo
code " cat CHANGELOG.md | md::render"
echo
# ------------------------------------------------------------------
hr
center "See README_MD_PARSER.md for the full reference"
echo
ok "Demo complete"