From 45b9f8048a122132827757a03c893d56f0a3fe4a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 29 Aug 2013 13:59:41 -0400 Subject: [PATCH] Documentation update to dialect --- .../javascripts/discourse/dialects/dialect.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 5202c4910..bac59993b 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -97,7 +97,10 @@ Discourse.Dialect = { For example to replace all occurrances of :) with a smile image: ```javascript - Discourse.Dialect.inlineReplace(':)', ['img', {src: '/images/smile.gif'}]) + Discourse.Dialect.inlineReplace(':)', function (text) { + return ['img', {src: '/images/smile.png'}]; + }); + ``` @method inlineReplace @@ -204,6 +207,31 @@ Discourse.Dialect = { }; }, + /** + Replaces a block of text between a start and stop. As opposed to inline, these + might span multiple lines. + + Here's an example that takes the content between `[code]` ... `[/code]` and + puts them inside a `pre` tag: + + ```javascript + Discourse.Dialect.replaceBlock({ + start: /(\[code\])([\s\S]*)/igm, + stop: '[/code]', + + emitter: function(blockContents) { + return ['p', ['pre'].concat(blockContents)]; + } + }); + ``` + + @method replaceBlock + @param {Object} args Our replacement options + @param {String} [opts.start] The starting regexp we want to find + @param {String} [opts.stop] The ending token we want to find + @param {Function} [opts.emitter] The emitting function to transform the contents of the block into jsonML + + **/ replaceBlock: function(args) { dialect.block[args.start.toString()] = function(block, next) { args.start.lastIndex = 0;