If the target is MarkDown, this slightly fuller version also tries to capture any *italic* or **bold** sequences in the topics/notes and represent them with Markdown asterisk emphases:
Code:
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
-- OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- IF YOU *REALLY* WANT TO DELETE THE CHILD NOTES AFTER CAPTURING THEIR TEXT
-- CHANGE THE VALUE OF THIS PROPERTY TO TRUE …
-- BUT *ONLY* EXPERIMENT WITH DISPOSABLE COPIES OF MULTIPLY BACKED UP WORK ...
property pVer : "002"
property pblnReallyDeleteDescendants : false
tell application id "OOut"
set lstDocs to documents
if length of lstDocs < 1 then return
tell first item of lstDocs
set lstSeln to selected rows
if length of lstSeln < 1 then return
tell first item of lstSeln
if has subtopics then
set its note to my MDEmphasis({text, font} of attribute runs of its note) & return & ¬
return & my GetSubText(its children)
end if
set its note expanded to true
end tell
end tell
end tell
on GetSubText(lstChiln)
tell application id "OOut"
set str to ""
-- CAPTURE THE TEXT
repeat with oChild in lstChiln
tell oChild
set str to str & my MDEmphasis({text, font} of attribute runs of its topic) & ¬
return & return & my MDEmphasis({text, font} of attribute runs of its note) & return & return
if has subtopics of it then set str to str & my GetSubText(its children)
end tell
end repeat
-- AND THEN DELETE THE CHILDREN ?
if pblnReallyDeleteDescendants then
repeat with i from length of lstChiln to 1 by -1
delete item i of lstChiln
end repeat
end if
return str
end tell
end GetSubText
on MDEmphasis({lstText, lstFont})
set str to ""
repeat with i from 1 to length of lstText
set strText to item i of lstText
if strText ≠ "" then
set strFont to item i of lstFont
if strFont contains "BoldOblique" or strFont contains "BoldItalic" then
set str to str & my emphasize(strText, "***")
else if strFont contains "bold" then
set str to str & my emphasize(strText, "**")
else if strFont contains "oblique" or strFont contains "italic" then
set str to str & my emphasize(strText, "*")
else
set str to str & strText
end if
end if
end repeat
return str
end MDEmphasis
-- wrap the trimmed part of the string with MD emphasis markers
-- and restore the end spaces
on emphasize(strText, strMarker)
set {dlm, my text item delimiters} to {my text item delimiters, space}
set lstParts to text items of strText
set lngParts to length of lstParts
-- The opening marker
repeat with i from 1 to lngParts
set strPart to item i of lstParts
if strPart ≠ "" then
set item i of lstParts to strMarker & strPart
exit repeat
end if
end repeat
-- and the closing marker
repeat with i from lngParts to 1 by -1
set strPart to item i of lstParts
if strPart ≠ "" then
set item i of lstParts to strPart & strMarker
exit repeat
end if
end repeat
set str to lstParts as string
set my text item delimiters to dlm
return str
end emphasize