Last active
October 16, 2018 09:02
-
-
Save mrzapp/e01fe64b025c1599b9f68db6164305db to your computer and use it in GitHub Desktop.
Markdown Processor for HashBrown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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