在sublime文本中使用不同的逻辑包裹带有标记的行2

时间:2016-06-10 08:21:20

标签: sublimetext

我有数百个要编码的列表项。每个列表项包含2行中的标题和描述。所以我需要做的是用标签包裹2行。有没有办法使用sublime text 2?我正在使用Windows操作系统。

这是所需的输出:

<ul>
    <li>
        this is the title
        this is the descrpition
    </li>
    <li>
        this is the title
        this is the descrpition
    </li>
</ul>

原始文本如下所示:

这是标题
这是描述
这是标题
这是描述

=====

我尝试过使用ctrl + shift + G并使用ul&gt; li *但不幸的是它用<li>

包裹了每一行

如果可以使用sublime文本,我实际上需要这种类型的结构:

<ul>
    <li>
        <span class="title">this is the title</span>
        <span class="description">this is the descrpition</span>
    </li>
    <li>
        <span class="title">this is the title</span>
        <span class="description">this is the descrpition</span>
    </li>
</ul>

1 个答案:

答案 0 :(得分:0)

使用查找和替换的两步过程怎么样?

我假设:

  • 您的原始文字根本没有缩进;
  • 你的缩进是两个空格;和
  • 完成此操作后,您将使用<ul>处理包裹并自行缩进。

原始状态:

    this is title
    this is description
    this is title
    this is description

第一步

确保已启用正则表达式匹配使用这些值执行查找和替换。

找到什么:: ((.*\n){1,2})

REPLACE WITH :: <li>\n\1</li>\n

结果:

    <li>
    this is title
    this is description
    </li>
    <li>
    this is title
    this is description
    </li>

第二步

确保已启用正则表达式匹配使用这些值执行查找和替换。

找到什么:: (<li>\n)(.*)\n(.*)

REPLACE WITH :: \1 <span class="title">\2</span>\n <span class="description">\3</span>

结果:

    <li>
      <span class="title">this is title</span>
      <span class="description">this is description</span>
    </li>
    <li>
      <span class="title">this is title</span>
      <span class="description">this is description</span>
    </li>

您怎么看?

足够接近有用吗?