我有一个结构如下的 HTML 文档:
<li class="indent1">(something)
<li class="indent2">(something else)</li>
<li class="indent2">(something else)
<li class="indent3">(another sublevel)</li>
</li>
<li class="indent2">(something else)</li>
</li>
我需要做的是将这些 LI 标签包装在 OL 标签中。整个文档中有许多这样的列表。HTML 需要如下所示:
<ol>
<li>(something)
<ol>
<li>(something else)</li>
<li>(something else)
<ol>
<li>(another sublevel)</li>
</ol>
</li>
<li>(something else)</li>
</ol>
</li>
</ol>
我怎么能在 Nokogiri 做这个?提前谢谢了。
编辑:
这是原始文档中的 HTML 示例。我的脚本将所有 P 标签转换为 LI 标签。
<p class="indent1"><i>a.</i> This regulation describes the Army Planning, Programming,
Budgeting, and Execution System (PPBES). It explains how an integrated Secretariat and
Army Staff, with the full participation of major Army commands (MACOMs), Program
Executive Offices (PEOs), and other operating agencies--</p>
<p class="indent2">(1) Plan, program, budget, and then allocate and manage approved
resources.</p>
<p class="indent2">(2) Provide the commanders in chief (CINCs) of United States unified
and specified commands with the best mix of Army forces, equipment, and support
attainable within available resources.</p>
<p class="indent1"><i>b.</i> The regulation assigns responsibilities and describes
policy and procedures for using the PPBES to:</p>
缩进 1 类表示一级列表项,缩进 2 表示二级等。我需要将这些缩进类转换为正确的有序列表。