修复 grep 页面排版问题 #80

This commit is contained in:
jaywcjlove 2019-04-18 16:43:22 +08:00
parent 36bec7c94c
commit 4f3c1f3d21
2 changed files with 28 additions and 38 deletions

View File

@ -20,13 +20,14 @@ renderer.heading = (text, level) => {
marked.setOptions({ marked.setOptions({
renderer: renderer, renderer: renderer,
pedantic: false,
gfm: true, gfm: true,
tables: true, tables: true,
breaks: false, breaks: false,
pedantic: false,
sanitize: false, sanitize: false,
smartLists: true, smartLists: true,
smartypants: false, smartypants: false,
xhtml: false,
highlight: (code, lang, callback) => { highlight: (code, lang, callback) => {
if (/(tex)$/.test(lang)) lang = 'latex'; if (/(tex)$/.test(lang)) lang = 'latex';
if (/(h)$/.test(lang)) lang = 'c'; if (/(h)$/.test(lang)) lang = 'c';
@ -48,6 +49,10 @@ marked.setOptions({
if (Prism.languages[lang]) { if (Prism.languages[lang]) {
html = Prism.highlight(code, Prism.languages[lang], lang); html = Prism.highlight(code, Prism.languages[lang], lang);
} }
if (lang === 'markdown') {
html.toString();
html = html.replace(/\$/g, '$')
}
return callback('', html); return callback('', html);
} }
}); });

View File

@ -65,110 +65,97 @@ x\{m,n\} # 重复字符x至少m次不多于n次'o\{5,10\}'匹配
在文件中搜索一个单词,命令会返回一个包含 **“match_pattern”** 的文本行: 在文件中搜索一个单词,命令会返回一个包含 **“match_pattern”** 的文本行:
``` ```bash
grep match_pattern file_name grep match_pattern file_name
grep "match_pattern" file_name grep "match_pattern" file_name
``` ```
在多个文件中查找: 在多个文件中查找:
``` ```bash
grep "match_pattern" file_1 file_2 file_3 ... grep "match_pattern" file_1 file_2 file_3 ...
``` ```
输出除之外的所有行 **-v** 选项: 输出除之外的所有行 **-v** 选项:
``` ```bash
grep -v "match_pattern" file_name grep -v "match_pattern" file_name
``` ```
标记匹配颜色 **--color=auto** 选项: 标记匹配颜色 **--color=auto** 选项:
``` ```bash
grep "match_pattern" file_name --color=auto grep "match_pattern" file_name --color=auto
``` ```
使用正则表达式 **-E** 选项: 使用正则表达式 **-E** 选项:
``` ```bash
grep -E "[1-9]+" grep -E "[1-9]+"
#
egrep "[1-9]+" egrep "[1-9]+"
``` ```
只输出文件中匹配到的部分 **-o** 选项: 只输出文件中匹配到的部分 **-o** 选项:
``` ```bash
echo this is a test line. | grep -o -E "[a-z]+\." echo this is a test line. | grep -o -E "[a-z]+\."
line. line.
echo this is a test line. | egrep -o "[a-z]+\." echo this is a test line. | egrep -o "[a-z]+\."
line. line.
``` ```
统计文件或者文本中包含匹配字符串的行数 **-c** 选项: 统计文件或者文本中包含匹配字符串的行数 **-c** 选项:
``` ```bash
grep -c "text" file_name grep -c "text" file_name
``` ```
输出包含匹配字符串的行数 **-n** 选项: 输出包含匹配字符串的行数 **-n** 选项:
``` ```bash
grep "text" -n file_name grep "text" -n file_name
#
cat file_name | grep "text" -n cat file_name | grep "text" -n
#多个文件 #多个文件
grep "text" -n file_1 file_2 grep "text" -n file_1 file_2
``` ```
打印样式匹配所位于的字符或字节偏移: 打印样式匹配所位于的字符或字节偏移:
``` ```bash
echo gun is not unix | grep -b -o "not" echo gun is not unix | grep -b -o "not"
7:not 7:not
#一行中字符串的字符便宜是从该行的第一个字符开始计算起始值为0。选项 **-b -o** 一般总是配合使用。 #一行中字符串的字符便宜是从该行的第一个字符开始计算起始值为0。选项 **-b -o** 一般总是配合使用。
``` ```
搜索多个文件并查找匹配文本在哪些文件中: 搜索多个文件并查找匹配文本在哪些文件中:
``` ```bash
grep -l "text" file1 file2 file3... grep -l "text" file1 file2 file3...
``` ```
### grep递归搜索文件 ### grep递归搜索文件
在多级目录中对文本进行递归搜索: 在多级目录中对文本进行递归搜索:
``` ```bash
grep "text" . -r -n grep "text" . -r -n
# .表示当前目录。 # .表示当前目录。
``` ```
忽略匹配样式中的字符大小写: 忽略匹配样式中的字符大小写:
``` ```bash
echo "hello world" | grep -i "HELLO" echo "hello world" | grep -i "HELLO"
hello # hello
``` ```
选项 **-e** 制动多个匹配样式: 选项 **-e** 制动多个匹配样式:
``` ```bash
echo this is a text line | grep -e "is" -e "line" -o echo this is a text line | grep -e "is" -e "line" -o
is is
line line
@ -179,12 +166,11 @@ aaa
bbb bbb
echo aaa bbb ccc ddd eee | grep -f patfile -o echo aaa bbb ccc ddd eee | grep -f patfile -o
``` ```
在grep搜索结果中包括或者排除指定文件 在grep搜索结果中包括或者排除指定文件
``` ```bash
# 只在目录中所有的.php和.html文件中递归搜索字符"main()" # 只在目录中所有的.php和.html文件中递归搜索字符"main()"
grep "main()" . -r --include *.{php,html} grep "main()" . -r --include *.{php,html}
@ -207,7 +193,6 @@ echo "aaa" > file3
grep "aaa" file* -lZ | xargs -0 rm grep "aaa" file* -lZ | xargs -0 rm
# 执行后会删除file1和file3grep输出用-Z选项来指定以0值字节作为终结符文件名\0xargs -0 读取输入并用0值字节终结符分隔文件名然后删除匹配文件-Z通常和-l结合使用。 # 执行后会删除file1和file3grep输出用-Z选项来指定以0值字节作为终结符文件名\0xargs -0 读取输入并用0值字节终结符分隔文件名然后删除匹配文件-Z通常和-l结合使用。
``` ```
grep静默输出 grep静默输出