This commit is contained in:
Stijn Wouters 2014-01-12 07:02:37 -08:00
commit 792cdfba20
196 changed files with 801 additions and 1051 deletions

View file

View file

@ -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();

View file

7
lib/markdown/LICENSE Normal file
View file

@ -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.

128
lib/markdown/README.md Normal file
View file

@ -0,0 +1,128 @@
# PHP Markdown Extra Extended
An fork of the [PHP Markdown (Extra) project](http://michelf.com/projects/php-markdown/) (<abbr title="PHP Markdown (Extra)">PME</abbr>), 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 `<br />`
In <abbr title="PHP Markdown (Extra)">PME</abbr>, when you want to insert a `<br />` 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 <abbr title="GitHub Flavored Markdown">GFM</abbr>.
Two returns does not insert a `<br />`, 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
<blockquote cite="http://www.whatwg.org/">
<p>Content inside a blockquote must be quoted
from another source, whose address, if it has one,
may be cited in the `cite` attribute.</p>
</blockquote>
```
#### Breaking changes from <abbr title="PHP Markdown (Extra)">PME</abbr>
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
<blockquote>
<p>(Ut brisket flank salami.) Cow cupidatat ex t-bone sirloin id.<br>
Sunt flank pastrami spare ribs sint id, nulla nisi.</p>
</blockquote>
```
### 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 <abbr title="GitHub Flavored Markdown">GFM</abbr>.
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
<p>Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.</p>
~~~
Using alternative fence markers:
```html
<p>Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.</p>
```
Both will output the following HTML:
```HTML
<pre><code class="language-html">
<p>Ut brisket flank salami. Cow cupidatat ex t-bone sirloin id.</p>
</code></pre>
```
### 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
===
![](img/reference.png)
===
```
This example shows a *figure* with a caption added before the content:
```markdown
=== [A **happy face** is good for web developers]
![](img/reference.png)
===
```
This example shows a *figure* with a caption added after the content:
```markdown
===
![](img/reference.png)
=== [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.

View file

@ -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"]
}
}

View file

@ -0,0 +1,162 @@
<?php
require_once('markdown.php');
define( 'MARKDOWNEXTRAEXTENDED_VERSION', "0.3" );
function MarkdownExtended($text, $default_claases = array()){
$parser = new MarkdownExtraExtended_Parser($default_claases);
return $parser->transform($text);
}
class MarkdownExtraExtended_Parser extends MarkdownExtra_Parser {
# Tags that are always treated as block tags:
var $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend';
var $default_classes;
function MarkdownExtraExtended_Parser($default_classes = array()) {
$default_classes = $default_classes;
$this->block_gamut += array(
"doFencedFigures" => 7,
);
parent::MarkdownExtra_Parser();
}
function transform($text) {
$text = parent::transform($text);
return $text;
}
function doHardBreaks($text) {
# Do hard breaks:
# EXTENDED: changed to allow breaks without two spaces and just one new line
# to activate this, uncomment the following code:
# return preg_replace_callback('/ *\n/',
return preg_replace_callback('/ {2,}\n/',
array(&$this, '_doHardBreaks_callback'), $text);
}
function doBlockQuotes($text) {
$text = preg_replace_callback('/
(?>^[ ]*>[ ]?
(?:\((.+?)\))?
[ ]*(.+\n(?:.+\n)*)
)+
/xm',
array(&$this, '_doBlockQuotes_callback'), $text);
return $text;
}
function _doBlockQuotes_callback($matches) {
$cite = $matches[1];
$bq = '> ' . $matches[2];
# trim one level of quoting - trim whitespace-only lines
$bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);
$bq = $this->runBlockGamut($bq); # recurse
$bq = preg_replace('/^/m', " ", $bq);
# These leading spaces cause problem with <pre> content,
# so we need to fix that:
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
array(&$this, '_doBlockQuotes_callback2'), $bq);
$res = "<blockquote";
$res .= empty($cite) ? ">" : " cite=\"$cite\">";
$res .= "\n$bq\n</blockquote>";
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 = "<pre><code>$codeblock</code></pre>";
//$cb = "<pre><code";
$cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code";
$cb .= empty($matches[2]) ? ">" : " class=\"language-$matches[2]\">";
$cb .= "$codeblock</code></pre>";
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 <pre> content,
# so we need to fix that - reuse blockqoute code to handle this:
$figure = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
array(&$this, '_doBlockQuotes_callback2'), $figure);
$res = "<figure>";
if(!empty($topcaption)){
$res .= "\n<figcaption>$topcaption</figcaption>";
}
$res .= "\n$figure\n";
if(!empty($bottomcaption) && empty($topcaption)){
$res .= "<figcaption>$bottomcaption</figcaption>";
}
$res .= "</figure>";
return "\n". $this->hashBlock($res)."\n\n";
}
}
?>

View file

@ -1,5 +1,5 @@
<?php
use \Michelf\MarkdownExtra;
require_once( 'markdown/markdown_extended.php' );
/**
* Pico
@ -138,7 +138,7 @@ class Pico {
{
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
$content = str_replace('%base_url%', $this->base_url(), $content);
$content = MarkdownExtra::defaultTransform($content);
$content = MarkdownExtended($content);
return $content;
}
@ -246,7 +246,7 @@ class Pico {
'date' => isset($page_meta['date']) ? $page_meta['date'] : '',
'date_formatted' => isset($page_meta['date']) ? date($config['date_format'], strtotime($page_meta['date'])) : '',
'content' => $page_content,
'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length)
'excerpt' => $this->limit_words($page_content, $excerpt_length)
);
// Extend the data provided with each page by hooking into the data array

Some files were not shown because too many files have changed in this diff Show more