Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9dd81527

Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt

  • ID 9dd81527db431f6f539007ac69d6fe1632b54a78
  • Vorgänger 36ecffa0
  • Nachfolger 5b414a78

MultiMarkdown: Unterstützung für Code-Blöcke mit drei Backticks ``` … ```

Unterschiede anzeigen:

modules/override/Text/MultiMarkdown.pm
287 287
    $self->SUPER::_CleanUpRunData($options);
288 288
}
289 289

  
290
sub _DoCodeBlocksMultiBackticks {
291
#
292
# Process Markdown code blocks embedded within lines consisting of three backticks: ```
293
# * encode <, >, & into HTML entities
294
# * escape Markdown special characters into MD5 hashes
295
# * trim leading and trailing newlines
296
#
297
    my ($self, $text) = @_;
298

  
299
    $text =~ s{
300
        (?:\n\n|\A)
301
        ```[^\n]*\n
302
        (                # $1 = the code block -- one or more lines
303
            .*?
304
        )
305
        ```(?:\n|\Z)
306
    }{
307
        my $codeblock = $1;
308
        my $result;  # return value
309

  
310
        $codeblock = $self->_EncodeCode($codeblock);
311
        $codeblock = $self->_Detab($codeblock);
312
        $codeblock =~ s/\A\n+//;  # trim leading newlines
313
        $codeblock =~ s/\n+\z//;  # trim trailing newlines
314

  
315
        $result = "\n\n<pre><code>" . $codeblock . "\n</code></pre>\n\n";
316

  
317
        $result;
318
    }egmsx;
319

  
320
    return $text;
321
}
322

  
290 323
sub _Markdown {
291 324
#
292 325
# Main function. The order in which other subs are called here is
......
309 342

  
310 343
    # MMD only
311 344
    $text = $self->_StripMarkdownReferences($text);
345
    $text = $self->_DoCodeBlocksMultiBackticks($text);
312 346

  
313 347
    $text = $self->_RunBlockGamut($text, {wrap_in_p_tags => 1});
314 348

  

Auch abrufbar als: Unified diff