Last active
March 5, 2018 00:39
-
-
Save ChapelR/803ec192cf5922f498652bd6a20a4bf8 to your computer and use it in GitHub Desktop.
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
function match (id, target, contents, macroName) { | |
return $(document.createElement('span')) | |
.attr({'id' : id, 'data-term' : target }) | |
.addClass('macro-' + macroName) | |
.wiki(contents); | |
} | |
function change (id, replacement) { | |
var $el = $(id), | |
text = $el.text(), | |
target = $el.attr('data-term'), | |
$content; | |
target = new RegExp(target, 'g'); | |
text = text.replace(target, replacement); | |
$content = $el.empty().wiki(text); | |
} | |
Macro.add('match', { | |
tags : null, | |
handler : function () { | |
if (this.args.length < 2 || this.args.length > 2) { | |
return this.error('incorrect number of arguments'); | |
} | |
var id = Util.slugify(this.args[0]), | |
target = this.args[1], $content; | |
$content = match(id, target, this.payload[0].contents, this.name); | |
$content.appendTo(this.output); | |
} | |
}); | |
Macro.add('change', { | |
handler : function () { | |
if (this.args.length < 2 || this.args.length > 2) { | |
return this.error('incorrect number of arguments'); | |
} | |
var id = Util.slugify(this.args[0]), | |
replacement = this.args[1]; | |
change('#' + id, replacement); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment