APIs design is still in beta stage, so there might be changes in the future.
The idea is from issue #101.
First of all, you need to open your Atom init.coffee
file by cmd+shift+p then choose Application: Open Your Init Script
.
Then you can add the following code:
atom.packages.onDidActivatePackage (pkg) ->
if pkg.name is 'markdown-preview-enhanced'
# Write your extension here
# for example:
pkg.mainModule.onWillParseMarkdown (markdown)->
markdown + '\nadd this extra line.'
Two types of Event Subscriptions are provided:
- Synchronous
- Asynchronous
Calls your callback
before the markdown
string is parsed by remarkable.
Argument | Description |
---|---|
callback(markdown ) |
Function |
markdown |
String |
callback
function here has to return a string that will be parsed to markdown parser in the future.
Example:
pkg.mainModule.onWillParseMarkdown (markdown)->
"# This is heading will be added in front\n" + markdown
### ::onDidParseMarkdown(callback) Calls your `callback` after parsing markdown.
Argument | Description |
---|---|
callback(htmlString ) |
Function |
htmlString |
String |
callback
function here has to return a HTML string that will be rendered on preview in the future.
Example:
pkg.mainModule.onDidParseMarkdown (htmlString)->
htmlString + "<h1>This heading will be added at the end of html</h1>"
callback
doesn't have to return a value
Calls your callback
after the preview has rendered html
Argument | Description |
---|---|
callback(event ) |
Function |
event |
Object |
.htmlString |
String |
.previewElement |
DOM |
Example
pkg.mainModule.onDidRenderPreview (event)->
previewElement = event.previewElement
previewElement.innerHTML += '<h1>This heading will be added at the end of html</h1>'