-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3df1026
commit a91dd6d
Showing
2 changed files
with
15 additions
and
26 deletions.
There are no files selected for viewing
39 changes: 14 additions & 25 deletions
39
assets/javascripts/discourse-markdown/df-paypal-buy-now.js.es6
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,38 +1,27 @@ | ||
function textPostProcess(content, state, ruler) { | ||
var buttons = state.md.options.discourse.dfPayPalButtons; | ||
var originalContent = content; | ||
buttons.forEach(function(button) { | ||
var from = '[' + button.id + ']'; | ||
if (-1 !== content.indexOf(from)) { | ||
content = content.replace(from, '<div class="df-paypal-button ' + button.id + '"></div>'); | ||
} | ||
}); | ||
debugger; | ||
if (content === originalContent) { | ||
var token = new state.Token('text', '', 0); | ||
token.content = content; | ||
var result = []; | ||
result.push(content); | ||
return result; | ||
function textPostProcess(content, state) { | ||
var button, result; | ||
if (button = state.md.options.discourse.dfPayPalButtons[content]) { | ||
// 2018-01-18 I have used this code as an example of a `html_block` usage: | ||
// https://github.com/valeriangalliat/markdown-it-anchor/blob/v4.0.0/index.js#L27 | ||
result = new state.Token('html_block', '', 0); | ||
result.content = '<div class="df-paypal-button ' + button + '"></div>'; | ||
} | ||
return result; | ||
} | ||
//noinspection FunctionWithInconsistentReturnsJS | ||
export function setup(helper) { | ||
helper.registerOptions((opts, siteSettings) => { | ||
var valueS = siteSettings['«PayPal_Buy_Now»_Button_Code']; | ||
/** @type {Object[]} */ var items; | ||
try {items = JSON.parse(valueS);} | ||
catch(ignore) {items = [];} | ||
opts.dfPayPalButtons = items; | ||
opts.dfPayPalButtons = _.object(_.map(items, item => ['[' + item.id + ']', item.id])); | ||
}); | ||
helper.whiteList({custom(tag, name, value) { | ||
return 'div' === tag && 'class' == name && 0 === value.indexOf('df-'); | ||
}}); | ||
/*helper.registerPlugin(md => { | ||
const ruler = md.core.textPostProcess.ruler; | ||
const replacer = (content, state) => textPostProcess(content, state, ruler); | ||
md.core.ruler.push('df-paypal-buy-now', state => | ||
md.options.discourse.helpers.textReplace(state, replacer, true) | ||
); | ||
}); */ | ||
helper.registerPlugin(md => { | ||
md.core.ruler.push('df-paypal-buy-now', state => md.options.discourse.helpers.textReplace( | ||
state, (content, state) => textPostProcess(content, state), true | ||
)); | ||
}); | ||
} |
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,6 +1,6 @@ | ||
# name: df-paypal-buy-now | ||
# about: You can insert PayPal «Buy Now» button to your forum posts. | ||
# version: 2.2.0 | ||
# version: 2.3.0 | ||
# authors: Dmitry Fedyuk | ||
# url: https://discourse.pro/t/29 | ||
register_asset 'stylesheets/main.scss' |