Skip to content

Commit

Permalink
feat: typing and documentation added
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Gerlach committed Apr 18, 2019
1 parent d01b00e commit 4e7f229
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
29 changes: 24 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
// @ts-check
/// <reference path="../typings/atom-ide.d.ts"/>
'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;
}
Expand Down
25 changes: 15 additions & 10 deletions lib/renderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-check
/// <reference path="../typings/atom-ide.d.ts"/>
'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');

Expand All @@ -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}`;
});
}

Expand Down Expand Up @@ -84,7 +85,8 @@ function tokenizeEditor(editorElement, preElement) {
if ((languageMode.fullyTokenized) || (languageMode.tree)) {
editor.component.getNextUpdatePromise().then(() => {
done();
});
})
.catch(reject);
}
else {
editor.onDidTokenize(() => {
Expand All @@ -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<string>} the inner HTML text of the rendered section
*/
async render (markdownText, grammar) {
let node = internalRender(markdownText);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const scopesByFenceName = {
'yml': 'source.yaml'
};

export default {
module.exports = {
scopeForFenceName (fenceName) {
fenceName = fenceName.toLowerCase();
let result = `source.${fenceName}`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"providedServices": {
"markdown-renderer": {
"versions": {
"0.1.0": "provideMarkdownRenderer"
"1.0.0": "provideMarkdownRenderer"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions typings/atom-ide-community.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'atom-ide' {
export interface MarkdownService {
render (markdownText: string, grammar: string) => Promise<string>;
}
}
7 changes: 7 additions & 0 deletions typings/atom-ide.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-check
/// <reference path="../node_modules/atom-languageclient/typings/atom-ide/index.d.ts" />
/// <reference path="./atom-ide-community.d.ts" />

import * as AtomIDE from 'atom-ide';
export = AtomIDE;
export as namespace AtomIDE;

0 comments on commit 4e7f229

Please sign in to comment.