Skip to content

Commit

Permalink
2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Jan 12, 2018
1 parent 3df1026 commit a91dd6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
39 changes: 14 additions & 25 deletions assets/javascripts/discourse-markdown/df-paypal-buy-now.js.es6
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
));
});
}
2 changes: 1 addition & 1 deletion plugin.rb
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'

0 comments on commit a91dd6d

Please # to comment.