Inline Markdown footnotes
Posted: 2018-01-31 15:14:29
I use Martin’s simple Markdown script to convert Markdown to a Nisus document; I recently ran into the need to also convert inline footnotes, and added the following code:
It works, but I’m wondering if it couldn’t be better, especially the insertFootnoteInTextAtIndex line and the removing of the Normal style from the footnotes after adding.
That is,
Code: Select all
Macro.run "Markdown Preview"
$document = Document.active
#Convert Inline Footnotes
While Find Next '\[\^[^\]]+\]', "E"
$noteText = TextSelection.activeSubtext
$noteRange = TextSelection.activeRange
$noteLocation = $noteRange.location
Edit:Delete
$noteText.deleteInRange Range.new 0, 2
$noteText.deleteInRange Range.new $noteText.length-1, 1
$newNote = Note.insertFootnoteInTextAtIndex $document.text, $noteLocation, $noteText
End
$document.setSelection $newNote.fullText
Format:Paragraph Style:Remove Paragraph Styles
That is,
- should I be using $document.text as the destination for the footnote?
- it seems like it would be better to be able to remove the paragraph styles (while retaining any other attributes) from the potential footnote text directly instead of removing it from all footnotes regardless of whether they were created using this macro. Something like “$noteText.removeParagraphStyles”, but I couldn’t see anything that does that in the Macro Reference. Am I missing something else that would perform the same task?