Code: Select all
put the htmltext of fld "text" into tText
put offset("{", tText) into tLeftBracePos
put char 1 to tLeftBracePos-2 of tText into tText1
Code: Select all
put tText1 & " FN " & tText2 into tNewNext
Monty May
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Code: Select all
put the htmltext of fld "text" into tText
put offset("{", tText) into tLeftBracePos
put char 1 to tLeftBracePos-2 of tText into tText1
Code: Select all
put tText1 & " FN " & tText2 into tNewNext
Code: Select all
put char 1 to tLeftBracePos-1 of tText into tText1
Code: Select all
put textEncode(fld "out","UTF-8") into url ("file:" & /path/to/fileout.txt)
Code: Select all
## Assumption: the user has entered some text and marked footnote into field "text" by enclosing it with braces. This script will update the file so that the text appears with a footnote reference
## and the citation appears in a separate text file listing all the footnotes.
on mouseup
put empty into tNewText
local tText, tSkip = "0", tCount = "1", tFNCount = "1", tStart, tEnd
put the cTitle of me into tTitle
put "c:/Users/"&gComputer&"/Documents/DB/articles/" into tFolder
## (1) get the newly edited text that will be update the article
put the htmltext of fld "text" into tText
put tText into fld "text1"
## (2) get text after the new entry and its marked citation & put it into tText2
put offset("}", tText) into tRightBracePos
put char tRightBracePos+1 to -1 of tText into tText2
put tText2 into fld "text2"
## (3) get just the old text plus the user's entry in the body, but not the citation, and put it into tText1
put the htmltext of fld "text" into tText
put offset("{", tText) into tLeftBracePos
put char 1 to tLeftBracePos-2 of tText into tText1
put tText1 into fld "text1"
## (3) get the footnote and put it into tCitation and delete it the marked citation from tFile1
put char (tLeftBracePos+1) to (tRightBracePos-1) of tText into tCitation
put tCitation into fld "text3"
## (4) Put it all together
put tText1 & " FN " & tText2 into tNewText
put tNewText into fld "text1"
## (5) get the number of footnote references in the body
put FNnum("FN", tNewText) into tFNnum
## (6) Format the new unformatted footnote reference in the variable tNewText while updating the footnote
## reference numbers
set the caseSensitive to "true"
repeat tFNnum
get WordOffset("FN", tNewText, tSkip) --word
add it to tSkip -- put word number of FN
if "</sup>" is not in word tSkip of tNewText then --format & update one-word FN
put "<a><sup shift=""e&"-12""e&">FN"&tCount& "</sup></a>" into word tSkip of tNewText
put tCount & ") " & tCitation into tCitation
add 1 to tSkip --now three words
else put "<a><sup shift=" "e&"-12""e& ">FN"&tCount& "</sup></a>" into word (tSkip-1) to tSkip of tNewText --update three-word FN
add 1 to tCount
end repeat
## (7) Update the body of the text file and display it in the field "text"
open file tFolder&tTitle&".txt" for write
write tNewText to file tFolder&tTitle&".txt" at 0
close file tFolder&tTitle&".txt"
set the HTMLtext of fld "text" to it
##(8) Update the footnote file
[script omitted]
## (9) Diplay updated file in fld "text"
[script omiited]
end mouseup
function FNnum pSearch, pCont
put 0 into rFNnum
put 0 into tCharsToSkip
repeat
put offset(pSearch, pCont, tCharsToSkip) into tHit
if tHit = 0 then exit repeat
add tHit to tCharsToSkip
add 1 to rFNnum
end repeat
return rFNnum
end FNnum
Code: Select all
open file tFolder&tTitle&".txt" for write
write tNewText to file tFolder&tTitle&".txt" at 0
close file tFolder&tTitle&".txt"
set the HTMLtext of fld "text" to it
Code: Select all
put URL "file:..." into myVar
Code: Select all
put myVar into URL "file:..."
Code: Select all
replace "{" with ("<a><sup shift=""e&"-12""e&">FN§") in tText
replace "}" with "</sup></a>" in tText
put 0 into tCount
repeat for each char tChar in tText
if tChar = "§" then
add 1 to tCount
put tCount after tText2
else
put tChar after tText2
end if
end repeat
Code: Select all
put URL "file:"&tFolder&tTitle&".txt" into fld "text"
Code: Select all
put URL ("file:"&tFolderPath&tTitle&".txt") into fld "text"
Hi Monty,
Code: Select all
function buildFootNotes Txt
local Notes, fnCounter, fnText
local fnLinkTemplate = "<sup><a href=#FN[[fnCounter]]>FN[[fnCounter]]</a></sup> "
local fnTextTemplate = "<a name=FN[[fnCounter]]><b>FN[[fnCounter]]</b>: [[fnText]]</a><br>"
put "<br /><br />_____ notes: _____<br />" into Notes
repeat while matchChunk( Txt, "(?x) ( { \s* (.*?) \s* } )", p1, p2, p3, p4)
add 1 to fnCounter
put char p3 to p4 of Txt into fnText
put merge( fnLinkTemplate) into char p1 to p2 of Txt
put merge( fnTextTemplate) after Notes
end repeat
return Txt & Notes
end buildFootNotes
Code: Select all
on mouseUp
local myHtmlFile = "file:/Users/xxxx/testBuildFootnotes.html"
put the htmlText of field "fInput" into tText
set the text of field "fResult" to buildFootNotes( tText)
put the text of field "fResult" into URL myHtmlFile
launch URL myHtmlFile
end mouseUp