【问题标题】:How to delete everything outside of paragraph tags in Sublime Text如何在 Sublime Text 中删除段落标签之外的所有内容
【发布时间】:2014-01-27 01:38:05
【问题描述】:

这可能看起来很奇怪,因为它是为了将文字自动上传到在线内容系统,但这里是:

我写了一个故事或任何东西以在 Sublime Text 中上传。我通过 Sublime Text 文件创建了一个 Word 2010 .htm 文件(导出到纯文本文件,Word 中的命令行批处理,在 Sublime 中重新打开新生成的 .htm)。 export.htm 文件是一个完整的 html 页面,而我只需要使用 <p> 标签的正文条目。例如来自这个 export.htm:

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 14 (filtered)">
<style>
<!--
 /* Font Definitions */
 @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
    {font-family:"Trebuchet MS";
    panose-1:2 11 6 3 2 2 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin-top:0in;
    margin-right:0in;
    margin-bottom:10.0pt;
    margin-left:0in;
    line-height:115%;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";}
.MsoChpDefault
    {font-family:"Calibri","sans-serif";}
.MsoPapDefault
    {margin-bottom:10.0pt;
    line-height:115%;}
@page WordSection1
    {size:8.5in 11.0in;
    margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
    {page:WordSection1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=WordSection1>

<p class=MsoNormal style='margin-top:12.0pt;text-indent:.5in'><font size=2
face="Trebuchet MS"><span style='font-size:11.0pt;line-height:115%;font-family:
"Trebuchet MS","sans-serif"'>This is a paragraph of story text to be uploaded
to the online parsing system.</span></font></p>

<p class=MsoNormal style='margin-top:12.0pt;text-indent:.5in'><font size=2
face="Trebuchet MS"><span style='font-size:11.0pt;line-height:115%;font-family:
"Trebuchet MS","sans-serif"'>This is a another paragraph of story text to be
uploaded to the online parsing system.</span></font></p>

</div>

</body>

</html>

我想保留的唯一部分如下:

<p class=MsoNormal style='margin-top:12.0pt;text-indent:.5in'><font size=2
face="Trebuchet MS"><span style='font-size:11.0pt;line-height:115%;font-family:
"Trebuchet MS","sans-serif"'>This is a paragraph of story text to be uploaded
to the online parsing system.</span></font></p>

<p class=MsoNormal style='margin-top:12.0pt;text-indent:.5in'><font size=2
face="Trebuchet MS"><span style='font-size:11.0pt;line-height:115%;font-family:
"Trebuchet MS","sans-serif"'>This is a another paragraph of story text to be
uploaded to the online parsing system.</span></font></p>

一旦我有了文件的这个特定部分,我就可以再执行一项自动化操作(加入行),并且文件已准备好发送到在线解析器。

解析器需要某种 html 文本格式,但只接受页面正文的内容(页面的其余部分通过提交系统自动执行。)这需要从文字处理器导出 html,但众所周知处理器吐出最大宽度的 html。解析器看到文件中的换行符(html 会忽略换行符)并添加
标签,所以这就是为什么我需要运行我的 sublime 脚本来连接导出文件中的行。但要做到这一点,我需要清理导出,以便只存在所需的行(内容段落),否则一般 html 将被编织到上传到解析器的单行中。

我意识到这里最好的解决方案可能是更改解析器,使其忽略文件中未使用的垃圾,但它由不妥协的第三方控制(这是一个创意故事托管网站)。无论如何,这是偏离目标的。我可以自己处理,只需要从文件中清除非段落部分即可。

我已经找到了手动选择单个标签然后抓取其全部内容的方法,但是抓取所有一种类型或抓取相反的类型(按照此处的要求,除了所需的标签之外的所有标签)是我无法企及的。我已经在 stackoverflow 上搜索了谷歌的高低以及这里,结果都干了。

感谢任何帮助,伙计们。

【问题讨论】:

  • 如果您所做的只是在 HTML 标记中包装一些文本,为什么不创建一个程序来做到这一点?
  • 既然您已经有了获取单个标签及其内容的方法,您是否尝试过在利用 ST 中的多个光标时执行相同的操作?
  • 天哪,Word还在使用&lt;font&gt;标签?
  • 遗憾的是,Word 仍然会输出一些非常糟糕的 HTML。但是,无论出于何种原因,我将内容上传到的网站都需要任何字体样式、凹进缩进或基本块格式。此外,我目前没有选择我需要的标签的方法。那是我的问题。我需要隔离和删除第一个“

    ”标签之前的文本和最后一个“

    ”标签之后的文本。然而,多个光标可能能够选择所有单独的段落部分并将它们连接起来。如果可能的话,我会尝试一下,也许然后转储到一个新文件。

标签: html sublimetext2


【解决方案1】:

按住“shift”键并按“箭头”键选择要删除的文本。然后按“退格”键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    相关资源
    最近更新 更多