0
我試圖在h3
標記後添加一行文本。如何使用Nokogiri在div後添加文本
我的出發HTML是這樣的:
<h3>hi</h3>
與任何其他標記,或文檔類型。我希望我的結局HTML看起來像這樣:
<h3>hi</h3>
{% include 'tester-credit-button' %}
我試過如下:
page = Nokogiri::HTML::DocumentFragment.parse("my_page.html")
title = page.at_css("h3")
#tried this first
title.children.after("\n{% include 'tester-credit-button' %}")
#then this
title << "\n{% include 'tester-credit-button' %}"
#then this
title.after("\n{% include 'tester-credit-button' %}")
#then this
text_node = Nokogiri::XML::Text.new("\n{% include 'tester-credit-button' %}"
, page)
title.add_child(text_node)
與我的HTML,節點或節點集的結構無關。非常感謝你的建議。 – ToddT