您的位置 首页 linux 运维

notepad++ 工具(markdown 清除格式)

notepad++ 工具(markdown 清除格式)

这个脚本会:
移除 Markdown 的标题符号(###)。
移除加粗符号(**)。
保留列表结构(1. 和 -),仅去除格式符号,保留你想要的纯文本列表格式。

 

如果你安装了 Notepad++ 的 Python 脚本插件,这是最简单的方法,它可以一键清除所有 Markdown 语法。

1 安装插件:如果未安装,可通过“插件管理器”安装 Python Script

2 新建脚本

点击菜单栏的 Plugins > Python Script > New Script

命名为 RemoveMarkdown.py

3 粘贴代码:将以下代码复制到文件中,然后保存。

RemoveMarkdown.py  内容如下:

# -*- coding: utf-8 -*-
import re

def remove_markdown_format(text):
    # 1. 移除标题 ### 符号
    text = re.sub(r'^\s*#{1,}\s*', '', text, flags=re.MULTILINE)
    
    # 2. 移除加粗 **文本** 和斜体 *文本*
    text = re.sub(r'\*{1,2}([^*]+)\*{1,2}', r'\1', text)
    
    # 3. 移除行内代码 `code`
    text = re.sub(r'`([^`]+)`', r'\1', text)
    
    # 4. 移除无序列表前的 "-" 符号(保留空格缩进)
    # 匹配行首的 "- " 并替换为空,但保留前面的空格用于缩进
    text = re.sub(r'(^|\n)(\s*)-\s+', r'\1\2', text)
    
    # 5. 移除有序列表前的 "数字." 符号
    # 匹配行首的 "数字. " 并替换为空,保留前面的空格
    text = re.sub(r'(^|\n)(\s*)\d+\.\s+', r'\1\2', text)
    
    # 6. 清理可能残留的多余空格(可选)
    # text = re.sub(r'[ \t]+$', '', text, flags=re.MULTILINE)
    
    return text

# 获取当前编辑器的全部文本
original_text = editor.getText()

# 执行转换
cleaned_text = remove_markdown_format(original_text)

# 将转换后的文本写回编辑器
editor.setText(cleaned_text)

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章