Page 1 of 1
Using Flare API to modify document structure
Posted: Sat Feb 08, 2014 3:51 pm
by phmonk
Hi all,
Does the Flare API support modifying the document structure?
I'm playing around with the Flare API and I've created a simple plugin that I can launch from inside Flare. (Following information in the Flare API documentation:
http://downloads.madcapsoftware.com/fla ... oc0900.zip).
I found that I can easily insert text into the active document (using
Code: Select all
IHost.GetEditorContext().GetActiveDocument().Selection.ReplaceText()
) , but I don't see any way to modify the actual structure (the HTML) of the document using the Flare API; HTML passed to ReplaceText() is automatically escaped.
Cheers,
Paul
Re: Using Flare API to modify document structure
Posted: Mon Feb 10, 2014 6:55 am
by Thomas Tregner
Hello Paul,
There are a couple of posts on my blog about Flare plug-ins.
A First Flare Plug-in
Create Topics in Bulk with a Plug-in
There aren't methods to manipulate topic DOMs in the current API. But what you can do is recreate the topic in your plug-in and overwrite it. For example you can load the topic XML into a Linq to XML XDocument, change things around, and save the XDocument as the topic from within the plug-in. Source control can add another level of complexity since just loading the document into an object using the plug-in would not prompt a check-out in the way an edit using the Topic Editors does.
Tom
Re: Using Flare API to modify document structure
Posted: Mon Feb 10, 2014 10:14 pm
by phmonk
Hi Tom,
Thanks for the advice. I was hoping to avoid doing what you're suggesting. Altering documents outside of Flare, behind the user's back, feels devious. Furthermore, when a file open in Flare is modified on disk, the user is prompted to either load the altered file, losing any changes made since last save, or continue working on their copy, which will likely lead to them saving over the alterations made outside Flare. Looks like my idea is a nonstarter.
I wonder if DOM manipulation is on the product roadmap. APIs don't usually get a lot of love and DOM manipulation isn't trivial. Ah well...
Cheers,
Paul
Re: Using Flare API to modify document structure
Posted: Fri Mar 07, 2014 11:19 am
by Thomas Tregner
Check out the documentation for the update to the plug-in API for version 10. It probably has what you need now.
http://downloads.madcapsoftware.com/fla ... oc0100.zip
Re: Using Flare API to modify document structure
Posted: Fri Mar 07, 2014 1:48 pm
by phmonk
Indeed! IDocument now has:
* void Select(XmlNode)
* XmlDocument GetXmlDocument()
* void InsertDocumentNode(XmlNode, XmlNode, int, bool)
* void RemoveDocumentNode(XmlNode, bool)
* void ReplaceDocumentNode(XmlNode, XmlNode, bool)
* bool Save()
* void Select(XmlNode)
That should cover all the bases, I think.
Thanks!
Paul