Using Flare API to modify document structure

This forum is for all Flare issues not related to any of the other categories.
Post Reply
phmonk
Jr. Propeller Head
Posts: 5
Joined: Sat Feb 08, 2014 11:18 am

Using Flare API to modify document structure

Post 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
Thomas Tregner
Propeller Head
Posts: 56
Joined: Mon Apr 05, 2010 6:51 pm
Location: Charleston
Contact:

Re: Using Flare API to modify document structure

Post 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
phmonk
Jr. Propeller Head
Posts: 5
Joined: Sat Feb 08, 2014 11:18 am

Re: Using Flare API to modify document structure

Post 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
Thomas Tregner
Propeller Head
Posts: 56
Joined: Mon Apr 05, 2010 6:51 pm
Location: Charleston
Contact:

Re: Using Flare API to modify document structure

Post 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
phmonk
Jr. Propeller Head
Posts: 5
Joined: Sat Feb 08, 2014 11:18 am

Re: Using Flare API to modify document structure

Post 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
Post Reply