diff --git a/lib/main.js b/lib/main.js
index da45504..13272f7 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,25 +1,44 @@
+// @ts-check
+///
'use babel';
-import { CompositeDisposable } from 'atom';
-import renderer from './renderer';
-
-export default {
+const { CompositeDisposable } = require('atom');
+const renderer = require('./renderer');
+/**
+ * the Atom IDE markdown service plugin
+ * @type {Object}
+ */
+module.exports = {
/**
* [subscriptions description]
* @type {CompositeDisposable}
*/
subscriptions: null,
+ /**
+ * called by Atom when activating an extension
+ * @param {any} state the current state of atom
+ */
activate(state) {
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable();
},
+ /**
+ * called by Atom when deactivating an extension
+ */
deactivate() {
- this.subscriptions.dispose();
+ if (this.subscriptions) {
+ this.subscriptions.dispose();
+ }
+ this.subscriptions = null;
},
+ /**
+ * provide an interface to the Markdown renderer service
+ * @return {AtomIDE.MarkdownService} the markdown renderer service
+ */
provideMarkdownRenderer() {
return renderer;
}
diff --git a/lib/renderer.js b/lib/renderer.js
index 76ed31c..00a9bc3 100644
--- a/lib/renderer.js
+++ b/lib/renderer.js
@@ -1,8 +1,9 @@
+// @ts-check
+///
'use babel';
-import { TextEditor } from 'atom';
-import { scopeForFenceName } from './utils';
-
+const { TextEditor } = require('atom');
+const { scopeForFenceName } = require('./utils');
const marked = require('marked');
const createDOMPurify = require('dompurify');
@@ -28,7 +29,7 @@ async function highlightCodeFragments(domFragment, grammar) {
if (fontFamily !== null) {
domFragment.querySelectorAll('code').forEach(codeElement => {
codeElement.style.fontFamily = fontFamily;
- codeElement.style.fontSize = fontSize;
+ codeElement.style.fontSize = `${fontSize}`;
});
}
@@ -84,7 +85,8 @@ function tokenizeEditor(editorElement, preElement) {
if ((languageMode.fullyTokenized) || (languageMode.tree)) {
editor.component.getNextUpdatePromise().then(() => {
done();
- });
+ })
+ .catch(reject);
}
else {
editor.onDidTokenize(() => {
@@ -110,13 +112,16 @@ function internalRender(markdownText) {
return template.content.cloneNode(true);
}
-
-export default {
+/**
+ * the markdown service object
+ * @type {AtomIDE.MarkdownService}
+ */
+module.exports = {
/**
* renders the markdown text to html
- * @param {String} markdownText the markdown text to render
- * @param {String} grammar the default grammar used in code sections that have no specific grammar set
- * @return {String} the inner HTML text of the rendered section
+ * @param {string} markdownText the markdown text to render
+ * @param {string} grammar the default grammar used in code sections that have no specific grammar set
+ * @return {Promise} the inner HTML text of the rendered section
*/
async render (markdownText, grammar) {
let node = internalRender(markdownText);
diff --git a/lib/utils.js b/lib/utils.js
index c73e71b..bae5c41 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -42,7 +42,7 @@ const scopesByFenceName = {
'yml': 'source.yaml'
};
-export default {
+module.exports = {
scopeForFenceName (fenceName) {
fenceName = fenceName.toLowerCase();
let result = `source.${fenceName}`;
diff --git a/package.json b/package.json
index 9f52d49..5940b90 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,7 @@
"providedServices": {
"markdown-renderer": {
"versions": {
- "0.1.0": "provideMarkdownRenderer"
+ "1.0.0": "provideMarkdownRenderer"
}
}
}
diff --git a/typings/atom-ide-community.d.ts b/typings/atom-ide-community.d.ts
new file mode 100644
index 0000000..7824c0b
--- /dev/null
+++ b/typings/atom-ide-community.d.ts
@@ -0,0 +1,5 @@
+declare module 'atom-ide' {
+ export interface MarkdownService {
+ render (markdownText: string, grammar: string) => Promise;
+ }
+}
diff --git a/typings/atom-ide.d.ts b/typings/atom-ide.d.ts
new file mode 100644
index 0000000..1287073
--- /dev/null
+++ b/typings/atom-ide.d.ts
@@ -0,0 +1,7 @@
+// @ts-check
+///
+///
+
+import * as AtomIDE from 'atom-ide';
+export = AtomIDE;
+export as namespace AtomIDE;