diff --git a/Parsedown.php b/Parsedown.php index ae0cbde..1106dce 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -11,13 +11,16 @@ # For the full license information, view the LICENSE file that was distributed # with this source code. # -# +# 2019-07-01T09:48:39/Erik Bachmann: Implementet Note blocks as
+# (see: https://docs.microsoft.com/en-us/contribute/how-to-write-use-markdown#note-blocks ) + +$_in_fieldset = FALSE; // On=Fieldset, off=blockquote class Parsedown { # ~ - const version = '1.8.0-beta-7'; + const version = '1.8.0-beta-7-noteblock'; # ~ @@ -744,14 +747,93 @@ class Parsedown # # Quote - protected function blockQuote($Line) { if (preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches)) { + // >>> Note block header >>> + /** + * Creating field sets from blockquotes with header + * + * Microsoft names this "Note blocks" but it is simply fieldsets + * ( https://docs.microsoft.com/en-us/contribute/how-to-write-use-markdown#note-blocks ) + * + * The Header has the syntax: [!#xxx] + * + * Element | Function + * --------|------------------------- + * `[!` | Legend start + * `#` | Special legend indicator + * `xxx` | Legend text + * `]` | Legend end + * + * + * + * Examples: + * + * > This is a block quote + * + * > [!#NOTE] + * > This is a + * > NOTE block + * + * will parse as + * + * This is a block quote + *
ⓘ NOTEThis is a NOTE block
+ * + * Special legends with Unicode indicator: + * + * Function | Unicode | Tag | Description + * ------------|-----------|-------|------------ + * Note | ⓘ | # | (i) + * Warning | ☠ | $ | Jolly Roger / Skull and crossbones + * Tip | 💡 | + | Light bulb + * Important | ⚠ | ! | /!\ + * + * Easy to spice up with som CSS + */ + global $_in_fieldset; // Fieldset / blockquote flag + $_type = 'blockquote'; // Default block type + + if ( "[!" == substr($matches[1], 0, 2) ){ + $_in_fieldset = TRUE; + $_type = 'fieldset'; + + // Extract legend + preg_match( '/\[!(.)(.*)\]/', $matches[1], $_match ); + + $_class = "legend1"; // Class + //echo "
".var_export($_match, TRUE). "
"; + switch ( $_match[1] ) { // Check special legends + case '$': //'IMPORTANT': + $matches[1] = "⚠ " . $_match[2] ; + $_class .= " legendimportant"; + break; + case '#': //'NOTE': + $matches[1] = "ⓘ " . $_match[2] ; + $_class .= " legendnote"; + break; + case '?': //'TIP': + $matches[1] = "💡 " . $_match[2] ; + $_class .= " legendtip"; + break; + case '!': //'WARNING': + $matches[1] = "☠ " . $_match[2] ; + $_class .= " legendwarning"; + break; + default: + $matches[1] = $_match[1] . $_match[2] ; + + } + $matches[1] = "
". $matches[1] .""; + } + // <<< Note block header + $Block = array( 'element' => array( - 'name' => 'blockquote', + //'name' => 'blockquote', + 'name' => $_type, // Variable type: fieldset or blockquote (default) 'handler' => array( 'function' => 'linesElements', 'argument' => (array) $matches[1], @@ -768,6 +850,15 @@ class Parsedown { if (isset($Block['interrupted'])) { + // >>> Note block footer + global $_in_fieldset; + if ( $_in_fieldset ) { + $Line['text'] = "
\n" . $Line['text']; + $_in_fieldset = false; + + } + // <<< Note block footer <<< + return; }