#!/bin/bash set -e check() { input="$(mktemp)" expected_output="$(mktemp)" output="$(mktemp)" current="input" while IFS='$\n' read -r line; do if [[ "$line" == "---" ]]; then current="output" elif [[ "$current" == "input" ]]; then echo "$line" >> "$input" else echo "$line" >> "$expected_output" fi done awk -f markdown.awk "$input" >> "$output" result="success" if ! cmp -s "$output" "$expected_output"; then echo "FAIL" echo "--- input" cat "$input" echo "--- expected" cat "$expected_output" echo "--- got" cat "$output" echo "---" result="fail" else echo "SUCCESS" fi rm "$input" rm "$expected_output" rm "$output" if [[ "$result" == "fail" ]]; then exit 1 fi } check <<-EOF This is a simple sentence. ---
This is a simple sentence.
EOF check <<-EOF This is a simple sentence. ---This is a simple sentence.
EOF check <<-EOF First paragraph. Second paragraph. ---First paragraph.
Second paragraph.
EOF check <<-EOF # Header body ---body
EOF check <<-EOF # Header1 ## Header2 ### Header3 ---bold
EOF check <<-EOF **bold multiline** ---bold multiline
EOF check <<-EOF **bold ---**bold
EOF check <<-"EOF" ``` first line of code second line of code > < & ``` ---
first line of code
second line of code
> < &
EOF
check <<-"EOF"
```
first line of code
second line of code
---
``` first line of code second line of code
EOF check <<-"EOF" This is `inline code` block ---This is inline code
block
code
indented by
spaces
EOF
check <<-"EOF"
asdf
* foo
* bar
- baz
+ qux
---
asdf
asdf
asdf
in list
EOF check <<-"EOF" > foo > > > bar > > baz ---foo bar
EOF check <<-"EOF" > foo > >> bar >> baz ---foo
bar baz
EOF check <<-"EOF" > code blocks > in blockquotes ---foo
bar baz
EOF check <<-"EOF" > A list within a blockquote: > > * asterisk 1 > * asterisk 2 > * asterisk 3 ---code blocks in blockquotes
EOF check <<-"EOF" foo&bar 1 < 2 2 > 1 ---A list within a blockquote:
- asterisk 1
- asterisk 2
- asterisk 3
foo&bar
1 < 2
2 > 1
EOF check <<-"EOF" foo bar --- EOF check <<-"EOF" \\ \` \* \_ \{ \} \[ \] \( \) \> \# \. \! \+ \- ---\
`
*
_
{
}
[
]
(
)
>
#
.
!
+
-
EOF check <<-"EOF" `This shouldn't be escaped: \*` ---This shouldn't be escaped: \*
This shouldn't be escaped: \*
EOF
check <<-"EOF"
Spimple link: [foo](/bar)
Link with title: [foo](/bar "baz")
---
Spimple link: foo
Link with title: foo
EOF check <<-"EOF" Spimple image: ![foo](/bar) Image with title: ![foo](/bar "baz") ---Spimple image:
Image with title:
EOF check <<-"EOF" Horizontal rules: - - - * * * _ _ _ ---Horizontal rules: