Skip to content

Instantly share code, notes, and snippets.

@mrzapp
Last active October 16, 2018 09:02
Show Gist options
  • Save mrzapp/e01fe64b025c1599b9f68db6164305db to your computer and use it in GitHub Desktop.
Save mrzapp/e01fe64b025c1599b9f68db6164305db to your computer and use it in GitHub Desktop.
Markdown Processor for HashBrown
'use strict';
// This library comes preloaded with HashBrown
const ToMarkdown = require('to-markdown');
/**
* The processor class
*/
class MarkdownProcessor extends HashBrown.Models.Processor {
// Getters
static get name() { return 'Markdown'; }
static get alias() { return 'markdown'; }
/**
* Compiles content as markdown
*
* @param {Content} content
* @param {String} language
*
* @returns {Promise} Result
*/
process(content, language) {
checkParam(content, 'content', HashBrown.Models.Content);
checkParam(language, 'language', String);
let properties = content.getLocalizedProperties(language);
// Here "text" is the name of the input field in the ContentSchema
if(properties.text) {
properties.text = ToMarkdown(properties.text);
}
return Promise.resolve(data);
}
}
/**
* The HashBrown markdown plugin
*/
class Markdown {
static init(app) {
HashBrown.Helpers.ConnectionHelper.registerProcessor(MarkdownProcessor);
}
}
module.exports = Markdown;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment