如何让 WordPress 以 Markdown 格式保存评论?
我喜欢 Markdown,并且我有 Wordpress markdown-for-wordpress-and -bbpress 解析我的帖子和评论中的降价。
但是,我注意到 WordPress 保存以 html 格式呈现的评论。这使得返回并编辑评论变得更加困难。如何让 WordPress 以 Markdown 格式保存评论?
我找不到它的插件。也许有一个简单的 php hack ?
编辑:
也许它不是内置于 wordpress 的。如果没有 Markdown 插件,评论通常不会以任何标记保存。可能是 wordpress 和 bbpress 的降价“功能”/意外吗?
交叉发布到 wordpress.stackexchange。 com。 BAinternet 有一些保存评论标记的好主意,例如在保存标记插件中,但还没有可行的解决方案。
部分破解
可能有帮助吗?可能取决于主题。有时列表仍然会保存渲染。
在 wp-content/plugins/markdown-for-wordpress-and-bbpress/markdown.php
中注释掉 pre_comment_content
markdown筛选
if (MARKDOWN_WP_COMMENTS) {
remove_filter('comment_text', 'wpautop', 30);
remove_filter('comment_text', 'make_clickable');
#HACK don't save comments rendered in HTML
#add_filter('pre_comment_content', 'Markdown', 6);
add_filter('pre_comment_content', 'mdwp_hide_tags', 8);
add_filter('pre_comment_content', 'mdwp_show_tags', 12);
add_filter('get_comment_text', 'Markdown', 6);
add_filter('get_comment_excerpt', 'Markdown', 6);
add_filter('get_comment_excerpt', 'mdwp_strip_p', 7);
I love markdown, and I have the Wordpress markdown-for-wordpress-and-bbpress parsing markdown in my posts and comments.
However, I've noticed that Wordpress saves the comments rendered in html format. This makes it more difficult to go back and edit comments. How can I get wordpress to save comments in markdown format?
I couldn't find a plugin for it. Maybe there's an easy php hack?
Edit:
Maybe it's not builtin to wordpress. Comments normally not saved with any markup without the markdown plugin. Could be a markdown-for-wordpress-and-bbpress "feature" / accident?
Cross-posted to wordpress.stackexchange.com. BAinternet had some good ideas of saving markup for comments like in the markup-on-save plugin, but no working solution yet.
Partial hack
may help? May be theme-dependent. Lists still get saved rendered sometimes.
In wp-content/plugins/markdown-for-wordpress-and-bbpress/markdown.php
comment out the pre_comment_content
markdown filter
if (MARKDOWN_WP_COMMENTS) {
remove_filter('comment_text', 'wpautop', 30);
remove_filter('comment_text', 'make_clickable');
#HACK don't save comments rendered in HTML
#add_filter('pre_comment_content', 'Markdown', 6);
add_filter('pre_comment_content', 'mdwp_hide_tags', 8);
add_filter('pre_comment_content', 'mdwp_show_tags', 12);
add_filter('get_comment_text', 'Markdown', 6);
add_filter('get_comment_excerpt', 'Markdown', 6);
add_filter('get_comment_excerpt', 'mdwp_strip_p', 7);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好问题。由于此功能在 Wordpress 插件中不可用,您需要进行一些修改,至少阻止它以 HTML 格式保存(您已经这样做了)。
现在,您需要在显示注释时将 markdown 处理为 HTML。因此,让我们使用
comment_text
挂钩:如果您不希望原始代码感觉像“ hackery”——将其变成一项功能。在 Markdown.php
$save_format = 'html'
或$save_format = 'markdown'
中添加一个配置选项,然后检查是否要执行 stripper 函数。事实上,你可以非常聪明,将所有这些变成 Markdown.php 中的一个函数(并且记得告诉作者你的新功能,他甚至可能更新他的原始代码;)Nice question. As this feature is not available in the Wordpress plugin, you'll need to do some hackery at least to stop it from saving in HTML format, which you have done.
Now you need for when the comments are displayed to process that markdown into HTML. So let's use the
comment_text
hook:If you don't want your original code to feel like "hackery" -- turn it into a feature. Add a config option to the Markdown.php
$save_format = 'html'
or$save_format = 'markdown'
then check if you want to execute the stripper function or not. In fact, you could be really smart and turn all of this into a function inside of Markdown.php (and remember to tell the author about your new feature, he might even update his original code ;)我想你可以使用 http://adambrown.info/p/wp_hooks/hook/comment_save_pre-hook 来操作数据。
I guess u can use the http://adambrown.info/p/wp_hooks/hook/comment_save_pre-hook to manipulate the data.