derived pretty much verbatim from PHP Markdown
()
| 542 | /// derived pretty much verbatim from PHP Markdown |
| 543 | /// </summary> |
| 544 | private static string GetBlockPattern() |
| 545 | { |
| 546 | |
| 547 | // Hashify HTML blocks: |
| 548 | // We only want to do this for block-level HTML tags, such as headers, |
| 549 | // lists, and tables. That's because we still want to wrap <p>s around |
| 550 | // "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
| 551 | // phrase emphasis, and spans. The list of tags we're looking for is |
| 552 | // hard-coded: |
| 553 | // |
| 554 | // * List "a" is made of tags which can be both inline or block-level. |
| 555 | // These will be treated block-level when the start tag is alone on |
| 556 | // its line, otherwise they're not matched here and will be taken as |
| 557 | // inline later. |
| 558 | // * List "b" is made of tags which are always block-level; |
| 559 | // |
| 560 | string blockTagsA = "ins|del"; |
| 561 | string blockTagsB = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|script|noscript|form|fieldset|iframe|math"; |
| 562 | |
| 563 | // Regular expression for the content of a block tag. |
| 564 | string attr = @" |
| 565 | (?> # optional tag attributes |
| 566 | \s # starts with whitespace |
| 567 | (?> |
| 568 | [^>""/]+ # text outside quotes |
| 569 | | |
| 570 | /+(?!>) # slash not followed by > |
| 571 | | |
| 572 | ""[^""]*"" # text inside double quotes (tolerate >) |
| 573 | | |
| 574 | '[^']*' # text inside single quotes (tolerate >) |
| 575 | )* |
| 576 | )? |
| 577 | "; |
| 578 | |
| 579 | string content = RepeatString(@" |
| 580 | (?> |
| 581 | [^<]+ # content without tag |
| 582 | | |
| 583 | <\2 # nested opening tag |
| 584 | " + attr + @" # attributes |
| 585 | (?> |
| 586 | /> |
| 587 | | |
| 588 | >", _nestDepth) + // end of opening tag |
| 589 | ".*?" + // last level nested tag content |
| 590 | RepeatString(@" |
| 591 | </\2\s*> # closing nested tag |
| 592 | ) |
| 593 | | |
| 594 | <(?!/\2\s*> # other tags with a different name |
| 595 | ) |
| 596 | )*", _nestDepth); |
| 597 | |
| 598 | string content2 = content.Replace(@"\2", @"\3"); |
| 599 | |
| 600 | // First, look for nested blocks, e.g.: |
| 601 | // <div> |