add newline break support

This commit is contained in:
祁宁 2014-09-27 11:44:56 +08:00
parent fbda6bc514
commit 4a50198f6e
21 changed files with 97 additions and 84 deletions

View File

@ -1752,31 +1752,23 @@ a.operate-reply {
/* 上传面板动画效果 */
@keyframes fullscreen-upload {
0% {
opacity: 0;
right: -280px; }
100% {
opacity: 1;
right: -1px; } }
@-moz-keyframes fullscreen-upload {
0% {
opacity: 0;
right: -280px; }
100% {
opacity: 1;
right: -1px; } }
@-webkit-keyframes fullscreen-upload {
0% {
opacity: 0;
right: -280px; }
100% {
opacity: 1;
right: -1px; } }
@-o-keyframes fullscreen-upload {
0% {
opacity: 0;
right: -280px; }
100% {
opacity: 1;
right: -1px; } }
/* 编辑器全屏 */
/* line 174, ../scss/components/_editor.scss */

View File

@ -582,7 +582,7 @@ var parseNewline = function(inlines) {
if (last && last.t == 'Str' && last.c.slice(-1) == ' ') {
last.c = last.c.slice(0, -1);
}
inlines.push({ t: 'Softbreak' });
inlines.push({ t: 'Hardbreak' });
}
return 1;
} else {

View File

@ -168,12 +168,21 @@
};
})($);
(function () {
(function () {
Typecho.Markdown = function () {
this.writer = new stmd.HtmlRenderer();
this.reader = new stmd.DocParser();
/* begin hardbreak hack */
var w = this.writer, r = w.renderInline;
w.renderInline = function (inline) {
if (inline.t == 'Softbreak') inline.t = 'Hardbreak';
return r.call(w, inline);
};
/* end hardbreak hack */
this.hooks = new Markdown.HookCollection()
this.hooks.addNoop('postConversion');
};

View File

@ -150,23 +150,23 @@
/* 上传面板动画效果 */
@keyframes fullscreen-upload {
0% {opacity: 0; right: -280px; }
100% {opacity: 1; right: -1px; }
0% { right: -280px; }
100% { right: -1px; }
}
@-moz-keyframes fullscreen-upload {
0% {opacity: 0; right: -280px; }
100% {opacity: 1; right: -1px; }
0% { right: -280px; }
100% { right: -1px; }
}
@-webkit-keyframes fullscreen-upload {
0% {opacity: 0; right: -280px; }
100% {opacity: 1; right: -1px; }
0% { right: -280px; }
100% { right: -1px; }
}
@-o-keyframes fullscreen-upload {
0% {opacity: 0; right: -280px; }
100% {opacity: 1; right: -1px; }
0% { right: -280px; }
100% { right: -1px; }
}
/* 编辑器全屏 */

View File

@ -37,6 +37,7 @@ commonmark-php:
rm -rf ../var/CommonMark
git clone git@github.com:colinodell/commonmark-php.git commonmark
php transfer.php commonmark/src CommonMark ColinODell/CommonMark
rm -f commonmark/src/CommonMarkConverter.php
mv commonmark/src ../var/CommonMark
rm -rf commonmark

View File

@ -49,7 +49,7 @@ foreach ($lists as $file) {
$current = $matches[1];
}
return '';
return "if (!defined('__TYPECHO_ROOT_DIR__')) exit;";
}, $source);
$source = preg_replace_callback("/\nuse\s*([a-z_\\\]+)(?:\s+as\s+([a-z_\\\]+))?;/is", function ($matches) use ($map, &$replace) {

View File

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the commonmark-php package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on stmd.js
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Converts CommonMark-compatible Markdown to HTML
*/
class CommonMark_CommonMarkConverter
{
/**
* Converts CommonMark to HTML
* @param string $commonMark
*
* @return string
*
* @api
*/
public function convertToHtml($commonMark)
{
$docParser = new CommonMark_DocParser();
$renderer = new CommonMark_HtmlRenderer();
$documentAST = $docParser->parse($commonMark);
$html = $renderer->render($documentAST);
return $html;
}
}

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Inline element

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
interface CommonMark_Element_InlineElementInterface
{

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* A collection of references, indexed by label

View File

@ -8,7 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Array collection

View File

@ -11,7 +11,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Provides regular expressions and utilties for parsing Markdown

62
var/Markdown.php Normal file
View File

@ -0,0 +1,62 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 扩展htmlrender使得其支持行内换行
*
* @package Markdown
* @copyright Copyright (c) 2014 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class HtmlRendererExtra extends CommonMark_HtmlRenderer
{
/**
* renderInline
*
* @param CommonMark_Element_InlineElementInterface $inline
* @access public
* @return void
*/
public function renderInline(CommonMark_Element_InlineElementInterface $inline)
{
if ($inline->getType() == CommonMark_Element_InlineElement::TYPE_SOFTBREAK) {
$inline->setType(CommonMark_Element_InlineElement::TYPE_HARDBREAK);
}
return parent::renderInline($inline);
}
}
/**
* Markdown解析
*
* @package Markdown
* @copyright Copyright (c) 2014 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Markdown
{
/**
* convert
*
* @param string $text
* @return string
*/
public static function convert($text)
{
static $docParser, $renderer;
if (empty($docParser)) {
$docParser = new CommonMark_DocParser();
}
if (empty($renderer)) {
$renderer = new HtmlRendererExtra();
}
$doc = $docParser->parse($text);
return $renderer->render($doc);
}
}

View File

@ -475,13 +475,7 @@ class Widget_Abstract_Comments extends Widget_Abstract
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
if (!$parsed) {
static $parser;
if (empty($parser)) {
$parser = new CommonMark_CommonMarkConverter();
}
$html = $parser->convertToHtml($text);
$html = Markdown::convert($text);
}
return $html;

View File

@ -959,13 +959,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
$html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text);
if (!$parsed) {
static $parser;
if (empty($parser)) {
$parser = new CommonMark_CommonMarkConverter();
}
$html = $parser->convertToHtml($text);
$html = Markdown::convert($text);
}
return $html;