Source for file AlphaMarkdown.inc
Documentation is available at AlphaMarkdown.inc
require_once $config->get('sysRoot'). 'alpha/lib/markdown/markdown.php';
require_once $config->get('sysRoot'). 'alpha/view/widgets/Image.inc';
* A custom version of the markdown class which uses the geshi library for rendering code
* @author John Collins <dev@alphaframework.org>
* @version $Id: AlphaMarkdown.inc 1454 2011-12-04 15:14:05Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Custom version of the _doCodeBlocks_callback method which invokes a Gheshi
$codeblock = $matches[1];
$codeblock = $this->outdent($codeblock);
// trim leading newlines and trailing whitespace
$codeblock = preg_replace(array('/\A\n+/', '/\n+\z/'), '', $codeblock);
// find the code block and replace it with a blank
preg_match('/codeType=\[.*\]/', $codeblock, $codeTypeTag);
$codeblock = preg_replace('/codeType=\[.*\]\n/', '', $codeblock);
if(isset ($codeTypeTag[0])) {
$start = strpos($codeTypeTag[0], '[');
$end = strpos($codeTypeTag[0], ']');
$language = substr($codeTypeTag[0], $start+ 1, $end- ($start+ 1));
// will use php as a defualt language type when none is provided
fopen('geshi.php', 'r', true);
require_once 'geshi.php';
$geshi = new GeSHi($codeblock, $language);
$codeblock = $geshi->parse_code();
$result = "\n\n". $this->hashBlock("<pre><code>" . $codeblock . "\n</code></pre>"). "\n\n";
* Custom _doAnchors_inline_callback that renders links to external sites with a
* target attribute and an icon.
$whole_match = $matches[1];
$link_text = $this->runSpanGamut($matches[2]);
* Only an external link if:
* 1. $url parses to a valid URL
* 2. $url has a host part
* 3. $url does not contain $config->get('sysURL'), i.e. points to a local resource.
if(is_array($parts) && isset ($parts['host']) && strpos($url, $config->get('sysURL')) === false)
$url = $this->encodeAmpsAndAngles($url);
$result = "<a href=\"$url\"";
$title = $this->encodeAmpsAndAngles($title);
$result .= " title=\"$title\"";
$result .= " target=\"$url\"";
$link_text = $this->runSpanGamut($link_text);
$result .= ">$link_text</a>";
$result .= '>'. $link_text. '<img src="'. $config->get('sysURL'). 'alpha/images/icons/page_go.png'. '" class="externalLink"/></a>';
return $this->hashSpan($result);
* Custom version of the _doTable_callback(...) method which sets the table border and CSS style
$underline = $matches[2];
# Remove any tailing pipes for each line.
# Reading alignement from header underline.
$separators = preg_split('/ *[|] */', $underline);
foreach ($separators as $n => $s) {
if (preg_match('/^ *-+: *$/', $s)) $attr[$n] = ' align="right"';
else if (preg_match('/^ *:-+: *$/', $s))$attr[$n] = ' align="center"';
else if (preg_match('/^ *:-+ *$/', $s)) $attr[$n] = ' align="left"';
# Creating code spans before splitting the row is an easy way to
# handle a code span containg pipes.
$head = $this->doCodeSpans($head);
$col_count = count($headers);
$text = "<table class=\"bordered\" border=\"1\">\n";
foreach ($headers as $n => $header)
$text .= " <th$attr[$n]>". $this->runSpanGamut(trim($header)). "</th>\n";
foreach ($rows as $row) {
# Creating code spans before splitting the row is an easy way to
# handle a code span containg pipes.
$row = $this->doCodeSpans($row);
$row_cells = preg_split('/ *[|] */', $row, $col_count);
$row_cells = array_pad($row_cells, $col_count, '');
foreach ($row_cells as $n => $cell)
$text .= " <td$attr[$n]>". $this->runSpanGamut(trim($cell)). "</td>\n";
return $this->hashBlock($text) . "\n";
|