You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need some help.
I have a string markup which contains my content and Here's my problem:
let markup = "Lorem ipsum dolor sit <strong>amet, consectetur adipiscing elit</strong>. Proin varius dictum magna sit amet dignissim. Donec vitae turpis commodo, interdum turpis vitae, tempus tellus. Nam dictum nunc erat, ac consectetur urna convallis in. Vivamus dignissim sapien nulla, ut elementum <em>massa venenatis sit amet</em>. Nunc lobortis lectus ut metus faucibus convallis. Curabitur nec ante ac magna vulputate bibendum quis a ex. Cras condimentum tempor elementum."
As you can see the string contains html entities such as <strong/> and <em/>, and PDFKIT uses doc.font('bold-font').text(); (http://pdfkit.org/docs/text.html#fonts) in order to insert bold text;
How can I possibly convert all the tags to functions?
The text was updated successfully, but these errors were encountered:
Use a package that can parse html (JSDOM or similar)
Assuming your markup is as simple as above (basically flat), you can then just iterate over the parsed nodes and check the nodetype for each node. If it's a text node, just call doc.text( currentNode.nodeValue ), if it's an element type node, check if it's a strong or em and call with the font argument as needed. If the markup is more complex you'll have to figure out how to walk the parsed nodes appropriately.
That should at least give you an idea of how to get started
I need some help.
I have a string markup which contains my content and Here's my problem:
let markup = "Lorem ipsum dolor sit <strong>amet, consectetur adipiscing elit</strong>. Proin varius dictum magna sit amet dignissim. Donec vitae turpis commodo, interdum turpis vitae, tempus tellus. Nam dictum nunc erat, ac consectetur urna convallis in. Vivamus dignissim sapien nulla, ut elementum <em>massa venenatis sit amet</em>. Nunc lobortis lectus ut metus faucibus convallis. Curabitur nec ante ac magna vulputate bibendum quis a ex. Cras condimentum tempor elementum."
As you can see the string contains html entities such as <strong/> and <em/>, and PDFKIT uses doc.font('bold-font').text(); (http://pdfkit.org/docs/text.html#fonts) in order to insert bold text;
How can I possibly convert all the tags to functions?
Hi,
I need some help.
I have a string
markup
which contains my content and Here's my problem:let markup = "Lorem ipsum dolor sit <strong>amet, consectetur adipiscing elit</strong>. Proin varius dictum magna sit amet dignissim. Donec vitae turpis commodo, interdum turpis vitae, tempus tellus. Nam dictum nunc erat, ac consectetur urna convallis in. Vivamus dignissim sapien nulla, ut elementum <em>massa venenatis sit amet</em>. Nunc lobortis lectus ut metus faucibus convallis. Curabitur nec ante ac magna vulputate bibendum quis a ex. Cras condimentum tempor elementum."
As you can see the string contains html entities such as
<strong/>
and<em/>
, and PDFKIT usesdoc.font('bold-font').text()
; (http://pdfkit.org/docs/text.html#fonts) in order to insert bold text;How can I possibly convert all the tags to functions?
The text was updated successfully, but these errors were encountered: