diff --git a/changelog.txt b/CHANGELOG.txt
similarity index 100%
rename from changelog.txt
rename to CHANGELOG.txt
diff --git a/license.txt b/LICENSE.txt
similarity index 100%
rename from license.txt
rename to LICENSE.txt
diff --git a/content/index.html b/content/index.html
deleted file mode 100644
index e69de29..0000000
diff --git a/index.php b/index.php
index d89eed7..2f49bdd 100644
--- a/index.php
+++ b/index.php
@@ -8,6 +8,6 @@ define('PLUGINS_DIR', ROOT_DIR .'plugins/');
define('THEMES_DIR', ROOT_DIR .'themes/');
define('CACHE_DIR', LIB_DIR .'cache/');
-require(ROOT_DIR .'vendor/autoload.php');
+require(LIB_DIR .'autoload.php');
require(LIB_DIR .'pico.php');
$pico = new Pico();
diff --git a/vendor/autoload.php b/lib/autoload.php
similarity index 100%
rename from vendor/autoload.php
rename to lib/autoload.php
diff --git a/vendor/composer/ClassLoader.php b/lib/composer/ClassLoader.php
similarity index 100%
rename from vendor/composer/ClassLoader.php
rename to lib/composer/ClassLoader.php
diff --git a/vendor/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php
similarity index 100%
rename from vendor/composer/autoload_classmap.php
rename to lib/composer/autoload_classmap.php
diff --git a/vendor/composer/autoload_namespaces.php b/lib/composer/autoload_namespaces.php
similarity index 100%
rename from vendor/composer/autoload_namespaces.php
rename to lib/composer/autoload_namespaces.php
diff --git a/vendor/composer/autoload_real.php b/lib/composer/autoload_real.php
similarity index 100%
rename from vendor/composer/autoload_real.php
rename to lib/composer/autoload_real.php
diff --git a/vendor/composer/installed.json b/lib/composer/installed.json
similarity index 100%
rename from vendor/composer/installed.json
rename to lib/composer/installed.json
diff --git a/lib/index.html b/lib/index.html
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/markdown/LICENSE b/lib/markdown/LICENSE
new file mode 100644
index 0000000..5ba3dec
--- /dev/null
+++ b/lib/markdown/LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2013 Egil Hansen (http://egilhansen.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/lib/markdown/README.md b/lib/markdown/README.md
new file mode 100644
index 0000000..7c2b82d
--- /dev/null
+++ b/lib/markdown/README.md
@@ -0,0 +1,128 @@
+# PHP Markdown Extra Extended
+
+An fork of the [PHP Markdown (Extra) project](http://michelf.com/projects/php-markdown/) (PME), extended with extra syntax, especially focused on adding support for more HTML attributes to outputted HTML, and for outputting HTML5.
+
+## Changes to syntax from PHP Markdown (Extra)
+Unless explicitly specified, existing Markdown markup works exactly as it did before. The orginal syntax is documentated here:
+
+- [Markdown syntax](http://daringfireball.net/projects/markdown/syntax)
+- [Markdown Extra syntax](http://michelf.com/projects/php-markdown/extra/)
+
+### Line break generates a `
`
+In PME, when you want to insert a `
` break tag using Markdown, you end a line with two or more spaces, then type return. This turned out to be more annoying than helpful in my projects, so now you just have to type return. This is also how Markdown works with GFM.
+
+Two returns does not insert a `
`, but instead creates a new paragraph as usual.
+
+### Support for *cite* attribute on blockquotes
+It is now possible to add the optional *cite* attribute to the *blockquote* element.
+
+The new, optional, syntax is:
+
+```markdown
+> (cite url) Cited content follows ...
+```
+
+#### Example:
+
+```markdown
+> (http://www.whatwg.org/) Content inside a blockquote must be quoted
+> from another source, whose address, if it has one,
+> may be cited in the `cite` attribute.
+```
+
+Will result in the following HTML:
+
+```html
+
++``` + +#### Breaking changes from PME +The existing rules for and [formatting options](http://daringfireball.net/projects/markdown/syntax#blockquote) for blockquotes still apply. There is one small breaking changes with this addition. If your quote starts with "(" you have two have at least two spaces between the initial ">" and the "(". E.g.: + +```markdown +> (Ut brisket flank salami.) Cow cupidatat ex t-bone sirloin id. +> Sunt flank pastrami spare ribs sint id, nulla nisi. +``` + +Will result in the following HTML: + +```html +Content inside a blockquote must be quoted +from another source, whose address, if it has one, +may be cited in the `cite` attribute.
+
++``` + +### Fenced code block with language support and alternating fence markers (```) +It is now possible to specify the language type of a code block, and use an alternatinge fence markers (```), enabling the same syntax as that of GFM. + +This addition follows the [suggested way](http://dev.w3.org/html5/spec-author-view/the-code-element.html#the-code-element) to specify language by W3C. + +#### Example: + + ~~~html +(Ut brisket flank salami.) Cow cupidatat ex t-bone sirloin id.
+
+ Sunt flank pastrami spare ribs sint id, nulla nisi.
Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.
+ ~~~ + +Using alternative fence markers: + + ```html +Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.
+ ``` + +Both will output the following HTML: + +```HTML +
+Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.
+
+```
+
+### Support for *figure* and *figcaption* tags
+There is now experimental support for the the HTML5 tags *[figure](http://dev.w3.org/html5/markup/figure.html)* and *[figcaption](http://dev.w3.org/html5/markup/figcaption.html)*.
+
+A *figure* is a block level element and is created by wrapping some other content in three or more equal (=) signs.
+
+A optional *figure caption* can be added to either the top of the figure or the bottom at the figure, right after the equal signs, wrapped in [ and ] signs.
+
+#### Examples
+This example shows a *figure* without a caption:
+
+```markdown
+===
+
+===
+```
+
+This example shows a *figure* with a caption added before the content:
+
+```markdown
+=== [A **happy face** is good for web developers]
+
+===
+```
+
+This example shows a *figure* with a caption added after the content:
+
+```markdown
+===
+
+=== [A **happy face** is good for web developers]
+```
+
+## Usage
+You need both the *markdown.php* and the *markdown_extended.php* files, but only needs to include *markdown_extended.php*.
+
+```PHP
+require_once('markdown_extended.php');
+
+// Convert markdown formatted text in $markdown to HTML
+$html = MarkdownExtended($markdown);
+```
+
+## License
+PHP Markdown Extra Extended is licensed under the [MIT License](http://opensource.org/licenses/MIT). See the LICENSE file for details.
\ No newline at end of file
diff --git a/lib/markdown/composer.json b/lib/markdown/composer.json
new file mode 100644
index 0000000..d4d86ac
--- /dev/null
+++ b/lib/markdown/composer.json
@@ -0,0 +1,14 @@
+{
+ "name": "egil/php-markdown-extra-extended",
+ "type": "library",
+ "description": "PHP Markdown Extra Extended",
+ "homepage": "https://github.com/egil/php-markdown-extra-extended",
+ "keywords": ["markdown"],
+ "license": "MIT",
+ "require": {
+ "php": ">=5.3"
+ },
+ "autoload": {
+ "files": ["markdown.php", "markdown_extended.php"]
+ }
+}
diff --git a/vendor/michelf/php-markdown/Michelf/Markdown.php b/lib/markdown/markdown.php
similarity index 76%
rename from vendor/michelf/php-markdown/Michelf/Markdown.php
rename to lib/markdown/markdown.php
index 094b0ee..ee3dddb 100644
--- a/vendor/michelf/php-markdown/Michelf/Markdown.php
+++ b/lib/markdown/markdown.php
@@ -1,81 +1,245 @@
#
-# Original Markdown
+# Original Markdown
# Copyright (c) 2004-2006 John Gruber
#
'.$text.'
'; + $text = preg_replace('{\n{2,}}', "\n\n", $text);
+ }
+ return $text;
+ }
+
+ function mdwp_strip_p($t) { return preg_replace('{?p>}i', '', $t); }
+
+ function mdwp_hide_tags($text) {
+ global $mdwp_hidden_tags, $mdwp_placeholders;
+ return str_replace($mdwp_hidden_tags, $mdwp_placeholders, $text);
+ }
+ function mdwp_show_tags($text) {
+ global $mdwp_hidden_tags, $mdwp_placeholders;
+ return str_replace($mdwp_placeholders, $mdwp_hidden_tags, $text);
+ }
+}
+
+
+### bBlog Plugin Info ###
+
+function identify_modifier_markdown() {
+ return array(
+ 'name' => 'markdown',
+ 'type' => 'modifier',
+ 'nicename' => 'PHP Markdown Extra',
+ 'description' => 'A text-to-HTML conversion tool for web writers',
+ 'authors' => 'Michel Fortin and John Gruber',
+ 'licence' => 'GPL',
+ 'version' => MARKDOWNEXTRA_VERSION,
+ 'help' => 'Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More...',
+ );
+}
+
+
+### Smarty Modifier Interface ###
+
+function smarty_modifier_markdown($text) {
+ return Markdown($text);
+}
+
+
+### Textile Compatibility Mode ###
+
+# Rename this file to "classTextile.php" and it can replace Textile everywhere.
+
+if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) {
+ # Try to include PHP SmartyPants. Should be in the same directory.
+ @include_once 'smartypants.php';
+ # Fake Textile class. It calls Markdown instead.
+ class Textile {
+ function TextileThis($text, $lite='', $encode='') {
+ if ($lite == '' && $encode == '') $text = Markdown($text);
+ if (function_exists('SmartyPants')) $text = SmartyPants($text);
+ return $text;
+ }
+ # Fake restricted version: restrictions are not supported for now.
+ function TextileRestricted($text, $lite='', $noimage='') {
+ return $this->TextileThis($text, $lite);
+ }
+ # Workaround to ensure compatibility with TextPattern 4.0.3.
+ function blockLite($text) { return $text; }
+ }
+}
+
#
# Markdown Parser Class
#
-class Markdown {
-
- ### Version ###
-
- const MARKDOWNLIB_VERSION = "1.3";
-
- ### Simple Function Interface ###
-
- public static function defaultTransform($text) {
- #
- # Initialize the parser and return the result of its transform method.
- # This will work fine for derived classes too.
- #
- # Take parser class on which this function was called.
- $parser_class = \get_called_class();
-
- # try to take parser from the static parser list
- static $parser_list;
- $parser =& $parser_list[$parser_class];
-
- # create the parser it not already set
- if (!$parser)
- $parser = new $parser_class;
-
- # Transform text using parser.
- return $parser->transform($text);
- }
-
- ### Configuration Variables ###
-
- # Change to ">" for HTML output.
- public $empty_element_suffix = " />";
- public $tab_width = 4;
-
- # Change to `true` to disallow markup or entities.
- public $no_markup = false;
- public $no_entities = false;
-
- # Predefined urls and titles for reference links and images.
- public $predef_urls = array();
- public $predef_titles = array();
-
-
- ### Parser Implementation ###
+class Markdown_Parser {
# Regex to match balanced [brackets].
# Needed to insert a maximum bracked depth while converting to PHP.
- protected $nested_brackets_depth = 6;
- protected $nested_brackets_re;
+ var $nested_brackets_depth = 6;
+ var $nested_brackets_re;
- protected $nested_url_parenthesis_depth = 4;
- protected $nested_url_parenthesis_re;
+ var $nested_url_parenthesis_depth = 4;
+ var $nested_url_parenthesis_re;
# Table of hash values for escaped characters:
- protected $escape_chars = '\`*_{}[]()>#+-.!';
- protected $escape_chars_re;
+ var $escape_chars = '\`*_{}[]()>#+-.!';
+ var $escape_chars_re;
+
+ # Change to ">" for HTML output.
+ var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX;
+ var $tab_width = MARKDOWN_TAB_WIDTH;
+
+ # Change to `true` to disallow markup or entities.
+ var $no_markup = false;
+ var $no_entities = false;
+
+ # Predefined urls and titles for reference links and images.
+ var $predef_urls = array();
+ var $predef_titles = array();
- public function __construct() {
+ function Markdown_Parser() {
#
# Constructor function. Initialize appropriate member variables.
#
@@ -100,15 +264,15 @@ class Markdown {
# Internal hashes used during transformation.
- protected $urls = array();
- protected $titles = array();
- protected $html_hashes = array();
+ var $urls = array();
+ var $titles = array();
+ var $html_hashes = array();
# Status flag to avoid invalid nesting.
- protected $in_anchor = false;
+ var $in_anchor = false;
- protected function setup() {
+ function setup() {
#
# Called before the transformation process starts to setup parser
# states.
@@ -118,10 +282,10 @@ class Markdown {
$this->titles = $this->predef_titles;
$this->html_hashes = array();
- $this->in_anchor = false;
+ $in_anchor = false;
}
- protected function teardown() {
+ function teardown() {
#
# Called after the transformation process to clear any variable
# which may be taking up memory unnecessarly.
@@ -132,7 +296,7 @@ class Markdown {
}
- public function transform($text) {
+ function transform($text) {
#
# Main function. Performs some preprocessing on the input text
# and pass it through the document gamut.
@@ -171,7 +335,7 @@ class Markdown {
return $text . "\n";
}
- protected $document_gamut = array(
+ var $document_gamut = array(
# Strip link definitions, store in hashes.
"stripLinkDefinitions" => 20,
@@ -179,7 +343,7 @@ class Markdown {
);
- protected function stripLinkDefinitions($text) {
+ function stripLinkDefinitions($text) {
#
# Strips link definitions from text, stores the URLs and titles in
# hash references.
@@ -213,7 +377,7 @@ class Markdown {
$text);
return $text;
}
- protected function _stripLinkDefinitions_callback($matches) {
+ function _stripLinkDefinitions_callback($matches) {
$link_id = strtolower($matches[1]);
$url = $matches[2] == '' ? $matches[3] : $matches[2];
$this->urls[$link_id] = $url;
@@ -222,7 +386,7 @@ class Markdown {
}
- protected function hashHTMLBlocks($text) {
+ function hashHTMLBlocks($text) {
if ($this->no_markup) return $text;
$less_than_tab = $this->tab_width - 1;
@@ -242,9 +406,7 @@ class Markdown {
#
$block_tags_a_re = 'ins|del';
$block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'.
- 'script|noscript|form|fieldset|iframe|math|svg|'.
- 'article|section|nav|aside|hgroup|header|footer|'.
- 'figure';
+ 'script|noscript|form|fieldset|iframe|math';
# Regular expression for the content of a block tag.
$nested_tags_level = 4;
@@ -361,14 +523,14 @@ class Markdown {
return $text;
}
- protected function _hashHTMLBlocks_callback($matches) {
+ function _hashHTMLBlocks_callback($matches) {
$text = $matches[1];
$key = $this->hashBlock($text);
return "\n\n$key\n\n";
}
- protected function hashPart($text, $boundary = 'X') {
+ function hashPart($text, $boundary = 'X') {
#
# Called whenever a tag must be hashed when a function insert an atomic
# element in the text stream. Passing $text to through this function gives
@@ -391,7 +553,7 @@ class Markdown {
}
- protected function hashBlock($text) {
+ function hashBlock($text) {
#
# Shortcut function for hashPart with block-level boundaries.
#
@@ -399,7 +561,7 @@ class Markdown {
}
- protected $block_gamut = array(
+ var $block_gamut = array(
#
# These are all the transformations that form block-level
# tags like paragraphs, headers, and list items.
@@ -412,7 +574,7 @@ class Markdown {
"doBlockQuotes" => 60,
);
- protected function runBlockGamut($text) {
+ function runBlockGamut($text) {
#
# Run block gamut tranformations.
#
@@ -426,7 +588,7 @@ class Markdown {
return $this->runBasicBlockGamut($text);
}
- protected function runBasicBlockGamut($text) {
+ function runBasicBlockGamut($text) {
#
# Run block gamut tranformations, without hashing HTML blocks. This is
# useful when HTML blocks are known to be already hashed, like in the first
@@ -443,7 +605,7 @@ class Markdown {
}
- protected function doHorizontalRules($text) {
+ function doHorizontalRules($text) {
# Do Horizontal Rules:
return preg_replace(
'{
@@ -461,7 +623,7 @@ class Markdown {
}
- protected $span_gamut = array(
+ var $span_gamut = array(
#
# These are all the transformations that occur *within* block-level
# tags like paragraphs, headers, and list items.
@@ -485,7 +647,7 @@ class Markdown {
"doHardBreaks" => 60,
);
- protected function runSpanGamut($text) {
+ function runSpanGamut($text) {
#
# Run span gamut tranformations.
#
@@ -497,17 +659,17 @@ class Markdown {
}
- protected function doHardBreaks($text) {
+ function doHardBreaks($text) {
# Do hard breaks:
return preg_replace_callback('/ {2,}\n/',
array(&$this, '_doHardBreaks_callback'), $text);
}
- protected function _doHardBreaks_callback($matches) {
+ function _doHardBreaks_callback($matches) {
return $this->hashPart(" tags
@@ -1246,7 +1408,7 @@ class Markdown {
}
- protected function encodeAttribute($text) {
+ function encodeAttribute($text) {
#
# Encode text for a double-quoted HTML attribute. This function
# is *not* suitable for attributes enclosed in single quotes.
@@ -1257,7 +1419,7 @@ class Markdown {
}
- protected function encodeAmpsAndAngles($text) {
+ function encodeAmpsAndAngles($text) {
#
# Smart processing for ampersands and angle brackets that need to
# be encoded. Valid character entities are left alone unless the
@@ -1278,7 +1440,7 @@ class Markdown {
}
- protected function doAutoLinks($text) {
+ function doAutoLinks($text) {
$text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
array(&$this, '_doAutoLinks_url_callback'), $text);
@@ -1305,19 +1467,19 @@ class Markdown {
return $text;
}
- protected function _doAutoLinks_url_callback($matches) {
+ function _doAutoLinks_url_callback($matches) {
$url = $this->encodeAttribute($matches[1]);
$link = "$url";
return $this->hashPart($link);
}
- protected function _doAutoLinks_email_callback($matches) {
+ function _doAutoLinks_email_callback($matches) {
$address = $matches[1];
$link = $this->encodeEmailAddress($address);
return $this->hashPart($link);
}
- protected function encodeEmailAddress($addr) {
+ function encodeEmailAddress($addr) {
#
# Input: an email address, e.g. "foo@example.com"
#
@@ -1358,7 +1520,7 @@ class Markdown {
}
- protected function parseSpan($str) {
+ function parseSpan($str) {
#
# Take the string $str and parse it into tokens, hashing embeded HTML,
# escaped characters and handling code spans.
@@ -1377,16 +1539,12 @@ class Markdown {
|
<\?.*?\?> | <%.*?%> # processing instruction
|
- <[!$]?[-a-zA-Z0-9:_]+ # regular tags
+ <[/!$]?[-a-zA-Z0-9:_]+ # regular tags
(?>
\s
(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*
)?
>
- |
- <[-a-zA-Z0-9:_]+\s*/> # xml-style empty tag
- |
- [-a-zA-Z0-9:_]+\s*> # closing tag
').'
)
}xs';
@@ -1418,7 +1576,7 @@ class Markdown {
}
- protected function handleSpanToken($token, &$str) {
+ function handleSpanToken($token, &$str) {
#
# Handle $token provided by parseSpan by determining its nature and
# returning the corresponding value that should replace it.
@@ -1442,7 +1600,7 @@ class Markdown {
}
- protected function outdent($text) {
+ function outdent($text) {
#
# Remove one level of line-leading tabs or spaces
#
@@ -1452,9 +1610,9 @@ class Markdown {
# String length function for detab. `_initDetab` will create a function to
# hanlde UTF-8 if the default function does not exist.
- protected $utf8_strlen = 'mb_strlen';
+ var $utf8_strlen = 'mb_strlen';
- protected function detab($text) {
+ function detab($text) {
#
# Replace tabs with the appropriate amount of space.
#
@@ -1467,7 +1625,7 @@ class Markdown {
return $text;
}
- protected function _detab_callback($matches) {
+ function _detab_callback($matches) {
$line = $matches[0];
$strlen = $this->utf8_strlen; # strlen function for UTF-8.
@@ -1484,7 +1642,7 @@ class Markdown {
}
return $line;
}
- protected function _initDetab() {
+ function _initDetab() {
#
# Check for the availability of the function in the `utf8_strlen` property
# (initially `mb_strlen`). If the function is not available, create a
@@ -1498,14 +1656,14 @@ class Markdown {
}
- protected function unhash($text) {
+ function unhash($text) {
#
# Swap back in all the tags hashed by _HashHTMLBlocks.
#
return preg_replace_callback('/(.)\x1A[0-9]+\1/',
array(&$this, '_unhash_callback'), $text);
}
- protected function _unhash_callback($matches) {
+ function _unhash_callback($matches) {
return $this->html_hashes[$matches[0]];
}
@@ -1513,50 +1671,27 @@ class Markdown {
#
-# Temporary Markdown Extra Parser Implementation Class
-#
-# NOTE: DON'T USE THIS CLASS
-# Currently the implementation of of Extra resides here in this temporary class.
-# This makes it easier to propagate the changes between the three different
-# packaging styles of PHP Markdown. When this issue is resolved, this
-# MarkdownExtra_TmpImpl class here will disappear and \Michelf\MarkdownExtra
-# will contain the code. So please use \Michelf\MarkdownExtra and ignore this
-# one.
+# Markdown Extra Parser Class
#
-class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
-
- ### Configuration Variables ###
+class MarkdownExtra_Parser extends Markdown_Parser {
# Prefix for footnote ids.
- public $fn_id_prefix = "";
+ var $fn_id_prefix = "";
# Optional title attribute for footnote links and backlinks.
- public $fn_link_title = "";
- public $fn_backlink_title = "";
+ var $fn_link_title = MARKDOWN_FN_LINK_TITLE;
+ var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE;
# Optional class attribute for footnote links and backlinks.
- public $fn_link_class = "footnote-ref";
- public $fn_backlink_class = "footnote-backref";
-
- # Class name for table cell alignment (%% replaced left/center/right)
- # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center'
- # If empty, the align attribute is used instead of a class name.
- public $table_align_class_tmpl = '';
-
- # Optional class prefix for fenced code block.
- public $code_class_prefix = "";
- # Class attribute for code blocks goes on the `code` tag;
- # setting this to true will put attributes on the `pre` tag instead.
- public $code_attr_on_pre = false;
+ var $fn_link_class = MARKDOWN_FN_LINK_CLASS;
+ var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS;
# Predefined abbreviations.
- public $predef_abbr = array();
+ var $predef_abbr = array();
- ### Parser Implementation ###
-
- public function __construct() {
+ function MarkdownExtra_Parser() {
#
# Constructor function. Initialize the parser object.
#
@@ -1582,23 +1717,21 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
"doAbbreviations" => 70,
);
- parent::__construct();
+ parent::Markdown_Parser();
}
# Extra variables used during extra transformations.
- protected $footnotes = array();
- protected $footnotes_ordered = array();
- protected $footnotes_ref_count = array();
- protected $footnotes_numbers = array();
- protected $abbr_desciptions = array();
- protected $abbr_word_re = '';
+ var $footnotes = array();
+ var $footnotes_ordered = array();
+ var $abbr_desciptions = array();
+ var $abbr_word_re = '';
# Give the current footnote number.
- protected $footnote_counter = 1;
+ var $footnote_counter = 1;
- protected function setup() {
+ function setup() {
#
# Setting up Extra-specific variables.
#
@@ -1606,8 +1739,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$this->footnotes = array();
$this->footnotes_ordered = array();
- $this->footnotes_ref_count = array();
- $this->footnotes_numbers = array();
$this->abbr_desciptions = array();
$this->abbr_word_re = '';
$this->footnote_counter = 1;
@@ -1620,14 +1751,12 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
}
- protected function teardown() {
+ function teardown() {
#
# Clearing Extra-specific variables.
#
$this->footnotes = array();
$this->footnotes_ordered = array();
- $this->footnotes_ref_count = array();
- $this->footnotes_numbers = array();
$this->abbr_desciptions = array();
$this->abbr_word_re = '';
@@ -1635,114 +1764,26 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- ### Extra Attribute Parser ###
-
- # Expression to use to catch attributes (includes the braces)
- protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}';
- # Expression to use when parsing in a context when no capture is desired
- protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}';
-
- protected function doExtraAttributes($tag_name, $attr) {
- #
- # Parse attributes caught by the $this->id_class_attr_catch_re expression
- # and return the HTML-formatted list of attributes.
- #
- # Currently supported attributes are .class and #id.
- #
- if (empty($attr)) return "";
-
- # Split on components
- preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches);
- $elements = $matches[0];
-
- # handle classes and ids (only first id taken into account)
- $classes = array();
- $id = false;
- foreach ($elements as $element) {
- if ($element{0} == '.') {
- $classes[] = substr($element, 1);
- } else if ($element{0} == '#') {
- if ($id === false) $id = substr($element, 1);
- }
- }
-
- # compose attributes as string
- $attr_str = "";
- if (!empty($id)) {
- $attr_str .= ' id="'.$id.'"';
- }
- if (!empty($classes)) {
- $attr_str .= ' class="'.implode(" ", $classes).'"';
- }
- return $attr_str;
- }
-
-
- protected function stripLinkDefinitions($text) {
- #
- # Strips link definitions from text, stores the URLs and titles in
- # hash references.
- #
- $less_than_tab = $this->tab_width - 1;
-
- # Link defs are in the form: ^[id]: url "optional title"
- $text = preg_replace_callback('{
- ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1
- [ ]*
- \n? # maybe *one* newline
- [ ]*
- (?:
- <(.+?)> # url = $2
- |
- (\S+?) # url = $3
- )
- [ ]*
- \n? # maybe one newline
- [ ]*
- (?:
- (?<=\s) # lookbehind for whitespace
- ["(]
- (.*?) # title = $4
- [")]
- [ ]*
- )? # title is optional
- (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr
- (?:\n+|\Z)
- }xm',
- array(&$this, '_stripLinkDefinitions_callback'),
- $text);
- return $text;
- }
- protected function _stripLinkDefinitions_callback($matches) {
- $link_id = strtolower($matches[1]);
- $url = $matches[2] == '' ? $matches[3] : $matches[2];
- $this->urls[$link_id] = $url;
- $this->titles[$link_id] =& $matches[4];
- $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]);
- return ''; # String that will replace the block
- }
-
-
### HTML Block Parser ###
# Tags that are always treated as block tags:
- protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption';
-
- # Tags treated as block tags only if the opening tag is alone on its line:
- protected $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video';
+ var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend';
+
+ # Tags treated as block tags only if the opening tag is alone on it's line:
+ var $context_block_tags_re = 'script|noscript|math|ins|del';
# Tags where markdown="1" default to span mode:
- protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address';
+ var $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address';
# Tags which must not have their contents modified, no matter where
# they appear:
- protected $clean_tags_re = 'script|math|svg';
+ var $clean_tags_re = 'script|math';
# Tags that do not need to be closed.
- protected $auto_close_tags_re = 'hr|img|param|source|track';
+ var $auto_close_tags_re = 'hr|img';
- protected function hashHTMLBlocks($text) {
+ function hashHTMLBlocks($text) {
#
# Hashify HTML Blocks and "clean tags".
#
@@ -1754,12 +1795,10 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
#
# This works by calling _HashHTMLBlocks_InMarkdown, which then calls
# _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1"
- # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back
+ # attribute is found whitin a tag, _HashHTMLBlocks_InHTML calls back
# _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag.
# These two functions are calling each other. It's recursive!
#
- if ($this->no_markup) return $text;
-
#
# Call the HTML-in-Markdown hasher.
#
@@ -1767,7 +1806,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
return $text;
}
- protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
+ function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
$enclosing_tag_re = '', $span = false)
{
#
@@ -1809,7 +1848,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
# Regex to match any tag.
$block_tag_re =
'{
- ( # $2: Capture whole tag.
+ ( # $2: Capture hole tag.
? # Any opening or closing tag.
(?> # Tag name.
'.$this->block_tags_re.' |
@@ -1845,16 +1884,8 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
)*
|
# Fenced code block marker
- (?<= ^ | \n )
- [ ]{0,'.($indent+3).'}~{3,}
- [ ]*
- (?:
- \.?[-_:a-zA-Z0-9]+ # standalone class name
- |
- '.$this->id_class_attr_nocatch_re.' # extra attributes
- )?
- [ ]*
- \n
+ (?> ^ | \n )
+ [ ]{'.($indent).'}~~~+[ ]*\n
' : '' ). ' # End (if not is span).
)
}xs';
@@ -1916,13 +1947,20 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
}
#
+ # Check for: Indented code block.
+ #
+ else if ($tag{0} == "\n" || $tag{0} == " ") {
+ # Indented code block: pass it unchanged, will be handled
+ # later.
+ $parsed .= $tag;
+ }
+ #
# Check for: Fenced code block marker.
#
- else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) {
+ else if ($tag{0} == "~") {
# Fenced code block marker: find matching end marker.
- $fence_indent = strlen($capture[1]); # use captured indent in re
- $fence_re = $capture[2]; # use captured fence in re
- if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text,
+ $tag_re = preg_quote(trim($tag));
+ if (preg_match('{^(?>.*\n)+?'.$tag_re.' *\n}', $text,
$matches))
{
# End marker found: pass text unchanged until marker.
@@ -1935,14 +1973,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
}
#
- # Check for: Indented code block.
- #
- else if ($tag{0} == "\n" || $tag{0} == " ") {
- # Indented code block: pass it unchanged, will be handled
- # later.
- $parsed .= $tag;
- }
- #
# Check for: Opening Block level tag or
# Opening Context Block tag (like ins and del)
# used as a block tag (tag is alone on it's line).
@@ -2005,7 +2035,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
return array($parsed, $text);
}
- protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) {
+ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) {
#
# Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags.
#
@@ -2036,7 +2066,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
# Regex to match any tag.
$tag_re = '{
- ( # $2: Capture whole tag.
+ ( # $2: Capture hole tag.
? # Any opening or closing tag.
[\w:$]+ # Tag name.
(?:
@@ -2163,7 +2193,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
if (!$span_mode) $parsed .= "\n\n$block_text\n\n";
else $parsed .= "$block_text";
- # Start over with a new block.
+ # Start over a new block.
$block_text = "";
}
else $block_text .= $tag;
@@ -2180,269 +2210,31 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- protected function hashClean($text) {
+ function hashClean($text) {
#
- # Called whenever a tag must be hashed when a function inserts a "clean" tag
- # in $text, it passes through this function and is automaticaly escaped,
+ # Called whenever a tag must be hashed when a function insert a "clean" tag
+ # in $text, it pass through this function and is automaticaly escaped,
# blocking invalid nested overlap.
#
return $this->hashPart($text, 'C');
}
- protected function doAnchors($text) {
+ function doHeaders($text) {
#
- # Turn Markdown link shortcuts into XHTML tags.
- #
- if ($this->in_anchor) return $text;
- $this->in_anchor = true;
-
- #
- # First, handle reference-style links: [link text] [id]
- #
- $text = preg_replace_callback('{
- ( # wrap whole match in $1
- \[
- ('.$this->nested_brackets_re.') # link text = $2
- \]
-
- [ ]? # one optional space
- (?:\n[ ]*)? # one optional newline followed by spaces
-
- \[
- (.*?) # id = $3
- \]
- )
- }xs',
- array(&$this, '_doAnchors_reference_callback'), $text);
-
- #
- # Next, inline-style links: [link text](url "optional title")
- #
- $text = preg_replace_callback('{
- ( # wrap whole match in $1
- \[
- ('.$this->nested_brackets_re.') # link text = $2
- \]
- \( # literal paren
- [ \n]*
- (?:
- <(.+?)> # href = $3
- |
- ('.$this->nested_url_parenthesis_re.') # href = $4
- )
- [ \n]*
- ( # $5
- ([\'"]) # quote char = $6
- (.*?) # Title = $7
- \6 # matching quote
- [ \n]* # ignore any spaces/tabs between closing quote and )
- )? # title is optional
- \)
- (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes
- )
- }xs',
- array(&$this, '_doAnchors_inline_callback'), $text);
-
- #
- # Last, handle reference-style shortcuts: [link text]
- # These must come last in case you've also got [link text][1]
- # or [link text](/foo)
- #
- $text = preg_replace_callback('{
- ( # wrap whole match in $1
- \[
- ([^\[\]]+) # link text = $2; can\'t contain [ or ]
- \]
- )
- }xs',
- array(&$this, '_doAnchors_reference_callback'), $text);
-
- $this->in_anchor = false;
- return $text;
- }
- protected function _doAnchors_reference_callback($matches) {
- $whole_match = $matches[1];
- $link_text = $matches[2];
- $link_id =& $matches[3];
-
- if ($link_id == "") {
- # for shortcut links like [this][] or [this].
- $link_id = $link_text;
- }
-
- # lower-case and turn embedded newlines into spaces
- $link_id = strtolower($link_id);
- $link_id = preg_replace('{[ ]?\n}', ' ', $link_id);
-
- if (isset($this->urls[$link_id])) {
- $url = $this->urls[$link_id];
- $url = $this->encodeAttribute($url);
-
- $result = "titles[$link_id] ) ) {
- $title = $this->titles[$link_id];
- $title = $this->encodeAttribute($title);
- $result .= " title=\"$title\"";
- }
- if (isset($this->ref_attr[$link_id]))
- $result .= $this->ref_attr[$link_id];
-
- $link_text = $this->runSpanGamut($link_text);
- $result .= ">$link_text";
- $result = $this->hashPart($result);
- }
- else {
- $result = $whole_match;
- }
- return $result;
- }
- protected function _doAnchors_inline_callback($matches) {
- $whole_match = $matches[1];
- $link_text = $this->runSpanGamut($matches[2]);
- $url = $matches[3] == '' ? $matches[4] : $matches[3];
- $title =& $matches[7];
- $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]);
-
-
- $url = $this->encodeAttribute($url);
-
- $result = "encodeAttribute($title);
- $result .= " title=\"$title\"";
- }
- $result .= $attr;
-
- $link_text = $this->runSpanGamut($link_text);
- $result .= ">$link_text";
-
- return $this->hashPart($result);
- }
-
-
- protected function doImages($text) {
- #
- # Turn Markdown image shortcuts into
empty_element_suffix\n");
}
- protected function doAnchors($text) {
+ function doAnchors($text) {
#
# Turn Markdown link shortcuts into XHTML tags.
#
@@ -577,7 +739,7 @@ class Markdown {
$this->in_anchor = false;
return $text;
}
- protected function _doAnchors_reference_callback($matches) {
+ function _doAnchors_reference_callback($matches) {
$whole_match = $matches[1];
$link_text = $matches[2];
$link_id =& $matches[3];
@@ -611,7 +773,7 @@ class Markdown {
}
return $result;
}
- protected function _doAnchors_inline_callback($matches) {
+ function _doAnchors_inline_callback($matches) {
$whole_match = $matches[1];
$link_text = $this->runSpanGamut($matches[2]);
$url = $matches[3] == '' ? $matches[4] : $matches[3];
@@ -632,7 +794,7 @@ class Markdown {
}
- protected function doImages($text) {
+ function doImages($text) {
#
# Turn Markdown image shortcuts into tags.
#
@@ -687,7 +849,7 @@ class Markdown {
return $text;
}
- protected function _doImages_reference_callback($matches) {
+ function _doImages_reference_callback($matches) {
$whole_match = $matches[1];
$alt_text = $matches[2];
$link_id = strtolower($matches[3]);
@@ -715,7 +877,7 @@ class Markdown {
return $result;
}
- protected function _doImages_inline_callback($matches) {
+ function _doImages_inline_callback($matches) {
$whole_match = $matches[1];
$alt_text = $matches[2];
$url = $matches[3] == '' ? $matches[4] : $matches[3];
@@ -734,7 +896,7 @@ class Markdown {
}
- protected function doHeaders($text) {
+ function doHeaders($text) {
# Setext-style headers:
# Header 1
# ========
@@ -764,7 +926,7 @@ class Markdown {
return $text;
}
- protected function _doHeaders_callback_setext($matches) {
+ function _doHeaders_callback_setext($matches) {
# Terrible hack to check we haven't found an empty list item.
if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
return $matches[0];
@@ -773,14 +935,14 @@ class Markdown {
$block = "
` blocks.
#
@@ -955,7 +1117,7 @@ class Markdown {
return $text;
}
- protected function _doCodeBlocks_callback($matches) {
+ function _doCodeBlocks_callback($matches) {
$codeblock = $matches[1];
$codeblock = $this->outdent($codeblock);
@@ -969,7 +1131,7 @@ class Markdown {
}
- protected function makeCodeSpan($code) {
+ function makeCodeSpan($code) {
#
# Create a code span markup for $code. Called from handleSpanToken.
#
@@ -978,24 +1140,24 @@ class Markdown {
}
- protected $em_relist = array(
- '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?
@@ -1155,7 +1317,7 @@ class Markdown {
return $text;
}
- protected function _doBlockQuotes_callback($matches) {
+ function _doBlockQuotes_callback($matches) {
$bq = $matches[1];
# trim one level of quoting - trim whitespace-only lines
$bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);
@@ -1169,14 +1331,14 @@ class Markdown {
return "\n". $this->hashBlock("
\n$bq\n
")."\n\n";
}
- protected function _doBlockQuotes_callback2($matches) {
+ function _doBlockQuotes_callback2($matches) {
$pre = $matches[1];
$pre = preg_replace('/^ /m', '', $pre);
return $pre;
}
- protected function formParagraphs($text) {
+ function formParagraphs($text) {
#
# Params:
# $text - string to process with html tags.
- #
- #
- # First, handle reference-style labeled images: ![alt text][id]
- #
- $text = preg_replace_callback('{
- ( # wrap whole match in $1
- !\[
- ('.$this->nested_brackets_re.') # alt text = $2
- \]
-
- [ ]? # one optional space
- (?:\n[ ]*)? # one optional newline followed by spaces
-
- \[
- (.*?) # id = $3
- \]
-
- )
- }xs',
- array(&$this, '_doImages_reference_callback'), $text);
-
- #
- # Next, handle inline images: 
- # Don't forget: encode * and _
- #
- $text = preg_replace_callback('{
- ( # wrap whole match in $1
- !\[
- ('.$this->nested_brackets_re.') # alt text = $2
- \]
- \s? # One optional whitespace character
- \( # literal paren
- [ \n]*
- (?:
- <(\S*)> # src url = $3
- |
- ('.$this->nested_url_parenthesis_re.') # src url = $4
- )
- [ \n]*
- ( # $5
- ([\'"]) # quote char = $6
- (.*?) # title = $7
- \6 # matching quote
- [ \n]*
- )? # title is optional
- \)
- (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes
- )
- }xs',
- array(&$this, '_doImages_inline_callback'), $text);
-
- return $text;
- }
- protected function _doImages_reference_callback($matches) {
- $whole_match = $matches[1];
- $alt_text = $matches[2];
- $link_id = strtolower($matches[3]);
-
- if ($link_id == "") {
- $link_id = strtolower($alt_text); # for shortcut links like ![this][].
- }
-
- $alt_text = $this->encodeAttribute($alt_text);
- if (isset($this->urls[$link_id])) {
- $url = $this->encodeAttribute($this->urls[$link_id]);
- $result = "
titles[$link_id])) {
- $title = $this->titles[$link_id];
- $title = $this->encodeAttribute($title);
- $result .= " title=\"$title\"";
- }
- if (isset($this->ref_attr[$link_id]))
- $result .= $this->ref_attr[$link_id];
- $result .= $this->empty_element_suffix;
- $result = $this->hashPart($result);
- }
- else {
- # If there's no such link ID, leave intact:
- $result = $whole_match;
- }
-
- return $result;
- }
- protected function _doImages_inline_callback($matches) {
- $whole_match = $matches[1];
- $alt_text = $matches[2];
- $url = $matches[3] == '' ? $matches[4] : $matches[3];
- $title =& $matches[7];
- $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]);
-
- $alt_text = $this->encodeAttribute($alt_text);
- $url = $this->encodeAttribute($url);
- $result = "
encodeAttribute($title);
- $result .= " title=\"$title\""; # $title already quoted
- }
- $result .= $attr;
- $result .= $this->empty_element_suffix;
-
- return $this->hashPart($result);
- }
-
-
- protected function doHeaders($text) {
- #
- # Redefined to add id and class attribute support.
+ # Redefined to add id attribute support.
#
# Setext-style headers:
# Header 1 {#header1}
# ========
#
- # Header 2 {#header2 .class1 .class2}
+ # Header 2 {#header2}
# --------
#
$text = preg_replace_callback(
'{
(^.+?) # $1: Header text
- (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes
+ (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # $2: Id attribute
[ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer
}mx',
array(&$this, '_doHeaders_callback_setext'), $text);
@@ -2450,9 +2242,9 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
# atx-style headers:
# # Header 1 {#header1}
# ## Header 2 {#header2}
- # ## Header 2 with closing hashes ## {#header3.class1.class2}
+ # ## Header 2 with closing hashes ## {#header3}
# ...
- # ###### Header 6 {.class2}
+ # ###### Header 6 {#header2}
#
$text = preg_replace_callback('{
^(\#{1,6}) # $1 = string of #\'s
@@ -2460,7 +2252,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
(.+?) # $2 = Header text
[ ]*
\#* # optional closing #\'s (not counted)
- (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes
+ (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # id attribute
[ ]*
\n+
}xm',
@@ -2468,23 +2260,27 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
return $text;
}
- protected function _doHeaders_callback_setext($matches) {
+ function _doHeaders_attr($attr) {
+ if (empty($attr)) return "";
+ return " id=\"$attr\"";
+ }
+ function _doHeaders_callback_setext($matches) {
if ($matches[3] == '-' && preg_match('{^- }', $matches[1]))
return $matches[0];
$level = $matches[3]{0} == '=' ? 1 : 2;
- $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]);
+ $attr = $this->_doHeaders_attr($id =& $matches[2]);
$block = "
\n";
@@ -2627,7 +2410,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- protected function doDefLists($text) {
+ function doDefLists($text) {
#
# Form HTML definition lists.
#
@@ -2669,7 +2452,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
return $text;
}
- protected function _doDefLists_callback($matches) {
+ function _doDefLists_callback($matches) {
# Re-usable patterns to match list item bullets and number markers:
$list = $matches[1];
@@ -2681,7 +2464,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- protected function processDefListItems($list_str) {
+ function processDefListItems($list_str) {
#
# Process the contents of a single definition list, splitting it
# into individual term and definition list items.
@@ -2696,7 +2479,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
(?>\A\n?|\n\n+) # leading line
( # definition terms = $1
[ ]{0,'.$less_than_tab.'} # leading whitespace
- (?!\:[ ]|[ ]) # negative lookahead for a definition
+ (?![:][ ]|[ ]) # negative lookahead for a definition
# mark (colon) or more whitespace.
(?> \S.* \n)+? # actual term (not whitespace).
)
@@ -2710,12 +2493,12 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
\n(\n+)? # leading line = $1
( # marker space = $2
[ ]{0,'.$less_than_tab.'} # whitespace before colon
- \:[ ]+ # definition mark (colon)
+ [:][ ]+ # definition mark (colon)
)
((?s:.+?)) # definition text = $3
(?= \n+ # stop at next definition mark,
(?: # next term or end of text
- [ ]{0,'.$less_than_tab.'} \:[ ] |
+ [ ]{0,'.$less_than_tab.'} [:][ ] |
";
-
+ $codeblock = "$codeblock
";
return "\n\n".$this->hashBlock($codeblock)."\n\n";
}
- protected function _doFencedCodeBlocks_newlines($matches) {
+ function _doFencedCodeBlocks_newlines($matches) {
return str_repeat("$codeblock
empty_element_suffix",
strlen($matches[0]));
}
@@ -2823,24 +2587,24 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
# Redefining emphasis markers so that emphasis by underscore does not
# work in the middle of a word.
#
- protected $em_relist = array(
- '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? tags
@@ -2878,7 +2642,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
### Footnotes
- protected function stripFootnotes($text) {
+ function stripFootnotes($text) {
#
# Strips link definitions from text, stores the URLs and titles in
# hash references.
@@ -2905,14 +2669,14 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$text);
return $text;
}
- protected function _stripFootnotes_callback($matches) {
+ function _stripFootnotes_callback($matches) {
$note_id = $this->fn_id_prefix . $matches[1];
$this->footnotes[$note_id] = $this->outdent($matches[2]);
return ''; # String that will replace the block
}
- protected function doFootnotes($text) {
+ function doFootnotes($text) {
#
# Replace footnote references in $text [^id] with a special text-token
# which will be replaced by the actual footnote marker in appendFootnotes.
@@ -2924,7 +2688,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- protected function appendFootnotes($text) {
+ function appendFootnotes($text) {
#
# Append footnote list to text.
#
@@ -2954,9 +2718,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$footnote = reset($this->footnotes_ordered);
$note_id = key($this->footnotes_ordered);
unset($this->footnotes_ordered[$note_id]);
- $ref_count = $this->footnotes_ref_count[$note_id];
- unset($this->footnotes_ref_count[$note_id]);
- unset($this->footnotes[$note_id]);
$footnote .= "\n"; # Need to append newline before parsing.
$footnote = $this->runBlockGamut("$footnote\n");
@@ -2965,13 +2726,9 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$attr = str_replace("%%", ++$num, $attr);
$note_id = $this->encodeAttribute($note_id);
-
- # Prepare backlink, multiple backlinks if multiple references
- $backlink = "↩";
- for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) {
- $backlink .= " ↩";
- }
+
# Add backlink to last paragraph; create new paragraph if needed.
+ $backlink = "↩";
if (preg_match('{$}', $footnote)) {
$footnote = substr($footnote, 0, -4) . " $backlink";
} else {
@@ -2988,25 +2745,18 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
return $text;
}
- protected function _appendFootnotes_callback($matches) {
+ function _appendFootnotes_callback($matches) {
$node_id = $this->fn_id_prefix . $matches[1];
# Create footnote marker only if it has a corresponding footnote *and*
# the footnote hasn't been used by another marker.
if (isset($this->footnotes[$node_id])) {
- $num =& $this->footnotes_numbers[$node_id];
- if (!isset($num)) {
- # Transfer footnote content to the ordered list and give it its
- # number
- $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
- $this->footnotes_ref_count[$node_id] = 1;
- $num = $this->footnote_counter++;
- $ref_count_mark = '';
- } else {
- $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1;
- }
-
- $attr = "";
+ # Transfert footnote content to the ordered list.
+ $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
+ unset($this->footnotes[$node_id]);
+
+ $num = $this->footnote_counter++;
+ $attr = " rel=\"footnote\"";
if ($this->fn_link_class != "") {
$class = $this->fn_link_class;
$class = $this->encodeAttribute($class);
@@ -3022,7 +2772,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$node_id = $this->encodeAttribute($node_id);
return
- "".
+ "".
"$num".
"";
}
@@ -3033,7 +2783,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
### Abbreviations ###
- protected function stripAbbreviations($text) {
+ function stripAbbreviations($text) {
#
# Strips abbreviations from text, stores titles in hash references.
#
@@ -3048,7 +2798,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
$text);
return $text;
}
- protected function _stripAbbreviations_callback($matches) {
+ function _stripAbbreviations_callback($matches) {
$abbr_word = $matches[1];
$abbr_desc = $matches[2];
if ($this->abbr_word_re)
@@ -3059,7 +2809,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
- protected function doAbbreviations($text) {
+ function doAbbreviations($text) {
#
# Find defined abbreviations in text and wrap them in elements.
#
@@ -3075,7 +2825,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
return $text;
}
- protected function _doAbbreviations_callback($matches) {
+ function _doAbbreviations_callback($matches) {
$abbr = $matches[0];
if (isset($this->abbr_desciptions[$abbr])) {
$desc = $this->abbr_desciptions[$abbr];
@@ -3093,4 +2843,90 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
}
+/*
+
+PHP Markdown Extra
+==================
+
+Description
+-----------
+
+This is a PHP port of the original Markdown formatter written in Perl
+by John Gruber. This special "Extra" version of PHP Markdown features
+further enhancements to the syntax for making additional constructs
+such as tables and definition list.
+
+Markdown is a text-to-HTML filter; it translates an easy-to-read /
+easy-to-write structured text format into HTML. Markdown's text format
+is most similar to that of plain text email, and supports features such
+as headers, *emphasis*, code blocks, blockquotes, and links.
+
+Markdown's syntax is designed not as a generic markup language, but
+specifically to serve as a front-end to (X)HTML. You can use span-level
+HTML tags anywhere in a Markdown document, and you can use block level
+HTML tags (like as well).
+
+For more information about Markdown's syntax, see:
+
+
content,
+ # so we need to fix that:
+ $bq = preg_replace_callback('{(\s*
.+?
)}sx',
+ array(&$this, '_doBlockQuotes_callback2'), $bq);
+
+ $res = "" : " cite=\"$cite\">";
+ $res .= "\n$bq\n
";
+ return "\n". $this->hashBlock($res)."\n\n";
+ }
+
+ function doFencedCodeBlocks($text) {
+ $less_than_tab = $this->tab_width;
+
+ $text = preg_replace_callback('{
+ (?:\n|\A)
+ # 1: Opening marker
+ (
+ ~{3,}|`{3,} # Marker: three tilde or more.
+ )
+
+ [ ]?(\w+)?(?:,[ ]?(\d+))?[ ]* \n # Whitespace and newline following marker.
+
+ # 3: Content
+ (
+ (?>
+ (?!\1 [ ]* \n) # Not a closing marker.
+ .*\n+
+ )+
+ )
+
+ # Closing marker.
+ \1 [ ]* \n
+ }xm',
+ array(&$this, '_doFencedCodeBlocks_callback'), $text);
+
+ return $text;
+ }
+
+ function _doFencedCodeBlocks_callback($matches) {
+ $codeblock = $matches[4];
+ $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
+ $codeblock = preg_replace_callback('/^\n+/',
+ array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock);
+ //$codeblock = "
";
+ //$cb = "$codeblock
";
+ return "\n\n".$this->hashBlock($cb)."\n\n";
+ }
+
+ function doFencedFigures($text){
+ $text = preg_replace_callback('{
+ (?:\n|\A)
+ # 1: Opening marker
+ (
+ ={3,} # Marker: equal sign.
+ )
+
+ [ ]?(?:\[([^\]]+)\])?[ ]* \n # Whitespace and newline following marker.
+
+ # 3: Content
+ (
+ (?>
+ (?!\1 [ ]?(?:\[([^\]]+)\])?[ ]* \n) # Not a closing marker.
+ .*\n+
+ )+
+ )
+
+ # Closing marker.
+ \1 [ ]?(?:\[([^\]]+)\])?[ ]* \n
+ }xm', array(&$this, '_doFencedFigures_callback'), $text);
+
+ return $text;
+ }
+
+ function _doFencedFigures_callback($matches) {
+ # get figcaption
+ $topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]);
+ $bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]);
+ $figure = $matches[3];
+ $figure = $this->runBlockGamut($figure); # recurse
+
+ $figure = preg_replace('/^/m', " ", $figure);
+ # These leading spaces cause problem with " : " class=\"language-$matches[2]\">";
+ $cb .= "$codeblock
content,
+ # so we need to fix that - reuse blockqoute code to handle this:
+ $figure = preg_replace_callback('{(\s*
.+?
)}sx',
+ array(&$this, '_doBlockQuotes_callback2'), $figure);
+
+ $res = "