-
-
Save wastemobile/cfd10d0a943f1900ca7d to your computer and use it in GitHub Desktop.
Generate FoldingText TOC with Applescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "FoldingText" | |
tell front document | |
evaluate script "function(editor, options) { | |
var tree = editor.tree(), | |
headings = tree.evaluateNodePath('//heading'), | |
toc = []; | |
headings.forEach(function(each) { | |
var level = each.typeIndentLevel(), | |
text = '- ' + each.text(); | |
while (level > 1) { | |
text = ' ' + text; | |
level--; | |
} | |
toc.push(text); | |
}); | |
toc = toc.join('\\n'); | |
require('ft/system/pasteboard').Pasteboard.writeString(toc); | |
return toc; | |
}" with options {} | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment