Skip to content

Commit 4f3c1f3

Browse files
committed
修复 grep 页面排版问题 jaywcjlove#80
1 parent 36bec7c commit 4f3c1f3

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

build/build.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ renderer.heading = (text, level) => {
2020

2121
marked.setOptions({
2222
renderer: renderer,
23+
pedantic: false,
2324
gfm: true,
2425
tables: true,
2526
breaks: false,
26-
pedantic: false,
2727
sanitize: false,
2828
smartLists: true,
2929
smartypants: false,
30+
xhtml: false,
3031
highlight: (code, lang, callback) => {
3132
if (/(tex)$/.test(lang)) lang = 'latex';
3233
if (/(h)$/.test(lang)) lang = 'c';
@@ -48,6 +49,10 @@ marked.setOptions({
4849
if (Prism.languages[lang]) {
4950
html = Prism.highlight(code, Prism.languages[lang], lang);
5051
}
52+
if (lang === 'markdown') {
53+
html.toString();
54+
html = html.replace(/\$/g, '$')
55+
}
5156
return callback('', html);
5257
}
5358
});

command/grep.md

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ grep
4444

4545
```bash
4646
^ # 锚定行的开始 如:'^grep'匹配所有以grep开头的行。
47-
$ # 锚定行的结束 如:'grep$'匹配所有以grep结尾的行。
47+
$ # 锚定行的结束 如:'grep$' 匹配所有以grep结尾的行。
4848
. # 匹配一个非换行符的字符 如:'gr.p'匹配gr后接一个任意字符,然后是p。
4949
* # 匹配零个或多个先前字符 如:'*grep'匹配所有一个或多个空格后紧跟grep的行。
5050
.* # 一起用代表任意字符。
@@ -65,110 +65,97 @@ x\{m,n\} # 重复字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配
6565

6666
在文件中搜索一个单词,命令会返回一个包含 **“match_pattern”** 的文本行:
6767

68-
```
68+
```bash
6969
grep match_pattern file_name
7070
grep "match_pattern" file_name
71-
7271
```
7372

7473
在多个文件中查找:
7574

76-
```
75+
```bash
7776
grep "match_pattern" file_1 file_2 file_3 ...
78-
7977
```
8078

8179
输出除之外的所有行 **-v** 选项:
8280

83-
```
81+
```bash
8482
grep -v "match_pattern" file_name
85-
8683
```
8784

8885
标记匹配颜色 **--color=auto** 选项:
8986

90-
```
87+
```bash
9188
grep "match_pattern" file_name --color=auto
92-
9389
```
9490

9591
使用正则表达式 **-E** 选项:
9692

97-
```
93+
```bash
9894
grep -E "[1-9]+"
99-
95+
#
10096
egrep "[1-9]+"
101-
10297
```
10398

10499
只输出文件中匹配到的部分 **-o** 选项:
105100

106-
```
101+
```bash
107102
echo this is a test line. | grep -o -E "[a-z]+\."
108103
line.
109104

110105
echo this is a test line. | egrep -o "[a-z]+\."
111106
line.
112-
113107
```
114108

115109
统计文件或者文本中包含匹配字符串的行数 **-c** 选项:
116110

117-
```
111+
```bash
118112
grep -c "text" file_name
119-
120113
```
121114

122115
输出包含匹配字符串的行数 **-n** 选项:
123116

124-
```
117+
```bash
125118
grep "text" -n file_name
126-
119+
#
127120
cat file_name | grep "text" -n
128121

129122
#多个文件
130123
grep "text" -n file_1 file_2
131-
132124
```
133125

134126
打印样式匹配所位于的字符或字节偏移:
135127

136-
```
128+
```bash
137129
echo gun is not unix | grep -b -o "not"
138130
7:not
139-
140131
#一行中字符串的字符便宜是从该行的第一个字符开始计算,起始值为0。选项 **-b -o** 一般总是配合使用。
141-
142132
```
143133

144134
搜索多个文件并查找匹配文本在哪些文件中:
145135

146-
```
136+
```bash
147137
grep -l "text" file1 file2 file3...
148-
149138
```
150139

151140
### grep递归搜索文件
152141

153142
在多级目录中对文本进行递归搜索:
154143

155-
```
144+
```bash
156145
grep "text" . -r -n
157146
# .表示当前目录。
158-
159147
```
160148

161149
忽略匹配样式中的字符大小写:
162150

163-
```
151+
```bash
164152
echo "hello world" | grep -i "HELLO"
165-
hello
166-
153+
# hello
167154
```
168155

169156
选项 **-e** 制动多个匹配样式:
170157

171-
```
158+
```bash
172159
echo this is a text line | grep -e "is" -e "line" -o
173160
is
174161
line
@@ -179,19 +166,18 @@ aaa
179166
bbb
180167

181168
echo aaa bbb ccc ddd eee | grep -f patfile -o
182-
183169
```
184170

185171
在grep搜索结果中包括或者排除指定文件:
186172

187-
```
188-
#只在目录中所有的.php和.html文件中递归搜索字符"main()"
173+
```bash
174+
# 只在目录中所有的.php和.html文件中递归搜索字符"main()"
189175
grep "main()" . -r --include *.{php,html}
190176

191-
#在搜索结果中排除所有README文件
177+
# 在搜索结果中排除所有README文件
192178
grep "main()" . -r --exclude "README"
193179

194-
#在搜索结果中排除filelist文件列表里的文件
180+
# 在搜索结果中排除filelist文件列表里的文件
195181
grep "main()" . -r --exclude-from filelist
196182

197183
```
@@ -206,8 +192,7 @@ echo "aaa" > file3
206192

207193
grep "aaa" file* -lZ | xargs -0 rm
208194

209-
#执行后会删除file1和file3,grep输出用-Z选项来指定以0值字节作为终结符文件名(\0),xargs -0 读取输入并用0值字节终结符分隔文件名,然后删除匹配文件,-Z通常和-l结合使用。
210-
195+
# 执行后会删除file1和file3,grep输出用-Z选项来指定以0值字节作为终结符文件名(\0),xargs -0 读取输入并用0值字节终结符分隔文件名,然后删除匹配文件,-Z通常和-l结合使用。
211196
```
212197

213198
grep静默输出:

0 commit comments

Comments
 (0)