aspell 在管道模式下可以输出行号而不是偏移量吗?
aspell
可以在管道模式下为 html 和 xml 文件输出行号而不是偏移量吗?我无法逐行读取文件,因为在这种情况下 aspell
无法识别闭合标签(如果标签位于下一行)。
Can aspell
output line number and not offset in pipe mode for html and xml files? I can't read the file line by line because in this case aspell
can't identify closed tag (if tag situated on the next line).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这将输出所有出现的拼写错误单词以及行号:
其中:
aspell.ignore.txt 示例:
example results.txt 输出(对于 en_GB 字典):
您还可以通过更改最后一个 < 来打印整行将代码>grep -on 转换为
grep -n
。This will output all occurrences of misspelt words with line numbers:
Where:
aspell.ignore.txt example:
example results.txt output (for an en_GB dictionary):
You can also print the whole line by changing the last
grep -on
intogrep -n
.这只是一个想法,我还没有真正尝试过(我在 Windows 机器上:()。但也许你可以通过 head 管道传输 html 文件(有字节限制)并使用 grep 计算换行数来查找你的行它既不高效也不漂亮,但它可能会起作用。
This is just an idea, I haven't really tried it yet (I'm on a windows machine :(). But maybe you could pipe the html file through head (with byte limit) and count newlines using grep to find your line number. It's neither efficient nor pretty, but it might just work.
我使用以下脚本来执行拼写检查并解决
aspell -a
/ispell
的尴尬输出。同时,该脚本还解决了 aspell 无法识别像2nd
这样的序数的问题,方法是简单地忽略 aspell 报告的所有非其自身的单词。如果脚本的 stdout 是终端,您甚至会得到彩色输出,并且如果脚本发现拼写错误,您会得到退出状态
1
,否则退出状态为脚本是0
。此外,该脚本还可以保护自己免受
pipefail
的影响,这是一个比较流行的选项,即在Makefile
中设置的选项,但不适用于该脚本。最后但并非最不重要的一点是,此脚本显式使用[[:alpha:]]
而不是[a-zA-Z]
,当它也匹配非 ASCII 时,不会那么混乱德语äöüäÖÜß
等字符。[a-zA-Z]
也是如此,但在某种程度上这令人惊讶。I use the following script to perform spell-checking and to work-around the awkward output of
aspell -a
/ispell
. At the same time, the script also works around the problem that ordinals like2nd
aren't recognized by aspell by simply ignoring everything that aspell reports which is not a word of its own.You even get colored output if the
stdout
of the script is a terminal, and you get an exit status of1
in case the script found spelling mistakes, otherwise the exit status of the script is0
.Also, the script protects itself from
pipefail
, which is a somewhat popular option to be set i.e. in aMakefile
but doesn't work for this script. Last but not least, this script explicitly uses[[:alpha:]]
instead of[a-zA-Z]
which is less confusing when it's also matching non-ASCII characters like GermanäöüÄÖÜß
and others.[a-zA-Z]
also does, but that to some level comes at a surprise.aspell pipe
/aspell -a
/ispell
为每个输入行输出一个空行(报告该行的错误后)。使用 awk: 打印行号的演示会
产生以下输出:
with testFile.txt
(仍然不如
hunspell -u
(https://stackoverflow.com/a/10778071/4124767)。但是 hunspell 错过了一些我喜欢的命令行选项。)aspell pipe
/aspell -a
/ispell
output one empty line for each input line (after reporting the errors of the line).Demonstration printing the line number with awk:
produces this output:
with testFile.txt
(Still not as nice as
hunspell -u
(https://stackoverflow.com/a/10778071/4124767). But hunspell misses some command line options I like.)对于将
aspell
与其中一种过滤模式(tex
、html
等)一起使用的其他人,这里有一种仅打印拼写错误单词的行号的方法在过滤后的文本中。例如,它不会打印注释中的拼写错误。这是有效的,因为
aspell 过滤器
不会删除空行。我意识到这并没有按照OP的要求使用aspell管道
,但它与使aspell
打印行号的精神相同。For others using
aspell
with one of the filter modes (tex
,html
, etc), here's a way to only print line numbers for misspelled words in the filtered text. So for example, it won't print misspellings in the comments.This works because
aspell filter
does not delete empty lines. I realize this isn't usingaspell pipe
as requested by OP, but it's in the same spirit of makingaspell
print line numbers.