sablon
sablon copied to clipboard
Issue with inserting a Hyperlink via HTML content.
I've been trying to insert a dynamic hyperlink via a mailmerge field but am running into issues.
The context json looks like
{
"html:test_link": "<a href=\"https://google.com\">Click me</a>"
}
And the template docx is pretty simple with only the following
but when I run the sample command line executable
cat test.json | ./exe/sablon Test_Template.docx Out.docx
I get the following output.
I'm really not sure where the trailing \h comes from or how to make this work. I've dug through the code and added some debug and I see the Nokogiri element being parsed correctly and I see the WordML struct coming back as
#<struct Sablon::Content::WordML xml=#<Nokogiri::XML::DocumentFragment:0x3fc43ad909ac name="#document-fragment" children=[#<Nokogiri::XML::Element:0x3fc43ad905c4 name="w:hyperlink" attributes=[#<Nokogiri::XML::Attr:0x3fc43ad902a4 name="r:id" value="rId18">]>]>>
I'm not sure if I'm doing something incorrectly or if this is a bug.
@sangpark we test hyperlink insertion using this HTML block, https://github.com/senny/sablon/blob/master/test/fixtures/html/html_test_content.html and yours looks fine. Unfortunately I don't have easy access to MS Word to test things anymore. Can you try wrapping the link in a <div></div>
tag? If you want you can attach your word doc template to the issue and I'll try it out.
Thanks @stadelmanma . I tried wrapping my anchor link in a <div></div>
and also <p></p>
but I get similar results. I've attached the template file below.
For other information, I'm running using version 0.3.1 of the Sablon gem, on Ruby 2.6.5 and Word version 16.49 on a Mac.