1// Unit tests for inline parsing 2 3package mmark 4 5import ( 6 "regexp" 7 "testing" 8 9 "strings" 10) 11 12func runMarkdownInline(input string, extensions, htmlFlags int, params HtmlRendererParameters) string { 13 extensions |= EXTENSION_AUTOLINK 14 15 renderer := HtmlRendererWithParameters(htmlFlags, "", "", params) 16 17 return Parse([]byte(input), renderer, extensions).String() 18} 19 20func doTestsInline(t *testing.T, tests []string) { 21 doTestsInlineParam(t, tests, 0, 0, HtmlRendererParameters{}) 22} 23 24func doLinkTestsInline(t *testing.T, tests []string) { 25 doTestsInline(t, tests) 26 27 prefix := "http://localhost" 28 params := HtmlRendererParameters{AbsolutePrefix: prefix} 29 transformTests := transformLinks(tests, prefix) 30 doTestsInlineParam(t, transformTests, 0, 0, params) 31 doTestsInlineParam(t, transformTests, 0, commonHtmlFlags, params) 32} 33 34func doSafeTestsInline(t *testing.T, tests []string) { 35 doTestsInlineParam(t, tests, 0, HTML_SAFELINK, HtmlRendererParameters{}) 36 37 // All the links in this test should not have the prefix appended, so 38 // just rerun it with different parameters and the same expectations. 39 prefix := "http://localhost" 40 params := HtmlRendererParameters{AbsolutePrefix: prefix} 41 transformTests := transformLinks(tests, prefix) 42 doTestsInlineParam(t, transformTests, 0, HTML_SAFELINK, params) 43} 44 45func doTestsInlineParam(t *testing.T, tests []string, extensions, htmlFlags int, 46 params HtmlRendererParameters) { 47 // catch and report panics 48 var candidate string 49 /* 50 defer func() { 51 if err := recover(); err != nil { 52 t.Errorf("\npanic while processing [%#v] (%v)\n", candidate, err) 53 } 54 }() 55 */ 56 57 for i := 0; i+1 < len(tests); i += 2 { 58 input := tests[i] 59 candidate = input 60 expected := tests[i+1] 61 actual := runMarkdownInline(candidate, extensions, htmlFlags, params) 62 if actual != expected { 63 t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", 64 candidate, expected, actual) 65 } 66 67 // now test every substring to stress test bounds checking 68 if !testing.Short() { 69 for start := 0; start < len(input); start++ { 70 for end := start + 1; end <= len(input); end++ { 71 candidate = input[start:end] 72 _ = runMarkdownInline(candidate, extensions, htmlFlags, params) 73 } 74 } 75 } 76 } 77} 78 79func transformLinks(tests []string, prefix string) []string { 80 newTests := make([]string, len(tests)) 81 anchorRe := regexp.MustCompile(`<a href="/(.*?)"`) 82 imgRe := regexp.MustCompile(`<img src="/(.*?)"`) 83 for i, test := range tests { 84 if i%2 == 1 { 85 test = anchorRe.ReplaceAllString(test, `<a href="`+prefix+`/$1"`) 86 test = imgRe.ReplaceAllString(test, `<img src="`+prefix+`/$1"`) 87 } 88 newTests[i] = test 89 } 90 return newTests 91} 92 93func TestEmphasis(t *testing.T) { 94 var tests = []string{ 95 "nothing inline\n", 96 "<p>nothing inline</p>\n", 97 98 "simple *inline* test\n", 99 "<p>simple <em>inline</em> test</p>\n", 100 101 "*at the* beginning\n", 102 "<p><em>at the</em> beginning</p>\n", 103 104 "at the *end*\n", 105 "<p>at the <em>end</em></p>\n", 106 107 "*try two* in *one line*\n", 108 "<p><em>try two</em> in <em>one line</em></p>\n", 109 110 "over *two\nlines* test\n", 111 "<p>over <em>two\nlines</em> test</p>\n", 112 113 "odd *number of* markers* here\n", 114 "<p>odd <em>number of</em> markers* here</p>\n", 115 116 "odd *number\nof* markers* here\n", 117 "<p>odd <em>number\nof</em> markers* here</p>\n", 118 119 "simple _inline_ test\n", 120 "<p>simple <em>inline</em> test</p>\n", 121 122 "_at the_ beginning\n", 123 "<p><em>at the</em> beginning</p>\n", 124 125 "at the _end_\n", 126 "<p>at the <em>end</em></p>\n", 127 128 "_try two_ in _one line_\n", 129 "<p><em>try two</em> in <em>one line</em></p>\n", 130 131 "over _two\nlines_ test\n", 132 "<p>over <em>two\nlines</em> test</p>\n", 133 134 "odd _number of_ markers_ here\n", 135 "<p>odd <em>number of</em> markers_ here</p>\n", 136 137 "odd _number\nof_ markers_ here\n", 138 "<p>odd <em>number\nof</em> markers_ here</p>\n", 139 140 "mix of *markers_\n", 141 "<p>mix of *markers_</p>\n", 142 143 "This is un*believe*able! This d_oe_s not work!\n", 144 "<p>This is un<em>believe</em>able! This d_oe_s not work!</p>\n", 145 146 "This is un**believe**able! This d_oe_s not work!\n", 147 "<p>This is un<strong>believe</strong>able! This d_oe_s not work!</p>\n", 148 149 "_does_ work\n", 150 "<p><em>does</em> work</p>\n", 151 152 "This is a * literal asterisk as is this *\n", 153 "<p>This is a * literal asterisk as is this *</p>\n", 154 155 "These are ** two literal asterisk.\n", 156 "<p>These are ** two literal asterisk.</p>\n", 157 158 "As \\*are\\* these!\n", 159 "<p>As *are* these!</p>\n", 160 161 "This is an underscore _ and a _word_\n", 162 "<p>This is an underscore _ and a <em>word</em></p>\n", 163 164 "This is a not a literal one *hallo there!*\n", 165 "<p>This is a not a literal one <em>hallo there!</em></p>\n", 166 167 "**This**", 168 "<p><strong>This</strong></p>\n", 169 170 "*What is A\\* algorithm?*\n", 171 "<p><em>What is A* algorithm?</em></p>\n", 172 } 173 doTestsInline(t, tests) 174} 175 176func TestStrong(t *testing.T) { 177 var tests = []string{ 178 "nothing inline\n", 179 "<p>nothing inline</p>\n", 180 181 "simple **inline** test\n", 182 "<p>simple <strong>inline</strong> test</p>\n", 183 184 "**at the** beginning\n", 185 "<p><strong>at the</strong> beginning</p>\n", 186 187 "at the **end**\n", 188 "<p>at the <strong>end</strong></p>\n", 189 190 "**try two** in **one line**\n", 191 "<p><strong>try two</strong> in <strong>one line</strong></p>\n", 192 193 "over **two\nlines** test\n", 194 "<p>over <strong>two\nlines</strong> test</p>\n", 195 196 "odd **number of** markers** here\n", 197 "<p>odd <strong>number of</strong> markers** here</p>\n", 198 199 "odd **number\nof** markers** here\n", 200 "<p>odd <strong>number\nof</strong> markers** here</p>\n", 201 202 "simple __inline__ test\n", 203 "<p>simple <strong>inline</strong> test</p>\n", 204 205 "__at the__ beginning\n", 206 "<p><strong>at the</strong> beginning</p>\n", 207 208 "at the __end__\n", 209 "<p>at the <strong>end</strong></p>\n", 210 211 "__try two__ in __one line__\n", 212 "<p><strong>try two</strong> in <strong>one line</strong></p>\n", 213 214 "over __two\nlines__ test\n", 215 "<p>over <strong>two\nlines</strong> test</p>\n", 216 217 "odd __number of__ markers__ here\n", 218 "<p>odd <strong>number of</strong> markers__ here</p>\n", 219 220 "odd __number\nof__ markers__ here\n", 221 "<p>odd <strong>number\nof</strong> markers__ here</p>\n", 222 223 "mix of **markers__\n", 224 "<p>mix of **markers__</p>\n", 225 226 "**`/usr`** : this folder is named `usr`\n", 227 "<p><strong><code>/usr</code></strong> : this folder is named <code>usr</code></p>\n", 228 229 "**`/usr`** :\n\n this folder is named `usr`\n", 230 "<p><strong><code>/usr</code></strong> :</p>\n\n<p>this folder is named <code>usr</code></p>\n", 231 } 232 doTestsInline(t, tests) 233} 234 235func TestEmphasisMix(t *testing.T) { 236 var tests = []string{ 237 "***triple emphasis***\n", 238 "<p><strong><em>triple emphasis</em></strong></p>\n", 239 240 "***triple\nemphasis***\n", 241 "<p><strong><em>triple\nemphasis</em></strong></p>\n", 242 243 "___triple emphasis___\n", 244 "<p><strong><em>triple emphasis</em></strong></p>\n", 245 246 "***triple emphasis___\n", 247 "<p>***triple emphasis___</p>\n", 248 249 "*__triple emphasis__*\n", 250 "<p><em><strong>triple emphasis</strong></em></p>\n", 251 252 "__*triple emphasis*__\n", 253 "<p><strong><em>triple emphasis</em></strong></p>\n", 254 255 "**improper *nesting** is* bad\n", 256 "<p><strong>improper *nesting</strong> is* bad</p>\n", 257 258 "*improper **nesting* is** bad\n", 259 "<p>*improper <strong>nesting* is</strong> bad</p>\n", 260 } 261 doTestsInline(t, tests) 262} 263 264func TestEmphasisLink(t *testing.T) { 265 var tests = []string{ 266 "[first](before) *text[second] (inside)text* [third](after)\n", 267 "<p><a href=\"before\">first</a> <em>text<a href=\"inside\">second</a>text</em> <a href=\"after\">third</a></p>\n", 268 269 "*incomplete [link] definition*\n", 270 "<p><em>incomplete [link] definition</em></p>\n", 271 272 "*it's [emphasis*] (not link)\n", 273 "<p><em>it's [emphasis</em>] (not link)</p>\n", 274 275 "*it's [emphasis*] and *[asterisk]\n", 276 "<p><em>it's [emphasis</em>] and *[asterisk]</p>\n", 277 } 278 doTestsInline(t, tests) 279} 280 281func TestStrikeThrough(t *testing.T) { 282 var tests = []string{ 283 "nothing inline\n", 284 "<p>nothing inline</p>\n", 285 286 "simple ~~inline~~ test\n", 287 "<p>simple <del>inline</del> test</p>\n", 288 289 "~~at the~~ beginning\n", 290 "<p><del>at the</del> beginning</p>\n", 291 292 "at the ~~end~~\n", 293 "<p>at the <del>end</del></p>\n", 294 295 "~~try two~~ in ~~one line~~\n", 296 "<p><del>try two</del> in <del>one line</del></p>\n", 297 298 "over ~~two\nlines~~ test\n", 299 "<p>over <del>two\nlines</del> test</p>\n", 300 301 "odd ~~number of~~ markers~~ here\n", 302 "<p>odd <del>number of</del> markers~~ here</p>\n", 303 304 "odd ~~number\nof~~ markers~~ here\n", 305 "<p>odd <del>number\nof</del> markers~~ here</p>\n", 306 } 307 doTestsInline(t, tests) 308} 309 310func TestSubscript(t *testing.T) { 311 var tests = []string{ 312 "H~2~O is a liquid. is 1024. but this is ~~strikethrough~~ text\n", 313 "<p>H<sub>2</sub>O is a liquid. is 1024. but this is <del>strikethrough</del> text</p>\n", 314 315 "~[hallo](http:/ddssd)~", 316 "<p><sub><a href=\"http:/ddssd\">hallo</a></sub></p>\n", 317 318 "~subtext~ and some other ~subtext~", 319 "<p><sub>subtext</sub> and some other <sub>subtext</sub></p>\n", 320 321 "no~thing inline\n", 322 "<p>no~thing inline</p>\n", 323 324 "simple ~~in~l~ine~~ test\n", 325 "<p>simple <del>in<sub>l</sub>ine</del> test</p>\n", 326 327 "~odd ~~number o~~ markers~~ here\n", 328 "<p>~odd <del>number o</del> markers~~ here</p>\n", 329 330 "~subtext~ and some other ~subtext~", 331 "<p><sub>subtext</sub> and some other <sub>subtext</sub></p>\n", 332 333 " ~subtext~ and some other ~subtext~ ", 334 "<p><sub>subtext</sub> and some other <sub>subtext</sub></p>\n", 335 336 "odd ~~number\nof~~ ma~~rkers~ her~e~\n", 337 "<p>odd <del>number\nof</del> ma~<sub>rkers</sub> her<sub>e</sub></p>\n", 338 339 "~boo ~bla", 340 "<p>~boo ~bla</p>\n", 341 342 "~boo\\ ~bla", 343 "<p><sub>boo </sub>bla</p>\n", 344 345 "\\^not sub\\^", 346 "<p>^not sub^</p>\n", 347 } 348 doTestsInline(t, tests) 349} 350 351func TestSuperscript(t *testing.T) { 352 var tests = []string{ 353 "H~2~O is a liquid. 2^10^ is 1024. but this is ~~strikethrough~~ text\n", 354 "<p>H<sub>2</sub>O is a liquid. 2<sup>10</sup> is 1024. but this is <del>strikethrough</del> text</p>\n", 355 356 "^[hallo](http:/ddssd)^", 357 "<p><sup><a href=\"http:/ddssd\">hallo</a></sup></p>\n", 358 359 "^[hallo]^ is superscript, not a footnote.", 360 "<p><sup>[hallo]</sup> is superscript, not a footnote.</p>\n", 361 362 "^[^]", 363 "<p><sup>[</sup>]</p>\n", 364 365 "^[a^]", 366 "<p><sup>[a</sup>]</p>\n", 367 368 "types ^inlinenote and [^2] footnote", 369 "<p>types ^inlinenote and [^2] footnote</p>\n", 370 371 "types ^[inlinenote] of ^[other inline with a [hallo](http://miek.nl) notes]", 372 "<p>types ^[inlinenote] of ^[other inline with a <a href=\"http://miek.nl\">hallo</a> notes]</p>\n", 373 374 "^[hallo](http://miek.nl)^", 375 "<p><sup><a href=\"http://miek.nl\">hallo</a></sup></p>\n", 376 377 "^boo ^bla", 378 "<p>^boo ^bla</p>\n", 379 380 "^boo\\ ^bla", 381 "<p><sup>boo </sup>bla</p>\n", 382 383 "P~a\\ cat~", 384 "<p>P<sub>a cat</sub></p>\n", 385 386 "\\^not sup\\^", 387 "<p>^not sup^</p>\n", 388 } 389 doTestsInline(t, tests) 390} 391 392func TestCodeSpan(t *testing.T) { 393 var tests = []string{ 394 "`source code`\n", 395 "<p><code>source code</code></p>\n", 396 397 "` source code with spaces `\n", 398 "<p><code>source code with spaces</code></p>\n", 399 400 "` source code with spaces `not here\n", 401 "<p><code>source code with spaces</code>not here</p>\n", 402 403 "a `single marker\n", 404 "<p>a `single marker</p>\n", 405 406 "a single multi-tick marker with ``` no text\n", 407 "<p>a single multi-tick marker with ``` no text</p>\n", 408 409 "markers with ` ` a space\n", 410 "<p>markers with a space</p>\n", 411 412 "`source code` and a `stray\n", 413 "<p><code>source code</code> and a `stray</p>\n", 414 415 "`source *with* _awkward characters_ in it`\n", 416 "<p><code>source *with* _awkward characters_ in it</code></p>\n", 417 418 "`split over\ntwo lines`\n", 419 "<p><code>split over\ntwo lines</code></p>\n", 420 421 "```multiple ticks``` for the marker\n", 422 "<p><code>multiple ticks</code> for the marker</p>\n", 423 424 "```multiple ticks `with` ticks inside```\n", 425 "<p><code>multiple ticks `with` ticks inside</code></p>\n", 426 } 427 doTestsInline(t, tests) 428} 429 430func TestLineBreak(t *testing.T) { 431 var tests = []string{ 432 "this line \nhas a break\n", 433 "<p>this line<br>\nhas a break</p>\n", 434 435 "this line \ndoes not\n", 436 "<p>this line\ndoes not</p>\n", 437 438 "this line\\\ndoes also!\n", 439 "<p>this line<br>\ndoes also!</p>\n", 440 441 "this line\\ \ndoes not\n", 442 "<p>this line\\\ndoes not</p>\n", 443 444 "this has an \nextra space\n", 445 "<p>this has an<br>\nextra space</p>\n", 446 } 447 doTestsInline(t, tests) 448 449 tests = []string{ 450 "this line \nhas a break\n", 451 "<p>this line<br>\nhas a break</p>\n", 452 453 "this line \ndoes not\n", 454 "<p>this line\ndoes not</p>\n", 455 456 "this line\\\nhas a break\n", 457 "<p>this line<br>\nhas a break</p>\n", 458 459 "this line\\ \ndoes not\n", 460 "<p>this line\\\ndoes not</p>\n", 461 462 "this has an \nextra space\n", 463 "<p>this has an<br>\nextra space</p>\n", 464 } 465 doTestsInlineParam(t, tests, EXTENSION_BACKSLASH_LINE_BREAK, 0, HtmlRendererParameters{}) 466} 467 468func TestInlineLink(t *testing.T) { 469 var tests = []string{ 470 "[foo](/bar/)\n", 471 "<p><a href=\"/bar/\">foo</a></p>\n", 472 473 "[foo with a title](/bar/ \"title\")\n", 474 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n", 475 476 "[foo with a title](/bar/\t\"title\")\n", 477 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n", 478 479 "[foo with a title](/bar/ \"title\" )\n", 480 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n", 481 482 "[foo with a title](/bar/ title with no quotes)\n", 483 "<p><a href=\"/bar/ title with no quotes\">foo with a title</a></p>\n", 484 485 "[foo]()\n", 486 "<p>[foo]()</p>\n", 487 488 "![foo](/bar/)\n", 489 "<p><figure><img src=\"/bar/\" alt=\"foo\"></figure></p>\n", 490 491 "![foo with a title](/bar/ \"title\")\n", 492 "<p><figure><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\"><figcaption>title</figcaption></figure></p>\n", 493 494 "![foo with a title](/bar/\t\"title\")\n", 495 "<p><figure><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\"><figcaption>title</figcaption></figure></p>\n", 496 497 "![foo with a title](/bar/ \"title\" )\n", 498 "<p><figure><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\"><figcaption>title</figcaption></figure></p>\n", 499 500 "![foo with a title](/bar/ title with no quotes)\n", 501 "<p><figure><img src=\"/bar/ title with no quotes\" alt=\"foo with a title\"></figure></p>\n", 502 503 "![](img.jpg)\n", 504 "<p><figure><img src=\"img.jpg\" alt=\"\"></figure></p>\n", 505 506 "[link](url)\n", 507 "<p><a href=\"url\">link</a></p>\n", 508 509 "![foo]()\n", 510 "<p>![foo]()</p>\n", 511 512 "[a link]\t(/with_a_tab/)\n", 513 "<p><a href=\"/with_a_tab/\">a link</a></p>\n", 514 515 "[a link] (/with_spaces/)\n", 516 "<p><a href=\"/with_spaces/\">a link</a></p>\n", 517 518 "[text (with) [[nested] (brackets)]](/url/)\n", 519 "<p><a href=\"/url/\">text (with) [[nested] (brackets)]</a></p>\n", 520 521 "[text (with) [broken nested] (brackets)]](/url/)\n", 522 "<p>[text (with) <a href=\"brackets\">broken nested</a>]](/url/)</p>\n", 523 524 "[text\nwith a newline](/link/)\n", 525 "<p><a href=\"/link/\">text\nwith a newline</a></p>\n", 526 527 "[text in brackets] [followed](/by a link/)\n", 528 "<p>[text in brackets] <a href=\"/by a link/\">followed</a></p>\n", 529 530 "[link with\\] a closing bracket](/url/)\n", 531 "<p><a href=\"/url/\">link with] a closing bracket</a></p>\n", 532 533 "[link with\\[ an opening bracket](/url/)\n", 534 "<p><a href=\"/url/\">link with[ an opening bracket</a></p>\n", 535 536 "[link with\\) a closing paren](/url/)\n", 537 "<p><a href=\"/url/\">link with) a closing paren</a></p>\n", 538 539 "[link with\\( an opening paren](/url/)\n", 540 "<p><a href=\"/url/\">link with( an opening paren</a></p>\n", 541 542 "[link]( with whitespace)\n", 543 "<p><a href=\"with whitespace\">link</a></p>\n", 544 545 "[link]( with whitespace )\n", 546 "<p><a href=\"with whitespace\">link</a></p>\n", 547 548 "[![image](someimage)](with image)\n", 549 "<p><a href=\"with image\"><figure><img src=\"someimage\" alt=\"image\"></figure></a></p>\n", 550 551 "[link](url \"one quote)\n", 552 "<p><a href=\"url "one quote\">link</a></p>\n", 553 554 "[link](url 'one quote)\n", 555 "<p><a href=\"url 'one quote\">link</a></p>\n", 556 557 "[link](<url>)\n", 558 "<p><a href=\"url\">link</a></p>\n", 559 560 "[link & ampersand](/url/)\n", 561 "<p><a href=\"/url/\">link & ampersand</a></p>\n", 562 563 "[link & ampersand](/url/)\n", 564 "<p><a href=\"/url/\">link & ampersand</a></p>\n", 565 566 "[link](/url/&query)\n", 567 "<p><a href=\"/url/&query\">link</a></p>\n", 568 569 "[[t]](/t)\n", 570 "<p><a href=\"/t\">[t]</a></p>\n", 571 572 // Issue #126 on blackfriday 573 "[Chef](https://en.wikipedia.org/wiki/Chef_(film))\n", 574 "<p><a href=\"https://en.wikipedia.org/wiki/Chef_(film)\">Chef</a></p>\n", 575 576 "[Chef](https://en.wikipedia.org/wiki/Chef_(film)_moretext)\n", 577 "<p><a href=\"https://en.wikipedia.org/wiki/Chef_(film)_moretext\">Chef</a></p>\n", 578 579 // Issue 116 in blackfriday 580 "![](http://www.broadgate.co.uk/Content/Upload/DetailImages/Cyclus700(1).jpg)", 581 "<p><figure><img src=\"http://www.broadgate.co.uk/Content/Upload/DetailImages/Cyclus700(1).jpg\" alt=\"\"></figure></p>\n", 582 583 // no closing ), autolinking detects the url next 584 "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation) is the", 585 "<p>[disambiguation](<a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation\">http://en.wikipedia.org/wiki/Disambiguation_(disambiguation</a>) is the</p>\n", 586 587 "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)) is the", 588 "<p><a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)\">disambiguation</a> is the</p>\n", 589 590 "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation))", 591 "<p><a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)\">disambiguation</a></p>\n", 592 } 593 doLinkTestsInline(t, tests) 594 595} 596 597func TestNofollowLink(t *testing.T) { 598 var tests = []string{ 599 "[foo](http://bar.com/foo/)\n", 600 "<p><a href=\"http://bar.com/foo/\" rel=\"nofollow\">foo</a></p>\n", 601 602 "[foo](/bar/)\n", 603 "<p><a href=\"/bar/\">foo</a></p>\n", 604 } 605 doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_NOFOLLOW_LINKS, 606 HtmlRendererParameters{}) 607} 608 609func TestMath(t *testing.T) { 610 var tests = []string{ 611 "{#eq1}\n $$ E = MC^2 $$", 612 "<p><span id=\"eq1\" class=\"math\">\\[ E = MC^2 \\]</span></p>\n", 613 614 "Another paragraph, with some inline math $$x^2$$", 615 "<p>Another paragraph, with some inline math <span class=\"math\">\\(x^2\\)</span></p>\n", 616 617 "$$ E = MC^2 $$", 618 "<p><span class=\"math\">\\[ E = MC^2 \\]</span></p>\n", 619 620 "$$ E = MC^2 $$ not so much $$ again yes $$", 621 "<p><span class=\"math\">\\( E = MC^2 \\)</span> not so much <span class=\"math\">\\( again yes \\)</span></p>\n", 622 623 "you can use $$\\Phi = \\Phi + 1$$ in your source code.", 624 "<p>you can use <span class=\"math\">\\(\\Phi = \\Phi + 1\\)</span> in your source code.</p>\n", 625 } 626 doTestsInlineParam(t, tests, EXTENSION_MATH, 0, HtmlRendererParameters{}) 627} 628 629func TestHrefTargetBlank(t *testing.T) { 630 var tests = []string{ 631 // internal link 632 "[foo](/bar/)\n", 633 "<p><a href=\"/bar/\">foo</a></p>\n", 634 635 "[foo](http://example.com)\n", 636 "<p><a href=\"http://example.com\" target=\"_blank\">foo</a></p>\n", 637 } 638 doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_HREF_TARGET_BLANK, HtmlRendererParameters{}) 639} 640 641func TestSafeInlineLink(t *testing.T) { 642 var tests = []string{ 643 "[foo](/bar/)\n", 644 "<p><a href=\"/bar/\">foo</a></p>\n", 645 646 "[foo](http://bar/)\n", 647 "<p><a href=\"http://bar/\">foo</a></p>\n", 648 649 "[foo](https://bar/)\n", 650 "<p><a href=\"https://bar/\">foo</a></p>\n", 651 652 "[foo](ftp://bar/)\n", 653 "<p><a href=\"ftp://bar/\">foo</a></p>\n", 654 655 "[foo](mailto://bar/)\n", 656 "<p><a href=\"mailto://bar/\">foo</a></p>\n", 657 658 // Not considered safe 659 "[foo](baz://bar/)\n", 660 "<p><tt>foo</tt></p>\n", 661 } 662 doSafeTestsInline(t, tests) 663} 664 665func TestReferenceLink(t *testing.T) { 666 var tests = []string{ 667 "[link][ref]\n", 668 "<p>[link][ref]</p>\n", 669 670 "[link][ref]\n [ref]: /url/ \"title\"\n", 671 "<p><a href=\"/url/\" title=\"title\">link</a></p>\n", 672 673 "[link][ref]\n [ref]: /url/\n", 674 "<p><a href=\"/url/\">link</a></p>\n", 675 676 " [ref]: /url/\n", 677 "", 678 679 " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n", 680 "", 681 682 " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n [4spaces]: /url/\n", 683 "<pre><code>[4spaces]: /url/\n</code></pre>\n", 684 685 "[hmm](ref2)\n [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n", 686 "<p><a href=\"ref2\">hmm</a></p>\n", 687 688 "[ref]\n", 689 "<p>[ref]</p>\n", 690 691 "[ref]\n [ref]: /url/ \"title\"\n", 692 "<p><a href=\"/url/\" title=\"title\">ref</a></p>\n", 693 694 "[link][ref]\n [ref]: /url/", 695 "<p><a href=\"/url/\">link</a></p>\n", 696 697 // Issue 172 in blackfriday 698 "[]:<", 699 "<p>[]:<</p>\n", 700 } 701 doLinkTestsInline(t, tests) 702} 703 704func TestTags(t *testing.T) { 705 var tests = []string{ 706 "a <span>tag</span>\n", 707 "<p>a <span>tag</span></p>\n", 708 709 "<span>tag</span>\n", 710 "<p><span>tag</span></p>\n", 711 712 "<span>mismatch</spandex>\n", 713 "<p><span>mismatch</spandex></p>\n", 714 715 "a <singleton /> tag\n", 716 "<p>a <singleton /> tag</p>\n", 717 } 718 doTestsInline(t, tests) 719} 720 721func TestAutoLink(t *testing.T) { 722 var tests = []string{ 723 "http://foo.com/\n", 724 "<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 725 726 "1 http://foo.com/\n", 727 "<p>1 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 728 729 "1http://foo.com/\n", 730 "<p>1<a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 731 732 "1.http://foo.com/\n", 733 "<p>1.<a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 734 735 "1. http://foo.com/\n", 736 "<ol>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ol>\n", 737 738 "-http://foo.com/\n", 739 "<p>-<a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 740 741 "- http://foo.com/\n", 742 "<ul>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ul>\n", 743 744 "_http://foo.com/\n", 745 "<p>_<a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 746 747 "令狐http://foo.com/\n", 748 "<p>令狐<a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 749 750 "令狐 http://foo.com/\n", 751 "<p>令狐 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 752 753 "ahttp://foo.com/\n", 754 "<p>ahttp://foo.com/</p>\n", 755 756 ">http://foo.com/\n", 757 "<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n", 758 759 "> http://foo.com/\n", 760 "<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n", 761 762 "go to <http://foo.com/>\n", 763 "<p>go to <a href=\"http://foo.com/\">http://foo.com/</a></p>\n", 764 765 "a secure <https://link.org>\n", 766 "<p>a secure <a href=\"https://link.org\">https://link.org</a></p>\n", 767 768 "an email <mailto:some@one.com>\n", 769 "<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n", 770 771 "an email <mailto://some@one.com>\n", 772 "<p>an email <a href=\"mailto://some@one.com\">some@one.com</a></p>\n", 773 774 "an email <some@one.com>\n", 775 "<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n", 776 777 "an ftp <ftp://old.com>\n", 778 "<p>an ftp <a href=\"ftp://old.com\">ftp://old.com</a></p>\n", 779 780 "an ftp <ftp:old.com>\n", 781 "<p>an ftp <a href=\"ftp:old.com\">ftp:old.com</a></p>\n", 782 783 "a link with <http://new.com?query=foo&bar>\n", 784 "<p>a link with <a href=\"http://new.com?query=foo&bar\">" + 785 "http://new.com?query=foo&bar</a></p>\n", 786 787 "quotes mean a tag <http://new.com?query=\"foo\"&bar>\n", 788 "<p>quotes mean a tag <http://new.com?query=\"foo\"&bar></p>\n", 789 790 "quotes mean a tag <http://new.com?query='foo'&bar>\n", 791 "<p>quotes mean a tag <http://new.com?query='foo'&bar></p>\n", 792 793 "unless escaped <http://new.com?query=\\\"foo\\\"&bar>\n", 794 "<p>unless escaped <a href=\"http://new.com?query="foo"&bar\">" + 795 "http://new.com?query="foo"&bar</a></p>\n", 796 797 "even a > can be escaped <http://new.com?q=\\>&etc>\n", 798 "<p>even a > can be escaped <a href=\"http://new.com?q=>&etc\">" + 799 "http://new.com?q=>&etc</a></p>\n", 800 801 "<a href=\"http://fancy.com\">http://fancy.com</a>\n", 802 "<p><a href=\"http://fancy.com\">http://fancy.com</a></p>\n", 803 804 "<a href=\"http://fancy.com\">This is a link</a>\n", 805 "<p><a href=\"http://fancy.com\">This is a link</a></p>\n", 806 807 "<a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a>\n", 808 "<p><a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a></p>\n", 809 810 "(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (\n", 811 "<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (</p>\n", 812 813 "(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).\n", 814 "<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).</p>\n", 815 816 "http://www.foo.com<br>\n", 817 "<p><a href=\"http://www.foo.com\">http://www.foo.com</a><br></p>\n", 818 819 "http://foo.com/viewtopic.php?f=18&t=297", 820 "<p><a href=\"http://foo.com/viewtopic.php?f=18&t=297\">http://foo.com/viewtopic.php?f=18&t=297</a></p>\n", 821 822 "http://foo.com/viewtopic.php?param="18"zz", 823 "<p><a href=\"http://foo.com/viewtopic.php?param="18"zz\">http://foo.com/viewtopic.php?param="18"zz</a></p>\n", 824 825 "http://foo.com/viewtopic.php?param="18"", 826 "<p><a href=\"http://foo.com/viewtopic.php?param="18"\">http://foo.com/viewtopic.php?param="18"</a></p>\n", 827 } 828 doLinkTestsInline(t, tests) 829} 830 831var footnoteTests = []string{ 832 "testing footnotes.[^a]\n\n[^a]: This is the note\n", 833 `<p>testing footnotes.<sup class="footnote-ref" id="fnref:a"><a class="footnote" href="#fn:a">1</a></sup></p> 834<div class="footnotes"> 835 836<hr> 837 838<ol> 839<li id="fn:a">This is the note 840</li> 841</ol> 842</div> 843`, 844 845 `testing long[^b] notes. 846 847[^b]: Paragraph 1 848 849 Paragraph 2 850 851 ` + "```\n\tsome code\n\t```" + ` 852 853 Paragraph 3 854 855No longer in the footnote 856`, 857 `<p>testing long<sup class="footnote-ref" id="fnref:b"><a class="footnote" href="#fn:b">1</a></sup> notes.</p> 858 859<p>No longer in the footnote</p> 860<div class="footnotes"> 861 862<hr> 863 864<ol> 865<li id="fn:b"><p>Paragraph 1</p> 866 867<p>Paragraph 2</p> 868 869<p><code>some code</code></p> 870 871<p>Paragraph 3</p> 872</li> 873</ol> 874</div> 875`, 876 877 `testing[^c] multiple[^d] notes. 878 879[^c]: this is [note] c 880 881 882omg 883 884[^d]: this is note d 885 886what happens here 887 888[note]: /link/c 889 890`, 891 `<p>testing<sup class="footnote-ref" id="fnref:c"><a class="footnote" href="#fn:c">1</a></sup> multiple<sup class="footnote-ref" id="fnref:d"><a class="footnote" href="#fn:d">2</a></sup> notes.</p> 892 893<p>omg</p> 894 895<p>what happens here</p> 896<div class="footnotes"> 897 898<hr> 899 900<ol> 901<li id="fn:c">this is <a href="/link/c">note</a> c 902</li> 903<li id="fn:d">this is note d 904</li> 905</ol> 906</div> 907`, 908 909 "testing inline^[this is the note] notes.\n", 910 `<p>testing inline<sup class="footnote-ref" id="fnref:this-is-the-note"><a class="footnote" href="#fn:this-is-the-note">1</a></sup> notes.</p> 911<div class="footnotes"> 912 913<hr> 914 915<ol> 916<li id="fn:this-is-the-note">this is the note</li> 917</ol> 918</div> 919`, 920 921 "testing multiple[^1] types^[inline note] of notes[^2]\n\n[^2]: the second deferred note\n[^1]: the first deferred note\n\n\twhich happens to be a block\n", 922 `<p>testing multiple<sup class="footnote-ref" id="fnref:1"><a class="footnote" href="#fn:1">1</a></sup> types<sup class="footnote-ref" id="fnref:inline-note"><a class="footnote" href="#fn:inline-note">2</a></sup> of notes<sup class="footnote-ref" id="fnref:2"><a class="footnote" href="#fn:2">3</a></sup></p> 923<div class="footnotes"> 924 925<hr> 926 927<ol> 928<li id="fn:1"><p>the first deferred note</p> 929 930<p>which happens to be a block</p> 931</li> 932<li id="fn:inline-note">inline note</li> 933<li id="fn:2">the second deferred note 934</li> 935</ol> 936</div> 937`, 938 939 `This is a footnote[^1]^[and this is an inline footnote] 940 941[^1]: the footnote text. 942 943 may be multiple paragraphs. 944`, 945 `<p>This is a footnote<sup class="footnote-ref" id="fnref:1"><a class="footnote" href="#fn:1">1</a></sup><sup class="footnote-ref" id="fnref:and-this-is-an-i"><a class="footnote" href="#fn:and-this-is-an-i">2</a></sup></p> 946<div class="footnotes"> 947 948<hr> 949 950<ol> 951<li id="fn:1"><p>the footnote text.</p> 952 953<p>may be multiple paragraphs.</p> 954</li> 955<li id="fn:and-this-is-an-i">and this is an inline footnote</li> 956</ol> 957</div> 958`, 959 960 "empty footnote[^]\n\n[^]: fn text", 961 "<p>empty footnote<sup class=\"footnote-ref\" id=\"fnref:\"><a class=\"footnote\" href=\"#fn:\">1</a></sup></p>\n<div class=\"footnotes\">\n\n<hr>\n\n<ol>\n<li id=\"fn:\">fn text\n</li>\n</ol>\n</div>\n", 962 963 "Some text.[^note1]\n\n[^note1]: fn1", 964 "<p>Some text.<sup class=\"footnote-ref\" id=\"fnref:note1\"><a class=\"footnote\" href=\"#fn:note1\">1</a></sup></p>\n<div class=\"footnotes\">\n\n<hr>\n\n<ol>\n<li id=\"fn:note1\">fn1\n</li>\n</ol>\n</div>\n", 965 966 "Some text.[^note1][^note2]\n\n[^note1]: fn1\n[^note2]: fn2\n", 967 "<p>Some text.<sup class=\"footnote-ref\" id=\"fnref:note1\"><a class=\"footnote\" href=\"#fn:note1\">1</a></sup><sup class=\"footnote-ref\" id=\"fnref:note2\"><a class=\"footnote\" href=\"#fn:note2\">2</a></sup></p>\n<div class=\"footnotes\">\n\n<hr>\n\n<ol>\n<li id=\"fn:note1\">fn1\n</li>\n<li id=\"fn:note2\">fn2\n</li>\n</ol>\n</div>\n", 968} 969 970func TestFootnotes(t *testing.T) { 971 doTestsInlineParam(t, footnoteTests, EXTENSION_FOOTNOTES, 0, HtmlRendererParameters{}) 972} 973 974func TestFootnotesWithParameters(t *testing.T) { 975 tests := make([]string, len(footnoteTests)) 976 977 prefix := "testPrefix" 978 returnText := "ret" 979 re := regexp.MustCompile(`(?ms)<li id="fn:(\S+?)">(.*?)</li>`) 980 981 // Transform the test expectations to match the parameters we're using. 982 for i, test := range footnoteTests { 983 if i%2 == 1 { 984 test = strings.Replace(test, "fn:", "fn:"+prefix, -1) 985 test = strings.Replace(test, "fnref:", "fnref:"+prefix, -1) 986 test = re.ReplaceAllString(test, `<li id="fn:$1">$2 <a class="footnote-return" href="#fnref:$1">ret</a></li>`) 987 } 988 tests[i] = test 989 } 990 991 params := HtmlRendererParameters{ 992 FootnoteAnchorPrefix: prefix, 993 FootnoteReturnLinkContents: returnText, 994 } 995 996 doTestsInlineParam(t, tests, EXTENSION_FOOTNOTES, HTML_FOOTNOTE_RETURN_LINKS, params) 997} 998 999func runMarkdownInlineXML(input string, extensions, xmlFlags int) string { 1000 extensions |= EXTENSION_AUTOLINK 1001 extensions |= EXTENSION_CITATION 1002 extensions |= EXTENSION_SHORT_REF 1003 1004 renderer := XmlRenderer(xmlFlags) 1005 1006 return Parse([]byte(input), renderer, extensions).String() 1007} 1008 1009func doTestsInlineXML(t *testing.T, tests []string) { 1010 doTestsInlineParamXML(t, tests, 0, 0) 1011} 1012 1013func doTestsInlineParamXML(t *testing.T, tests []string, extensions, xmlFlags int) { 1014 var candidate string 1015 1016 for i := 0; i+1 < len(tests); i += 2 { 1017 input := tests[i] 1018 candidate = input 1019 expected := tests[i+1] 1020 actual := runMarkdownInlineXML(candidate, extensions, xmlFlags) 1021 if actual != expected { 1022 t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", 1023 candidate, expected, actual) 1024 } 1025 1026 // now test every substring to stress test bounds checking 1027 if !testing.Short() { 1028 for start := 0; start < len(input); start++ { 1029 for end := start + 1; end <= len(input); end++ { 1030 candidate = input[start:end] 1031 _ = runMarkdownInlineXML(candidate, extensions, xmlFlags) 1032 } 1033 } 1034 } 1035 } 1036} 1037 1038func TestIndexXML(t *testing.T) { 1039 var tests = []string{ 1040 "(((Tiger, Cats)))\n", 1041 "<t>\n<iref item=\"Tiger\" subitem=\"Cats\"/>\n</t>\n", 1042 1043 "`(((Tiger, Cats)))`\n", 1044 "<t>\n<tt>(((Tiger, Cats)))</tt>\n</t>\n", 1045 1046 "(((Tiger, Cats))\n", 1047 "<t>\n(((Tiger, Cats))\n</t>\n", 1048 } 1049 doTestsInlineXML(t, tests) 1050} 1051 1052func TestNestedFootnotes(t *testing.T) { 1053 var tests = []string{ 1054 `Paragraph.[^fn1] 1055 1056[^fn1]: 1057 Asterisk[^fn2] 1058 1059[^fn2]: 1060 Obelisk`, 1061 `<p>Paragraph.<sup class="footnote-ref" id="fnref:fn1"><a class="footnote" href="#fn:fn1">1</a></sup></p> 1062<div class="footnotes"> 1063 1064<hr> 1065 1066<ol> 1067<li id="fn:fn1">Asterisk<sup class="footnote-ref" id="fnref:fn2"><a class="footnote" href="#fn:fn2">2</a></sup> 1068</li> 1069<li id="fn:fn2">Obelisk 1070</li> 1071</ol> 1072</div> 1073`, 1074 } 1075 doTestsInlineParam(t, tests, EXTENSION_FOOTNOTES, 0, HtmlRendererParameters{}) 1076} 1077 1078func TestInlineComments(t *testing.T) { 1079 var tests = []string{ 1080 "Hello <!-- there ->\n", 1081 "<p>Hello <!— there –></p>\n", 1082 1083 "Hello <!-- there -->\n", 1084 "<p>Hello <!-- there --></p>\n", 1085 1086 "Hello <!-- there -->", 1087 "<p>Hello <!-- there --></p>\n", 1088 1089 "Hello <!---->\n", 1090 "<p>Hello <!----></p>\n", 1091 1092 "Hello <!-- there -->\na", 1093 "<p>Hello <!-- there -->\na</p>\n", 1094 1095 "* list <!-- item -->\n", 1096 "<ul>\n<li>list <!-- item --></li>\n</ul>\n", 1097 1098 "<!-- Front --> comment\n", 1099 "<p><!-- Front --> comment</p>\n", 1100 1101 "blahblah\n<!--- foo -->\nrhubarb\n", 1102 "<p>blahblah\n<!--- foo -->\nrhubarb</p>\n", 1103 } 1104 doTestsInlineParam(t, tests, 0, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_DASHES, HtmlRendererParameters{}) 1105} 1106 1107func TestCitationXML(t *testing.T) { 1108 var tests = []string{ 1109 "[@RFC2525]", 1110 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC2525\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2525.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1111 1112 "[@!RFC1024]", 1113 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC1024\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Normative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.1024.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1114 1115 "[@?RFC3024]", 1116 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC3024\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3024.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1117 1118 "[-@RFC3024]", 1119 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3024.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1120 1121 "[@?I-D.6man-udpzero]", 1122 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"I-D.6man-udpzero\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.6man-udpzero.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1123 1124 "[@?I-D.6man-udpzero#06]", 1125 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"I-D.6man-udpzero\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-6man-udpzero-06.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1126 1127 "[@?I-D.6man-udpzero p. 23]", 1128 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"I-D.6man-udpzero\" section=\"p. 23\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.6man-udpzero.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1129 1130 "[@RFC2525], as you can see from @RFC2525, as @miekg says", 1131 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC2525\"/>, as you can see from <xref target=\"RFC2525\"/>, as @miekg says\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2525.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1132 1133 "[@?RFC2525], as you can see from [@!RFC2525]", 1134 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC2525\"/>, as you can see from <xref target=\"RFC2525\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Normative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2525.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1135 1136 "[@!RFC2525], as you can see from [@?RFC2525]", 1137 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\n<xref target=\"RFC2525\"/>, as you can see from <xref target=\"RFC2525\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Normative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2525.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1138 1139 "More of that in [@?ISO.8571-2.1988]", 1140 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\nMore of that in <xref target=\"ISO.8571-2.1988\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Informative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml2/reference.ISO.8571-2.1988.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1141 1142 "Hey, what about [@!ISO.8571-2.1988]", 1143 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<t>\nHey, what about <xref target=\"ISO.8571-2.1988\"/>\n</t>\n\n</middle>\n<back>\n<references>\n<name>Normative References</name>\n<xi:include href=\"https://xml2rfc.tools.ietf.org/public/rfc/bibxml2/reference.ISO.8571-2.1988.xml\"/>\n</references>\n\n</back>\n</rfc>\n", 1144 } 1145 doTestsInlineParamXML(t, tests, 0, XML_STANDALONE) 1146} 1147 1148func TestRFC2119XML(t *testing.T) { 1149 var tests = []string{ 1150 "MUST", 1151 "<t>\nMUST\n</t>\n", 1152 1153 "*MUST*", 1154 "<t>\n<em>MUST</em>\n</t>\n", 1155 1156 "**MUST**", 1157 "<t>\n<bcp14>MUST</bcp14>\n</t>\n", 1158 } 1159 doTestsInlineXML(t, tests) 1160} 1161 1162func TestShortReferenceXML(t *testing.T) { 1163 var tests = []string{ 1164 "(#ref)", 1165 "<t>\n<xref target=\"ref\"/>\n</t>\n", 1166 } 1167 doTestsInlineXML(t, tests) 1168} 1169 1170func TestSmartDoubleQuotes(t *testing.T) { 1171 var tests = []string{ 1172 "this should be normal \"quoted\" text.\n", 1173 "<p>this should be normal “quoted” text.</p>\n", 1174 "this \" single double\n", 1175 "<p>this “ single double</p>\n", 1176 "two pair of \"some\" quoted \"text\".\n", 1177 "<p>two pair of “some” quoted “text”.</p>\n"} 1178 1179 doTestsInlineParam(t, tests, 0, HTML_USE_SMARTYPANTS, HtmlRendererParameters{}) 1180} 1181 1182func TestSmartAngledDoubleQuotes(t *testing.T) { 1183 var tests = []string{ 1184 "this should be angled \"quoted\" text.\n", 1185 "<p>this should be angled «quoted» text.</p>\n", 1186 "this \" single double\n", 1187 "<p>this « single double</p>\n", 1188 "two pair of \"some\" quoted \"text\".\n", 1189 "<p>two pair of «some» quoted «text».</p>\n"} 1190 1191 doTestsInlineParam(t, tests, 0, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_ANGLED_QUOTES, HtmlRendererParameters{}) 1192} 1193 1194func TestSmartFractions(t *testing.T) { 1195 var tests = []string{ 1196 "1/2, 1/4 and 3/4; 1/4th and 3/4ths\n", 1197 "<p>½, ¼ and ¾; ¼th and ¾ths</p>\n", 1198 "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", 1199 "<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"} 1200 1201 doTestsInlineParam(t, tests, 0, HTML_USE_SMARTYPANTS, HtmlRendererParameters{}) 1202 1203 tests = []string{ 1204 "1/2, 2/3, 81/100 and 1000000/1048576.\n", 1205 "<p><sup>1</sup>⁄<sub>2</sub>, <sup>2</sup>⁄<sub>3</sub>, <sup>81</sup>⁄<sub>100</sub> and <sup>1000000</sup>⁄<sub>1048576</sub>.</p>\n", 1206 "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", 1207 "<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"} 1208 1209 doTestsInlineParam(t, tests, 0, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_FRACTIONS, HtmlRendererParameters{}) 1210} 1211 1212func TestDisableSmartDashes(t *testing.T) { 1213 doTestsInlineParam(t, []string{ 1214 "foo - bar\n", 1215 "<p>foo - bar</p>\n", 1216 "foo -- bar\n", 1217 "<p>foo -- bar</p>\n", 1218 "foo --- bar\n", 1219 "<p>foo --- bar</p>\n", 1220 }, 0, 0, HtmlRendererParameters{}) 1221 doTestsInlineParam(t, []string{ 1222 "foo - bar\n", 1223 "<p>foo – bar</p>\n", 1224 "foo -- bar\n", 1225 "<p>foo — bar</p>\n", 1226 "foo --- bar\n", 1227 "<p>foo —– bar</p>\n", 1228 }, 0, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_DASHES, HtmlRendererParameters{}) 1229 doTestsInlineParam(t, []string{ 1230 "foo - bar\n", 1231 "<p>foo - bar</p>\n", 1232 "foo -- bar\n", 1233 "<p>foo – bar</p>\n", 1234 "foo --- bar\n", 1235 "<p>foo — bar</p>\n", 1236 }, 0, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_LATEX_DASHES|HTML_SMARTYPANTS_DASHES, 1237 HtmlRendererParameters{}) 1238 doTestsInlineParam(t, []string{ 1239 "foo - bar\n", 1240 "<p>foo - bar</p>\n", 1241 "foo -- bar\n", 1242 "<p>foo -- bar</p>\n", 1243 "foo --- bar\n", 1244 "<p>foo --- bar</p>\n", 1245 }, 0, 1246 HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_LATEX_DASHES, 1247 HtmlRendererParameters{}) 1248} 1249