Page 1 of 1

insertFragment in AuthorMode is pretty

Posted: Fri Sep 23, 2016 9:43 pm
by andygraham
Hi

I have a plugin which constructs a string containing XML with everything on one line. I insert it into a document using the following method:

AuthorDocumentFragment fragment = documentController.createNewDocumentFragmentInContext( xmlString, selection);
documentController.insertFragment(selection, fragment);

In Author mode everything looks fine but when I switch to text mode the inserted fragment is pretty printed while the rest of the document is not. I would like the fragment to appear in the document the way I created it in the string - all on the same line.

Any ideas?

Thanks
Andy

Re: insertFragment in AuthorMode is pretty

Posted: Tue Sep 27, 2016 9:22 am
by alex_jitianu
Hi Andy,

When the Author page serializes its content, it automatically applies some pretty print rules. These rules can be controlled from the Author Preferences page. Once you arrive on this page, focus on the Compatibility with other tools section. if you select Do not break lines, do not indent, the entire document will be on one line. If this is more than you desire, then you can try going on the Format Preferences page and add a few elements in the Preserve space list. The contents of these elements are not formatted and will be serialized on one line.

Best regards,
Alex

Re: insertFragment in AuthorMode is pretty

Posted: Thu Feb 01, 2018 5:15 pm
by andygraham
Hi Alex

Thanks a lot for your reply, that was really helpful.

Apologies for the delay in responding, initially we found another workaround with our own content but we have now been forced to adopt the solution you suggested. We are now programatically setting the compatibility option in our plugin, as follows:

Code: Select all

standalonePluginWorkspace.setGlobalObjectProperty("author.format.compatibility", 1);
My concern with this is that if the number of options for this property change, or the order of the properties in the drop down change, then setting this property to 1 will fail silently. Are there any plans to extend programmatic property setting to make it statically typed?

-Andy

Re: insertFragment in AuthorMode is pretty

Posted: Fri Feb 02, 2018 3:23 pm
by alex_jitianu
Hi Andy,

We have published this option in the API so, now, there is a constant that you can use: ro.sync.exml.options.APIAccessibleOptionTags.AUTHOR_FORMAT_COMPATIBILITY. Set the value to ro.sync.ecss.dom.builder.AuthorFormatCompatibilityModeConstants.FORMAT_COMPATIBILITY_DO_NOT_BREAK_LINES_DO_NO_INDENT.

Best regards,
Alex