Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

this is some text saved to the page


Document properties

<#assign dumy = doc.setTitle("this is the new title")>
<#assign dumy = doc.setDescription("this is the new description")>
<#assign dumy = doc.setFeedItemUrl("https://not-a-real-domain.com")>

Document custom properties

There are now 10 custom document properties that will hold strings of up to about 20,000 characters.  They are named – very imaginatively – custom1, custom2, …, custom10.  These properties are preserved through all workflows.  To access one of these values in a script do:

custom1 = ${doc.custom1}

To assign a value to one of these variables do:

<#assign dumy = doc.setCustom1("uno")>

Note a small detail:  The values you set on custom variables currently “take effect” at the end of script execution. so if you assign a value to one of these properties in a script and then access its value, you won’t get the updated value.  This is a (minor) bug scheduled for the next update.

jSoup

This oddly named package provides easy yet powerful ways to both query and edit HTML documents.  The entire package is exposed so go here for the full documentation.  Here is a simple example of it’s use.

<#assign dom = doc.soup>
<#assign p1 = dom.select("p").first()>
<#assign dumy = p1.attr("style","font-weight:bold")>
<#assign dumy = p1.append("<p>an inserted paragraph</p>")>
<#assign special = dom.select("p#specialp").html("this is the special text we inserted")>
${dom.html()}

The code above gets the jSoup structure into ‘dom’.  We then find the first paragraph, add some styling to it, and then add a new paragraph immediately following.  Finally, we find we replace the contents of the paragraph with id=specialp with the text shown.  The dom variable now contains the original document with content changed and added.  We probably want to keep those changes for use in later workflows, so the final line takes the dom and converts it back to html as the output of this script.





  • No labels