Skip to content

Commit

Permalink
📖 Add: 章节链接
Browse files Browse the repository at this point in the history
  • Loading branch information
BigCoke233 authored Jan 24, 2020
1 parent e9f89f2 commit cb482ac
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions libs/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ static public function parseContent($data, $widget, $last)
$text = preg_replace('/<img(.*?)src="(.*?)"(.*?)alt="(.*?)"(.*?)>/s','<center><a data-fancybox="gallery" href="${2}" class="gallery-link"><img${1}src="${2}"${3}></a></center>',$text);
//LazyLoad
$text = preg_replace('/<img (.*?)src(.*?)(\/)?>/','<img $1src="/usr/themes/Miracles/images/loading/'.$load_image.'.gif" data-original$2 />',$text);


//章节链接
$reg='/\<h([2-3])(.*?)\>(.*?)\<\/h.*?\>/s';
$text = preg_replace_callback($reg, array('Contents', 'parseHeaderCallback'), $text);

//气泡
$text = preg_replace('/\[bubble\](.*?)\[\/bubble\]/s','<div class="bubble post-bubble"><div class="saying-content"><p>${1}</p></div></div>',$text);

//阴影
//Text Color
$text = preg_replace('/\&\{\"(.*?)\"\|(.*?)\|(.*?)\}/s','<span style="color:${2};background:${3}">${1}</span>',$text);

//ruby
Expand All @@ -43,7 +47,7 @@ static public function parseContent($data, $widget, $last)
$text = preg_replace('/\[tip type="(.*?)"\](.*?)\[\/tip\]/s','<div class="tip ${1}"><div class="container-fluid"><div class="row"><div class="col-1 tip-icon"><i class="iconfont icon-info"></i></div><div class="col-11 tip-content">${2}</div></div></div></div>',$text);
//Tip Group
$text = preg_replace('/\[tip\-group\](.*?)\[\/tip\-group\]/s','<div class="tip-group">${1}</div>',$text);

//解析友链盒子
$reg = '/\[links\](.*?)\[\/links\]/s';
$rp = '<div class="links-box container-fluid"><div class="row">${1}</div></div>';
Expand Down Expand Up @@ -74,6 +78,18 @@ static public function parseContent($data, $widget, $last)
* @param string $table 表名, 支持 contents, comments, metas, users
* @return Widget_Abstract
*/

/**
* 为内容中的标题编号
*/
static private $CurrentTocID = 0;
static public function parseHeaderCallback($matchs)
{
// 增加单独标记,否则冲突
$id = 'toc_'.(self::$CurrentTocID++);
return '<h'.$matchs[1].$matchs[2].' id="'.$id.'">'.$matchs[3].'<a href="#'.$id.'" title="章节链接" class="post-toc-link no-line"><i class="iconfont icon-paragraph"></i></a></h'.$matchs[1].'>';
}

public static function widgetById($table, $pkId)
{
$table = ucfirst($table);
Expand Down

0 comments on commit cb482ac

Please sign in to comment.