strapi-markdown-parser
Advanced tools
Comparing version 0.0.4 to 0.0.5
48
index.js
class StrapiMarkdown { | ||
constructor(model, types, options) { | ||
this.types = {} | ||
constructor( | ||
model, | ||
types = { | ||
standard: ['richtext'], | ||
inline: ['string'] | ||
}, | ||
options = { | ||
smartypants: true, | ||
headerIds: false, | ||
breaks: true | ||
} | ||
) { | ||
if (types && (types.constructor === Object || Array.isArray(types))) { | ||
this.types = types | ||
} | ||
if (types && types.constructor === Object) { | ||
this.types.standard = types.standard | ||
this.types.inline = types.inline | ||
} else if (types && Array.isArray(types)) { | ||
this.types.standard = types | ||
if (model) { | ||
this.model = this.model.attributes | ||
} else { | ||
this.types.standard = ['richtext'] | ||
this.types.inline = ['string'] | ||
throw new Error('StrapiMarkdown requires `model`') | ||
} | ||
this.marked = require('marked') | ||
options | ||
? this.marked.setOptions(options) | ||
: this.marked.setOptions({ | ||
smartypants: true, | ||
headerIds: false, | ||
breaks: true | ||
}) | ||
this.marked.setOptions(options) | ||
} | ||
@@ -28,9 +30,7 @@ | ||
for (let key in this.model) { | ||
let out | ||
if (this.types.standard.includes(this.model[key].type)) { | ||
out = this.marked(data[key] || '') | ||
if (this.types.standard && this.types.standard.includes(this.model[key].type)) { | ||
const out = this.marked(data[key] || '') | ||
data[key] = out.length ? out : null | ||
} else if (this.types.inline.includes(this.model[key].type)) { | ||
out = this.marked.parseInline(data[key] || '') | ||
} else if (this.types.inline && this.types.inline.includes(this.model[key].type)) { | ||
const out = this.marked.parseInline(data[key] || '') | ||
data[key] = out.length ? out : null | ||
@@ -44,4 +44,2 @@ } | ||
md(data) { | ||
model = model.attributes | ||
if (Array.isArray(data)) { | ||
@@ -48,0 +46,0 @@ return data.map(obj => this.parse(obj)) |
{ | ||
"name": "strapi-markdown-parser", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Strapi controller module to parse Markdown to HTML", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113
6426