用marked.js以及MarkdownExtraExtended替换旧的markdown解析引擎

全面支持表格,以及回车换行
This commit is contained in:
joyqi 2013-11-20 11:16:25 +08:00
parent 3873bff06e
commit 10ed729f84
11 changed files with 6962 additions and 7126 deletions

15
.gitattributes vendored Normal file
View File

@ -0,0 +1,15 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.php text eol=lf
*.js text eol=lf
*.css text eol=lf
*.html text eol=lf
*.xml text eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

View File

@ -1,5 +1,6 @@
<?php $content = !empty($post) ? $post : $page; if ($options->markdown && (!$content->have() || $content->isMarkdown)): ?>
<script src="<?php $options->adminUrl('js/markdown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminUrl('js/marked.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminUrl('js/pagedown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminUrl('js/diff.js?v=' . $suffixVersion); ?>"></script>
<script>
$(document).ready(function () {
@ -7,7 +8,7 @@ $(document).ready(function () {
toolbar = $('<div class="editor" id="wmd-button-bar" />').insertBefore(textarea.parent())
preview = $('<div id="wmd-preview" />').insertAfter('.submit');
var converter = new Showdown.converter(), options = {};
var options = {};
options.strings = {
bold: '<?php _e('加粗'); ?> <strong> Ctrl+B',
@ -55,13 +56,36 @@ $(document).ready(function () {
help: '<?php _e('Markdown语法帮助'); ?>'
};
var editor = new Markdown.Editor(converter, '', options),
var editor = new Markdown.Editor(marked, '', options),
diffMatch = new diff_match_patch(), last = '', preview = $('#wmd-preview'),
mark = '@mark' + Math.ceil(Math.random() * 100000000) + '@',
span = '<span class="diff" />';
// 设置markdown
marked.setOptions({
breaks : true
});
// 自动跟随
converter.postConversion = function (html) {
editor.hooks.chain('postMarkdown', function (html) {
html = html.replace(/<\/?(\!doctype|html|head|body|link|title|input|select|button|textarea|style|noscript)[^>]*>/ig, function (all) {
return all.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#039;')
.replace(/"/g, '&quot;');
});
if (html.indexOf('<!--more-->') > 0) {
var parts = html.split(/\s*<\!\-\-more\-\->\s*/),
summary = parts.shift(),
details = parts.join('');
html = '<div class="summary">' + summary + '</div>'
+ '<div class="details">' + details + '</div>';
}
var diffs = diffMatch.diff_main(last, html);
last = html;
@ -110,7 +134,7 @@ $(document).ready(function () {
}
return html;
}
});
editor.hooks.chain('onPreviewRefresh', function () {
var diff = $('.diff', preview);

File diff suppressed because it is too large Load Diff

1168
admin/js/marked.js Normal file

File diff suppressed because it is too large Load Diff

2426
admin/js/pagedown.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +1,68 @@
<!DOCTYPE HTML>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="<?php $this->options->charset(); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><?php $this->archiveTitle(' &raquo; ', '', ' - '); ?><?php $this->options->title(); ?></title>
<!-- 使用url函数转换相关路径 -->
<link rel="stylesheet" href="<?php $this->options->adminUrl('css/normalize.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->adminUrl('css/grid.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>">
<!--[if lt IE 9]>
<script src="<?php $this->options->adminUrl('js/html5shiv.js'); ?>"></script>
<script src="<?php $this->options->adminUrl('js/respond.js'); ?>"></script>
<![endif]-->
<!-- 通过自有函数输出HTML头部信息 -->
<?php $this->header(); ?>
</head>
<body>
<header id="header" class="clearfix">
<div class="container">
<div class="colgroup">
<div class="site-name col-mb-12 col-9">
<a id="logo" href="<?php $this->options->siteUrl(); ?>">
<?php if ($this->options->logoUrl): ?>
<img src="<?php $this->options->logoUrl() ?>" alt="<?php $this->options->title() ?>" />
<?php endif; ?>
<?php $this->options->title() ?>
</a>
<p class="description"><?php $this->options->description() ?></p>
</div>
<div class="site-search col-3 kit-hidden-tb">
<form id="search" method="post" action="./">
<input type="text" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
<button type="submit" class="submit"><?php _e('搜索'); ?></button>
</form>
</div>
<div class="col-mb-12">
<nav id="nav-menu" class="clearfix">
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php while($pages->next()): ?>
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
<?php endwhile; ?>
</nav>
</div>
</div><!-- end .colgroup -->
</div>
</header><!-- end #header -->
<div id="body">
<div class="container">
<div class="colgroup">
<!DOCTYPE HTML>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="<?php $this->options->charset(); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><?php $this->archiveTitle(array(
'category' => _t('分类 %s 下的文章'),
'search' => _t('包含关键字 %s 的文章'),
'tag' => _t('标签 %s 下的文章'),
'author' => _t('%s 发布的文章')
), '', ' - '); ?><?php $this->options->title(); ?></title>
<!-- 使用url函数转换相关路径 -->
<link rel="stylesheet" href="<?php $this->options->adminUrl('css/normalize.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->adminUrl('css/grid.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>">
<!--[if lt IE 9]>
<script src="<?php $this->options->adminUrl('js/html5shiv.js'); ?>"></script>
<script src="<?php $this->options->adminUrl('js/respond.js'); ?>"></script>
<![endif]-->
<!-- 通过自有函数输出HTML头部信息 -->
<?php $this->header(); ?>
</head>
<body>
<header id="header" class="clearfix">
<div class="container">
<div class="colgroup">
<div class="site-name col-mb-12 col-9">
<a id="logo" href="<?php $this->options->siteUrl(); ?>">
<?php if ($this->options->logoUrl): ?>
<img src="<?php $this->options->logoUrl() ?>" alt="<?php $this->options->title() ?>" />
<?php endif; ?>
<?php $this->options->title() ?>
</a>
<p class="description"><?php $this->options->description() ?></p>
</div>
<div class="site-search col-3 kit-hidden-tb">
<form id="search" method="post" action="./">
<input type="text" name="s" class="text" placeholder="<?php _e('输入关键字搜索'); ?>" />
<button type="submit" class="submit"><?php _e('搜索'); ?></button>
</form>
</div>
<div class="col-mb-12">
<nav id="nav-menu" class="clearfix">
<a<?php if($this->is('index')): ?> class="current"<?php endif; ?> href="<?php $this->options->siteUrl(); ?>"><?php _e('首页'); ?></a>
<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php while($pages->next()): ?>
<a<?php if($this->is('page', $pages->slug)): ?> class="current"<?php endif; ?> href="<?php $pages->permalink(); ?>" title="<?php $pages->title(); ?>"><?php $pages->title(); ?></a>
<?php endwhile; ?>
</nav>
</div>
</div><!-- end .colgroup -->
</div>
</header><!-- end #header -->
<div id="body">
<div class="container">
<div class="colgroup">

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,9 +29,10 @@ class Typecho_Widget_Helper_PageNavigator_Box extends Typecho_Widget_Helper_Page
* @param string $nextWord 下一页文字
* @param int $splitPage 分割范围
* @param string $splitWord 分割字符
* @param string $currentClass 当前激活元素class
* @return void
*/
public function render($prevWord = 'PREV', $nextWord = 'NEXT', $splitPage = 3, $splitWord = '...')
public function render($prevWord = 'PREV', $nextWord = 'NEXT', $splitPage = 3, $splitWord = '...', $currentClass)
{
if ($this->_total < 1) {
return;
@ -52,13 +53,13 @@ class Typecho_Widget_Helper_PageNavigator_Box extends Typecho_Widget_Helper_Page
if ($from > 2) {
//输出省略号
echo '<li>' . $splitWord . '</li>';
echo '<li><span>' . $splitWord . '</span></li>';
}
}
//输出中间页
for ($i = $from; $i <= $to; $i ++) {
echo '<li' . ($i != $this->_currentPage ? '' : ' class="current"') . '><a href="' .
echo '<li' . ($i != $this->_currentPage ? '' : ' class="' . $currentClass . '"') . '><a href="' .
str_replace($this->_pageHolder, $i, $this->_pageTemplate) . $this->_anchor . '">'
. $i . '</a></li>';
}
@ -66,7 +67,7 @@ class Typecho_Widget_Helper_PageNavigator_Box extends Typecho_Widget_Helper_Page
//输出最后页
if ($to < $this->_totalPage) {
if ($to < $this->_totalPage - 1) {
echo '<li>' . $splitWord . '</li>';
echo '<li><span>' . $splitWord . '</span></li>';
}
echo '<li><a href="' . str_replace($this->_pageHolder, $this->_totalPage, $this->_pageTemplate) . $this->_anchor . '">'

View File

@ -90,8 +90,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
$content = $this->pluginHandle(__CLASS__)->trigger($plugged)->excerpt($this->text, $this);
if (!$plugged) {
if ($this->isMarkdown) {
$markdown = new Markdown();
$content = $markdown->transform($content);
$content = MarkdownExtraExtended::defaultTransform($content);
} else {
$content = Typecho_Common::cutParagraph($content);
}
@ -119,8 +118,7 @@ class Widget_Abstract_Contents extends Widget_Abstract
if (!$plugged) {
if ($this->isMarkdown) {
$markdown = new Markdown();
$content = $markdown->transform($content);
$content = MarkdownExtraExtended::defaultTransform($content);
} else {
$content = Typecho_Common::cutParagraph($content);
}

View File

@ -1314,7 +1314,8 @@ class Widget_Archive extends Widget_Abstract_Contents
* @param string $splitWord 分割字符
* @return void
*/
public function pageNav($prev = '&laquo;', $next = '&raquo;', $splitPage = 3, $splitWord = '...')
public function pageNav($prev = '&laquo;', $next = '&raquo;', $splitPage = 3, $splitWord = '...',
$class = 'page-navigator', $currentClass = 'current')
{
if ($this->have()) {
$hasNav = false;
@ -1329,8 +1330,8 @@ class Widget_Archive extends Widget_Abstract_Contents
$nav = new Typecho_Widget_Helper_PageNavigator_Box(false === $this->_total ? $this->_total = $this->size($this->_countSql) : $this->_total,
$this->_currentPage, $this->parameter->pageSize, $query);
echo '<ol class="page-navigator">';
$nav->render($prev, $next, $splitPage, $splitWord);
echo '<ol class="' . $class . '">';
$nav->render($prev, $next, $splitPage, $splitWord, $currentClass);
echo '</ol>';
}
}