LuRenJiasWorld / WP-Editor.md

或许这是一个WordPress中最好,最完美的Markdown编辑器
https://wordpress.org/plugins/wp-editormd/
GNU General Public License v3.0
744 stars 87 forks source link

[Feature]Markdown语法中一级标题#能否转为html中的H2标签 #582

Open HW140701 opened 1 year ago

HW140701 commented 1 year ago

该功能的缺失是否引起你的使用不便? | Is your feature request related to a problem?

请详细描述该功能的使用场景,如:我在使用Typora(一款所见即所得的Markdown编辑器桌面软件)的时候发现 [...] A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

现在编辑器中MarkDown语法中一级标题#是转成html中H1标签的。 将MarkDown语法中一级标题#能否转为html中的H2标签,而不是H1标签。 在一个文章页面有多个H1标签不利于网站SEO,或者在插件设置中提供复选框进行可选设置。

你认为该功能应该是什么样的? | Describe the solution you'd like

请清晰描述该功能的存在位置、使用方法以及预期效果 A clear and concise description of what you want to happen.

有类似功能的产品可供参考吗? | Is there some similar software?

如果有类似产品或解决方案,请在这里提供该产品的相关信息 A clear and concise description of any similar solutions or features.

其他信息 | Additional context

请在这里附带上其他可能对新功能开发有帮助的信息 Add any other context or screenshots about the feature request here.

LuRenJiasWorld commented 1 year ago

为什么不在写作时使用 ## 代替 # 呢?因为Markdown的标准实现对标题的定义就是这样的,# 对应 H1,## 对应 H2。

HW140701 commented 1 year ago

额,这样也是可以的,但是好像有点违背习惯,哈哈哈哈

LuRenJiasWorld commented 1 year ago

额,这样也是可以的,但是好像有点违背习惯,哈哈哈哈

其实大部分情况下都是这样的,只是WordPress把标题放在正文之外了,GitHub也是把 ## 作为 H2 处理的。

HW140701 commented 1 year ago

只是个小建议,做SEO优化的一个小trick,功能可加可不加,感谢。

LuRenJiasWorld commented 1 year ago

只是个小建议,做SEO优化的一个小trick,功能可加可不加,感谢。

嗯嗯,可以自己写一个插件来过滤一下,以下代码可供参考:

<?php
/*
Plugin Name: Replace H1 with H2
Plugin URI: https://example.com/
Description: Replace H1 tags with H2 tags in post content
Version: 1.0
Author: Your Name
Author URI: https://example.com/
*/

function replace_h1_with_h2($content) {
    $content = preg_replace('/<h1([^>]*)>/', '<h2$1>', $content);
    $content = preg_replace('/<\/h1>/', '</h2>', $content);
    return $content;
}

add_filter('the_content', 'replace_h1_with_h2');
HW140701 commented 1 year ago

感谢,我之前也是想这么处理,但是想着如果WP-Editor能够原始支持就好了