使用SED命令删除Markdown文件中的代码块

时间:2019-05-20 07:50:38

标签: linux unix sed markdown

我有一篇文章是降价文档( fit('should show menu', () => { component.menuTrigger.openMenu() } )文件。它具有如下代码围栏

*.md

我正在使用自动拼写检查器工具来检查脚本调用的文档中的拼写。在我为输入提供拼写检查工具之前,是否可以删除代码围栏块。在Unix中可以使用 SED 命令。

请求所有退伍军人的帮助。

编辑更加清晰。下面是我的脚本:

```
My code fence
```

运行命令时出现以下错误:

#!/bin/bash
TEXT_CONTENT=`cat $(echo python_tips.md | sed -E ':a;N;$!ba;s/\n/ /g')`
TEXT_CONTENT=`echo "$TEXT_CONTENT" | sed -E 's/\{:([^\}]+)\}//g'`
TEXT_CONTENT=`echo "$TEXT_CONTENT" | sed -E 's/<([^<]+)>//g'`
TEXT_CONTENT=`echo "$TEXT_CONTENT" | sed -E 's/http(s)?:\/\/([^ ]+)//g'`
TEXT_CONTENT=`echo "$TEXT_CONTENT" | sed  -n '/```/,/```/ !p'`
echo $TEXT_CONTENT

2 个答案:

答案 0 :(得分:1)

是的,可以使用地址范围和 d 删除命令。

sed '/```/,//d' file

答案 1 :(得分:1)

输入:

$ cat input.md
Indent every line of the block by at least 4 spaces.

This is a normal paragraph:

    This is a code block.
    With multiple lines.

Alternatively, you can use 3 backtick quote marks ``` before and after the block, like this:

```
This is a code block
```

however, this ``` sample ``` is not a code block.

To add syntax highlighting to a code block, add the name of the language immediately
after the backticks: 

```javascript
var oldUnload = window.onbeforeunload;
window.onbeforeunload = function() {
    saveCoverage();
    if (oldUnload) {
        return oldUnload.apply(this, arguments);
    }
};
```

CMD:

sed '/^```/,/^```/d' input.md

输出:

$ sed '/^```/,/^```/d' input.md
Indent every line of the block by at least 4 spaces.

This is a normal paragraph:

    This is a code block.
    With multiple lines.

Alternatively, you can use 3 backtick quote marks ``` before and after the block, like this:


however, this ``` sample ``` is not a code block.

To add syntax highlighting to a code block, add the name of the language immediately
after the backticks: