Use plugins to integrate directly with FoldingText's code and add new features.
Related:
- Nodes
- Debugging
- CodeMirror
- Classification
Extensions
About
FoldingText's editor is implemented in JavaScript/HTML/DOM.
Plugins allow you to load your own JavaScript code into FoldingText. Your plugin code runs right along side the core FoldingText code. JavaScript is a flexible language, and I've included all of FoldingText's JavaScript codebase for you to use as a reference (not open source) when writing your plugins.
Flexible language and source code access means you can hack deeply into FoldingText when needed. But if you do that be aware that the internals change from time to time, so things might break on an update. Not saying don't do it... just saying be aware.
I have documented the public APIs (listed on the right) and Extensions
that I think are stable and that I will try to maintain between releases. If you'll be releasing your plugin to the public please use only the public documented APIs. If you run into a case where something's not possible using only the public APIs let me know, and we'll try to find a solution.
Getting Started
-
Choose the menu item File > Open Application Folder
-
Make a new folder with the extension
.ftplugin
inside the "Plug-Ins" folder. -
Inside your plugin's folder create
main.js
andpackage.json
files:
main.js
define(function(require, exports, module) {
var Extensions = require('@foldingtext/extensions').Extensions;
Extensions.addInit(function (editor) {
editor.addKeyMap({
'Cmd-H' : function (editor) {
editor.replaceSelection('Hello world!');
}
});
});
});
package.json
{
"name": "Hello world",
"version": "1.0.0",
"description": "Shortcut to insert 'Hello world!'",
"engines": {
"foldingtext": ">=2.0.0",
"taskpaper": ">=3.0.0"
},
"homepage": "https://myhome.com"
}
style.less (optional)
If your plugin requires Create Themes rules you can include them with the plugin in a style.less
file.
That's your first plugin! Now "Command-H" inserts "Hello world!" instead of hiding FoldingText. If you plugin isn't working view it in the "Plug-Ins" preference pane to see if it had any configuration or loading errors.
Next Steps
-
Browse through the public API (listed on the right).
-
Learn from the existing plugins and use them as starting points for your own solutions.
-
Develop using Debugging for live refresh, to set breakpoints, and to step into FoldingText's uncompressed source code.
-
Write Specs for your plugin so I can test it as I develop FoldingText's core and make sure I don't break it!
-
Ask questions in the support forum.