Skip to content
This repository
Browse code

Changed abbreviation syntax and other small improvements

  • Loading branch information...
commit 2c2b637293d092c026945bbf011ff2b13e08fd5a 1 parent c51009e
Michel Fortin authored

Showing 2 changed files with 79 additions and 43 deletions. Show diff stats Hide diff stats

  1. +1 1  PHP Markdown Extra Readme.text
  2. +78 42 markdown.php
2  PHP Markdown Extra Readme.text
... ... @@ -1,7 +1,7 @@
1 1 PHP Markdown Extra
2 2 ==================
3 3
4   -Version 1.1b1 - Sat 16 Sep 2006
  4 +Version 1.1b2 - Sat 21 Sep 2006
5 5
6 6 by Michel Fortin
7 7 <http://www.michelf.com/>
120 markdown.php
@@ -13,7 +13,7 @@
13 13
14 14
15 15 define( 'MARKDOWN_VERSION', "1.0.2b7" ); # Sat 16 Sep 2006
16   -define( 'MARKDOWNEXTRA_VERSION', "1.1b1" ); # Sat 16 Sep 2006
  16 +define( 'MARKDOWNEXTRA_VERSION', "1.1b2" ); # Sat 16 Sep 2006
17 17
18 18
19 19 #
@@ -63,7 +63,7 @@ function Markdown($text) {
63 63 Plugin Name: Markdown Extra
64 64 Plugin URI: http://www.michelf.com/projects/php-markdown/
65 65 Description: <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a> allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>. <a href="http://www.michelf.com/projects/php-markdown/">More...</a>
66   -Version: 1.1b1
  66 +Version: 1.1b2
67 67 Author: Michel Fortin
68 68 Author URI: http://www.michelf.com/
69 69 */
@@ -2373,12 +2373,15 @@ function doItalicsAndBold($text) {
2373 2373 [^_]+? # Anthing not em markers.
2374 2374 |
2375 2375 # Balence any regular _ emphasis inside.
2376   - (?<![a-zA-Z0-9])_ (?=\S) (?! _) (.+?)
  2376 + (?<![a-zA-Z0-9]) _ (?=\S) (?! _) (.+?)
2377 2377 (?<=\S) _ (?![a-zA-Z0-9])
  2378 + |
  2379 + ___+
2378 2380 )+?
2379 2381 )
2380 2382 (?<=\S) __ # End mark not preceded by whitespace.
2381   - (?!\w) # Not followed by alphanum.
  2383 + (?![a-zA-Z0-9]) # Not followed by alphanum
  2384 + (?!__) # or two others marker chars.
