-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: STRF-10493 Address markdown helper messy logs (#266)
- Loading branch information
1 parent
258b56e
commit b12710a
Showing
4 changed files
with
147 additions
and
142 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
const merge = require('./mixinDeep'); | ||
const { Remarkable } = require('remarkable'); | ||
const {Remarkable} = require('remarkable'); | ||
const {linkify} = require('remarkable/linkify'); | ||
|
||
module.exports = function markdown(config) { | ||
|
||
if (typeof config === 'string') { | ||
return helper.apply(this, arguments); | ||
} | ||
|
||
config = config || {}; | ||
if (config.fn || config.hash || arguments.length > 1) { | ||
console.log(arguments); | ||
return helper.apply(this, arguments); | ||
} | ||
|
||
function helper(context, options) { | ||
if (typeof context === 'string') { | ||
var opts = merge({}, config, options); | ||
console.log(options) | ||
var md = new Remarkable(opts); | ||
return md.render(context); | ||
if (typeof config === 'string') { | ||
return helper.apply(this, arguments); | ||
} | ||
|
||
if (typeof context === 'object' && typeof context.fn === 'function') { | ||
options = context; | ||
context = {}; | ||
config = config || {}; | ||
if (config.fn || config.hash || arguments.length > 1) { | ||
return helper.apply(this, arguments); | ||
} | ||
|
||
options = merge({ html: true, breaks: true }, config, options); | ||
options = merge({}, options, options.markdown, options.hash); | ||
if (options.hasOwnProperty('lang')) { | ||
options.langPrefix = options.lang; | ||
function helper(context, options) { | ||
|
||
if (typeof context === 'string') { | ||
const opts = merge({}, config, options); | ||
const md = buildRemarkable(opts); | ||
return md.render(context); | ||
} | ||
|
||
if (typeof context === 'object' && typeof context.fn === 'function') { | ||
options = context; | ||
context = {}; | ||
} | ||
|
||
options = merge({html: true, breaks: true}, config, options); | ||
options = merge({}, options, options.markdown, options.hash); | ||
if (options.hasOwnProperty('lang')) { | ||
options.langPrefix = options.lang; | ||
} | ||
|
||
const md = buildRemarkable(options); | ||
const ctx = merge({}, options, (this.context || this), context); | ||
return md.render(options.fn(ctx)); | ||
} | ||
|
||
var md = new Remarkable(options); | ||
var ctx = merge({}, options, (this.context || this), context); | ||
return md.render(options.fn(ctx)); | ||
} | ||
function buildRemarkable(options) { | ||
const remarkable = options.linkify === true ? new Remarkable(options).use(linkify) : new Remarkable(options); | ||
delete options.linkify; | ||
return remarkable; | ||
} | ||
|
||
return helper; | ||
}; | ||
return helper; | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ describe('markdown', function() { | |
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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