You're right. The set of commands for manipulating formatting, styles and attributes is a bit 'hit and miss'.
One command that will work for pushed targets is Style.apply
. So if you have a desired style as an object you can apply it to your target text. But removing won't be possible with that method.
When all else fails, you can put the text bit in a new document, or on a clipboard and format it there, then collect the result and dismiss the document/clipboard. This is a method that Nisus Classic users will fondly recall as the "light show"
(NWP is fast enough that you might not even see anything.)
But for these and others reasons, I would generally avoid formatting bit by bit. A better approach is to put the bits into the document, then select just the desired bits, and apply the formatting in the document. This is what you were trying to do at first, but rather than selecting the .fullText
you'll have to accumulate the individual note selections in an array. For this to work correctly you will have to carefully consider how you are inserting things into the document. Your current macro works front to back, so something like this should work (no guarantees, I just wrote this here.):
Code: Select all
#Convert Inline Footnotes
$newNotes = Array.new
While Find Next '\[\^[^\]]+\]', "E"
$noteText = TextSelection.activeSubtext
$noteRange = TextSelection.activeRange
$noteLocation = $noteRange.location
$noteText.deleteInRange Range.new 0, 2
$noteText.deleteInRange Range.new $noteText.length-1, 1
$newNote = Note.insertFootnoteInTextAtIndex $document.text, $noteLocation, $noteText
$newNotes.push TextSelection.new($newNote.fullText, $newNote.fullTextRange)
Format:Paragraph Style:Remove Paragraph Styles
If you are generally working with small amounts of text (< a dozen notes), then your method will probably be ok. But usually I would opt for a method that works "in batch". First find all
the notes, then process the find results in a loop, then apply the formatting. In the case of notes this can be tricky however, since removing and inserting will change your document, so if you want to keep track of them to select them again later, you have to operate carefully. This problem has been dealt with a number of times. I'd look for macros by Kino, either in the macro repository, on this forum.