mirror of
https://github.com/mashirozx/sakura.git
synced 2024-11-25 08:18:14 +08:00
评论Markdown解析
This commit is contained in:
parent
c025d6b6ff
commit
8f648d6819
@ -1655,4 +1655,53 @@ if (akina_option('sakura_widget')) {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// 评论Markdown解析
|
||||
function markdown_parser($incoming_comment) {
|
||||
global $wpdb,$comment_markdown_content;
|
||||
$myCustomer = $wpdb->get_row("SELECT * FROM wp_comments");
|
||||
//Add column if not present.
|
||||
if (!isset($myCustomer->say_state)) {
|
||||
$wpdb->query("ALTER TABLE wp_comments ADD comment_markdown text");
|
||||
}
|
||||
$comment_markdown_content = $incoming_comment['comment_content'];
|
||||
include 'inc/Parsedown.php';
|
||||
$Parsedown = new Parsedown();
|
||||
$incoming_comment['comment_content'] = $Parsedown->text($incoming_comment['comment_content']);
|
||||
return $incoming_comment;
|
||||
}
|
||||
add_filter('preprocess_comment' , 'markdown_parser');
|
||||
|
||||
//保存Markdown评论
|
||||
function save_markdown_comment($comment_ID, $comment_approved) {
|
||||
global $wpdb,$comment_markdown_content;
|
||||
$comment = get_comment($comment_ID);
|
||||
$comment_content = $comment_markdown_content;
|
||||
//store markdow content
|
||||
$wpdb->query("UPDATE wp_comments SET comment_markdown='".$comment_content."' WHERE comment_ID='".$comment_ID."';");
|
||||
}
|
||||
add_action('comment_post', 'save_markdown_comment', 10, 2);
|
||||
|
||||
//打开评论HTML标签限制
|
||||
function allow_more_tag_in_comment() {
|
||||
global $allowedtags;
|
||||
$allowedtags['pre'] = array('class'=>array());
|
||||
$allowedtags['code'] = array('class'=>array());
|
||||
$allowedtags['h1'] = array('class'=>array());
|
||||
$allowedtags['h2'] = array('class'=>array());
|
||||
$allowedtags['h3'] = array('class'=>array());
|
||||
$allowedtags['h4'] = array('class'=>array());
|
||||
$allowedtags['h5'] = array('class'=>array());
|
||||
$allowedtags['ul'] = array('class'=>array());
|
||||
$allowedtags['ol'] = array('class'=>array());
|
||||
$allowedtags['li'] = array('class'=>array());
|
||||
$allowedtags['td'] = array('class'=>array());
|
||||
$allowedtags['th'] = array('class'=>array());
|
||||
$allowedtags['tr'] = array('class'=>array());
|
||||
$allowedtags['table'] = array('class'=>array());
|
||||
$allowedtags['thead'] = array('class'=>array());
|
||||
$allowedtags['tbody'] = array('class'=>array());
|
||||
$allowedtags['span'] = array('class'=>array());
|
||||
}
|
||||
add_action('pre_comment_on_post', 'allow_more_tag_in_comment');
|
||||
//code end
|
||||
|
@ -17,7 +17,7 @@ class Parsedown
|
||||
{
|
||||
# ~
|
||||
|
||||
const version = '1.7.1';
|
||||
const version = '1.7.3';
|
||||
|
||||
# ~
|
||||
|
||||
@ -429,7 +429,21 @@ class Parsedown
|
||||
|
||||
if (isset($matches[1]))
|
||||
{
|
||||
$class = 'language-'.$matches[1];
|
||||
/**
|
||||
* https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes
|
||||
* Every HTML element may have a class attribute specified.
|
||||
* The attribute, if specified, must have a value that is a set
|
||||
* of space-separated tokens representing the various classes
|
||||
* that the element belongs to.
|
||||
* [...]
|
||||
* The space characters, for the purposes of this specification,
|
||||
* are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab),
|
||||
* U+000A LINE FEED (LF), U+000C FORM FEED (FF), and
|
||||
* U+000D CARRIAGE RETURN (CR).
|
||||
*/
|
||||
$language = substr($matches[1], 0, strcspn($matches[1], " \t\n\f\r"));
|
||||
|
||||
$class = 'language-'.$language;
|
||||
|
||||
$Element['attributes'] = array(
|
||||
'class' => $class,
|
||||
|
Loading…
Reference in New Issue
Block a user