code.t 3.69 KB
Newer Older
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
. tests/functions.sh

title "code blocks"

rc=0
MARKDOWN_FLAGS=

try 'format for code block html' \
'    this is
    code' \
    '<pre><code>this is
code
</code></pre>'

try 'mismatched backticks' '```tick``' '<p><code>`tick</code></p>'
try 'mismatched backticks(2)' '``tick```' '<p>``tick```</p>'
try 'unclosed single backtick' '`hi there' '<p>`hi there</p>'
try 'unclosed double backtick' '``hi there' '<p>``hi there</p>'
try 'triple backticks' '```hi there```' '<p><code>hi there</code></p>'
try 'quadruple backticks' '````hi there````' '<p><code>hi there</code></p>'
try 'remove space around code' '`` hi there ``' '<p><code>hi there</code></p>'
try 'code containing backticks' '`` a```b ``' '<p><code>a```b</code></p>'
try 'backslash before backtick' '`a\`' '<p><code>a\</code></p>'
try '`>`' '`>`' '<p><code>&gt;</code></p>'
try '`` ` ``' '`` ` ``' '<p><code>`</code></p>'
try '````` ``` `' '````` ``` `' '<p><code>``</code> `</p>'
try '````` ` ```' '````` ` ```' '<p><code>`` `</code></p>'
try 'backslashes in code(1)' '    printf "%s: \n", $1;' \
'<pre><code>printf "%s: \n", $1;
</code></pre>'
try 'backslashes in code(2)' '`printf "%s: \n", $1;`' \
'<p><code>printf "%s: \n", $1;</code></p>'

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
try 'fenced code disabled backtick' \
'```

unrecognized code!
```' \
'<p>```</p>

<p>unrecognized code!
```</p>'

# no <pre/> proves it’s the inline variant of `code` delimitation
try 'fenced code disabled backtick as inline code' \
'```
inline code?
```' \
'<p><code>
inline code?
</code></p>'
52

53 54 55 56 57 58 59 60 61 62 63
try 'fenced code disabled tilde' \
'~~~

unrecognized code!
~~~' \
'<p>~~~</p>

<p>unrecognized code!
~~~</p>'

try -ffencedcode 'fenced code block with blank lines' \
64 65 66 67 68 69 70 71 72 73
'~~~
code!

still code!
~~~' \
    '<pre><code>code!

still code!
</code></pre>'

74
try  -ffencedcode 'fenced code block' \
75 76 77 78 79 80
'~~~
code!
~~~' \
    '<pre><code>code!
</code></pre>'

81
try  -ffencedcode 'fenced code block in list' \
82 83 84 85 86 87 88 89
'1. ~~~
code block
~~~' \
'<ol>
<li><pre><code>code block
</code></pre></li>
</ol>'

90
try  -ffencedcode 'fenced code block in blockquote' \
91 92 93 94 95 96
'>~~~
code
~~~' \
'<blockquote><pre><code>code
</code></pre></blockquote>'

97
try  -ffencedcode 'unterminated fenced code block' \
98 99 100 101 102
'~~~
code' \
'<p>~~~
code</p>'

103
try  -ffencedcode 'fenced code block with tildes' \
104 105 106 107 108 109 110 111 112 113
'~~~~~
~~~
code with tildes
~~~
~~~~~' \
'<pre><code>~~~
code with tildes
~~~
</code></pre>'

114
try  -ffencedcode 'paragraph with trailing fenced block' \
115 116 117 118 119 120 121 122 123 124 125
'text text text
text text text
~~~
code code code?
~~~' \
'<p>text text text
text text text
~~~
code code code?
~~~</p>'

126
try  -ffencedcode 'fenced code blocks with backtick delimiters' \
127 128 129 130 131 132
'```
code
```' \
'<pre><code>code
</code></pre>'

133
try  -ffencedcode 'fenced code block with mismatched delimters' \
134 135 136 137 138 139 140
'```
code
~~~' \
'<p>```
code
~~~</p>'

141
try  -ffencedcode 'fenced code block with lang attribute' \
142 143 144 145 146 147
'```lang
code
```' \
'<pre><code class="lang">code
</code></pre>'

148
try  -ffencedcode 'fenced code block with lang-name attribute' \
149 150 151 152 153 154
'```lang-name
code
```' \
'<pre><code class="lang-name">code
</code></pre>'

155
try  -ffencedcode 'fenced code block with lang_name attribute' \
156 157 158 159 160 161
'```lang_name
code
```' \
'<pre><code class="lang_name">code
</code></pre>'

162
try  -ffencedcode 'fenced code block with lang attribute and space' \
163 164 165 166 167 168
'``` lang
code
```' \
'<pre><code class="lang">code
</code></pre>'

169
try  -ffencedcode 'fenced code block with lang attribute and multiple spaces' \
170 171 172 173 174 175
'```       lang
code
```' \
'<pre><code class="lang">code
</code></pre>'

176
try  -ffencedcode 'fenced code block with lang-name attribute and space' \
177 178 179 180 181 182
'``` lang-name
code
```' \
'<pre><code class="lang-name">code
</code></pre>'

183
try  -ffencedcode 'fenced code block with lang_name attribute and space' \
184 185 186 187 188 189
'``` lang_name
code
```' \
'<pre><code class="lang_name">code
</code></pre>'

190 191
summary $0
exit $rc