2382 2385 }sx',
2383 2386 '{
2384 2387 ( (?<!\*\*) \*\* ) # $1: Marker (not preceded by two *)
@@ -2398,8 +2401,8 @@ function doItalicsAndBold($text) {
2398 2401 array(&$this, '_doItalicAndBold_strong_callback'), $text);
2399 2402 # Then <em>:
2400 2403 $text = preg_replace_callback(array(
2401   - '{ ( (?<!\w) _ ) (?=\S) (?! _) (.+?) (?<=\S) _ (?!\w) }sx',
2402   - '{ ( (?<!\*)\* ) (?=\S) (?! \*) (.+?) (?<=\S) \* }sx',
  2404 + '{ ( (?<!\w|_) _ ) (?![\s_]) (.+?) (?<![\s_]) _ (?!\w|_) }sx',
  2405 + '{ ( (?<! \*)\* ) (?![\s*]) (.+?) (?<![\s*])\* (?! \*) }sx',
2403 2406 ),
2404 2407 array(&$this, '_doItalicAndBold_em_callback'), $text);
2405 2408
@@ -2449,36 +2452,6 @@ function formParagraphs($text) {
2449 2452
2450 2453 ### Footnotes
2451 2454
2452   - function doFootnotes($text) {
2453   - #
2454   - # Replace footnote references in $text [^id] with a link to the footnote.
2455   - #
2456   - $text = preg_replace_callback('{\[\^(.+?)\]}',
2457   - array(&$this, '_doFootnotes_callback'), $text);
2458   -
2459   - return $text;
2460   - }
2461   - function _doFootnotes_callback($matches) {
2462   - $node_id = $this->footnote_prefix . $matches[1];
2463   -
2464   - # Create footnote marker only if it has a corresponding footnote *and*
2465   - # the footnote hasn't been used by another marker.
2466   - if (isset($this->footnotes[$node_id])) {
2467   - # Transfert footnote content to the ordered list.
2468   - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
2469   - unset($this->footnotes[$node_id]);
2470   -
2471   - $num = count($this->footnotes_ordered);
2472   - $result =
2473   - "<sup id=\"fnref:$node_id\">".
2474   - "<a href=\"#fn:$node_id\" rel=\"footnote\">$num</a>".
2475   - "</sup>";
2476   - } else {
2477   - $result = $matches[0];
2478   - }
2479   - return $this->hashSpan($result);
2480   - }
2481   -
2482 2455 function stripFootnotes($text) {
2483 2456 #
2484 2457 # Strips link definitions from text, stores the URLs and titles in
@@ -2488,7 +2461,7 @@ function stripFootnotes($text) {
2488 2461
2489 2462 # Link defs are in the form: [^id]: url "optional title"
2490 2463 $text = preg_replace_callback('{
2491   - ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\]: # note_id = $1
  2464 + ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1
2492 2465 [ \t]*
2493 2466 \n? # maybe *one* newline
2494 2467 ( # text = $2 (no blank lines allowed)
@@ -2497,7 +2470,7 @@ function stripFootnotes($text) {
2497 2470 |
2498 2471 \n # newlines but
2499 2472 (?!\[\^.+?\]:\s)# negative lookahead for footnote marker.
2500   - (?!\n+\S{4}) # ensure line is not blank and followed
  2473 + (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
2501 2474 # by non-indented content
2502 2475 )*
2503 2476 )
@@ -2513,10 +2486,23 @@ function _stripFootnotes_callback($matches) {
2513 2486 }
2514 2487
2515 2488
  2489 + function doFootnotes($text) {
  2490 + #
  2491 + # Replace footnote references in $text [^id] with a special text-token
  2492 + # which will be can be
  2493 + #
  2494 + $text = preg_replace('{\[\^(.+?)\]}', "a\0fn:\\1\0z", $text);
  2495 + return $text;
  2496 + }
  2497 +
  2498 +
2516 2499 function appendFootnotes($text) {
2517 2500 #
2518 2501 # Append footnote list to text.
2519 2502 #
  2503 + $text = preg_replace_callback('{a\0fn:(.*?)\0z}',
  2504 + array(&$this, '_appendFootnotes_callback'), $text);
  2505 +
2520 2506 if (!empty($this->footnotes_ordered)) {
2521 2507 $text .= "\n\n";
2522 2508 $text .= "<div class=\"footnotes\">\n";
@@ -2530,7 +2516,7 @@ function appendFootnotes($text) {
2530 2516 # Add backlink to last paragraph; create new paragraph if needed.
2531 2517 $backlink = "<a href=\"#fnref:$note_id\" rev=\"footnote\">&#8617;</a>";
2532 2518 if (preg_match('{</p>$}', $footnote)) {
2533   - $footnote = substr($footnote, 0, -4) . " $backlink</p>";
  2519 + $footnote = substr($footnote, 0, -4) . "&#160;$backlink</p>";
2534 2520 } else {
2535 2521 $footnote .= "\n\n<p>$backlink</p>";
2536 2522 }
@@ -2542,10 +2528,31 @@ function appendFootnotes($text) {
2542 2528
2543 2529 $text .= "</ol>\n";
2544 2530 $text .= "</div>\n";
  2531 +
  2532 + $text = preg_replace('{a\{fn:(.*?)\}z}', '[^\\1]', $text);
2545 2533 }
2546 2534 return $text;
2547 2535 }
2548   -
  2536 + function _appendFootnotes_callback($matches) {
  2537 + $node_id = $this->footnote_prefix . $matches[1];
  2538 +
  2539 + # Create footnote marker only if it has a corresponding footnote *and*
  2540 + # the footnote hasn't been used by another marker.
  2541 + if (isset($this->footnotes[$node_id])) {
  2542 + # Transfert footnote content to the ordered list.
  2543 + $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
  2544 + unset($this->footnotes[$node_id]);
  2545 +
  2546 + $num = count($this->footnotes_ordered);
  2547 + return
  2548 + "<sup id=\"fnref:$node_id\">".
  2549 + "<a href=\"#fn:$node_id\" rel=\"footnote\">$num</a>".
  2550 + "</sup>";
  2551 + }
  2552 +
  2553 + return "[^".$matches[1]."]";
  2554 + }
  2555 +
2549 2556
2550 2557 ### Abbreviations ###
2551 2558
@@ -2558,7 +2565,7 @@ function stripAbbreviations($text) {
2558 2565
2559 2566 # Link defs are in the form: [id]*: url "optional title"
2560 2567 $text = preg_replace_callback('{
2561   - ^[ ]{0,'.$less_than_tab.'}\[(.+?)\]\*: # abbr_id = $1
  2568 + ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1
2562 2569 [ \t]* \n? # maybe *one* newline
2563 2570 (.*) # text = $2 (no blank lines allowed)
2564 2571 }xm',
@@ -2580,7 +2587,7 @@ function doAbbreviations($text) {
2580 2587 # Replace footnote references in $text [^id] with a link to the footnote.
2581 2588 #
2582 2589 if ($this->abbr_matches) {
2583   - $regex = '{\b(?:'. implode('|', $this->abbr_matches) .')\b}';
  2590 + $regex = '{(?<!\w)(?:'. implode('|', $this->abbr_matches) .')(?!\w)}';
2584 2591
2585 2592 $text = preg_replace_callback($regex,
2586 2593 array(&$this, '_doAbbreviations_callback'), $text);
@@ -2649,6 +2656,35 @@ function _doAbbreviations_callback($matches) {
2649 2656
2650 2657 See Readme file for details.
2651 2658
  2659 +1.1b2 (21 Sep 2006)
  2660 +
  2661 +* Changed the space before footnote backlinks to an unbrekable space
  2662 + `&#160;` at the suggestion of John Gruber.
  2663 +
  2664 +* Fixed the out-of-order footnote problems which were occuring when they
  2665 + were refered to by markers from various block-level constructs.
  2666 +
  2667 +* Fixed a bug where footnotes definition were taking the text following
  2668 + them even though that text had no indentation.
  2669 +
  2670 +* Footnotes are now prevented from containing a reference to another
  2671 + footnote.
  2672 +
  2673 +* Small change to the syntax for abbreviation definitions. Abbreviations are
  2674 + now defined like this:
  2675 +
  2676 + *[SGML]: Standard Generalized Markup Language
  2677 +
  2678 + The asterisk was previously after the brakets, making it harder to
  2679 + distinguish from link references.
  2680 +
  2681 +* Abbreviations are now correctly surrounded by `<abbr>` tags when found
  2682 + around punctuation marks.
  2683 +
  2684 +* Arranged badly nested emphasis to produce mostly the same result as
  2685 + PHP Markdown. Still not ideal, but better.
  2686 +
  2687 +
2652 2688 1.1b1 (16 Sep 2006)
2653 2689
2654 2690 * Added a syntax for footnotes.

0 comments on commit 2c2b637

Please sign in to comment.
Something went wrong with that request. Please try again.