I’m trying to format an academic article that was typed in plain text and convert the author’s custom markup to actual rich text in Word 2008. Here’s an example of the author’s markup system:
Doing the bold and italic replacements is easy. I’m running into problems with the footnotes.
Here’s what I have so far:
tell application "Microsoft Word"
set selFind to find object of selection
set forward of selFind to true
set wrap of selFind to find stop
set match wildcards of selFind to true
set content of selFind to "\\\\footnote\\{(*)\\}"
set content of replacement of selFind to "\\1"
execute find selFind replace replace all
end tell
It can successfully search the document using Word’s wildcard syntax and find all instances of \footnote{whatever} and as it stands it can replace the selected find with the first found group, or \1, Word’s syntax for the regex standard $1
That gets rid of the footnote syntax junk, but leaves the author’s reference in the text. I obviously need it to go in as a footnote.
Instead of finding and replacing the text, I’ve tried just cutting the whole selection out, inserting a footnote, and pasting the text, but I’ve run into problems with cut object and cut text range. Additionally, I’d have to run the find and replace again to get rid of the surrounding \footnote{} syntax in the footnotes. I’ve found that this partially works; it gets the text and saves it as a variable and adds a footnote, but doesn’t get rid of any text.
...
execute find selFind
set strText to content of text object of selection
collapse range text object of selection direction collapse end
set myFootnote to make new footnote at active document with properties {text range:text object of selection}
set content of text object of myFootnote to strText
Optimally, here’s what I’m trying to do, in pseudo code
Any ideas on how to get this all to work?
Thanks!