那么输出的时候,在遇到<!--more-->时终止输出,只输出摘要。
使用Python Markdown保存了用户原始输入数据,那么这个<!--more-->应该怎么融入进去,同时输出时遇到这个标记时终止,只输出摘要。
希望有人能跟我讲解下这个原理是怎么实现的?需要用到哪些函数方法?
那么输出的时候,在遇到<!--more-->时终止输出,只输出摘要。
使用Python Markdown保存了用户原始输入数据,那么这个<!--more-->应该怎么融入进去,同时输出时遇到这个标记时终止,只输出摘要。
希望有人能跟我讲解下这个原理是怎么实现的?需要用到哪些函数方法?
来,给你看下wordpress恶心的代码
function get_extended($post) {
//Match the new style more links
if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) {
list($main, $extended) = explode($matches[0], $post, 2);
$more_text = $matches[1];
} else {
$main = $post;
$extended = '';
$more_text = '';
}
// Strip leading and trailing whitespace
$main = preg_replace('/^[s]*(.*)[s]*$/', '\1', $main);
$extended = preg_replace('/^[s]*(.*)[s]*$/', '\1', $extended);
$more_text = preg_replace('/^[s]*(.*)[s]*$/', '\1', $more_text);
return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text );
}
wordpress的code @kankana已贴,那么补充一些实现方式
javascript版本
'正文内容<!--more-->截断更多内容'.split('<!--more-->')[0];返回 '正文内容'
$errrr=explode('<!--more-->','正文内容<!--more-->截断更多内容');
echo $errrr[0]输出 '正文内容'
lz是想用jekyll么,可以试试postmore.rb这个plugin,创建一个Liquid过滤器过滤掉不需要现实的内容,详情请猛戳 https://github.com/tokkonopapa/jekyll... 。
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号