2015-10-05 79 views
-1

我有一个看起来一个SGML文件有很多<p>段落已经暗示结束标记,像这样的:如何添加SGML结束标签?

<p>Here is one paragraph. 
<p>And here is another. This one contains <i>italics</i>. 
<p>Finally, here is another paragraph. 

上有这些段落没有结束标记。我想使它看起来像这样:

<p>Here is one paragraph.</p> 
<p>And here is another. This one contains <i>italics</i>.</p> 
<p>Finally, here is another paragraph.</p> 

有没有一种简单的方法来做到这一点使用OSS工具? (像vim,sed等?)

+0

什么都不做,它会看起来一样 – tinySandy

+0

良好的捕获。复制粘贴错误。固定。 – Jono

回答

1

在vim中,考虑到您指定的输入,您可以使用:%s/$/<\/p>/。 请注意,这仅适用于您的示例,其中每个段落都是一行。

如果是多行段落,首先加入所有行:%j,然后在开始标记:%s/ \+<p>/<\/p><p>/前添加一个结束标记,然后添加最终结束标记:%s/$/<\/p>/。最后用gqap重排文本。

0

%s/<p>\zs\(.*\)/\1<\/p>/应该在Vim中工作,但“经典”解决方案是%s/<p>/<\/p><p>/,然后将第一个</p>移动到文本的末尾。