mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
{{#markdown}} works!
This commit is contained in:
@@ -4,7 +4,7 @@ if (Package.ui) {
|
||||
Package.ui.Handlebars.registerHelper('markdown', UI.block(function () {
|
||||
var self = this;
|
||||
return function () {
|
||||
var text = UI.toRawText(self.__content);
|
||||
var text = UI.toRawText(self.__content, self /*parentComponent*/);
|
||||
var converter = new Showdown.converter();
|
||||
return HTML.Raw(converter.makeHtml(text));
|
||||
};
|
||||
|
||||
@@ -288,7 +288,8 @@
|
||||
</template>
|
||||
|
||||
<template name="spacebars_template_test_markdown_basic">
|
||||
{{#markdown}}
|
||||
{{#with obj}}
|
||||
{{#markdown}}
|
||||
{{hi}}
|
||||
/each}}
|
||||
|
||||
@@ -301,20 +302,28 @@
|
||||
* <b>{{hi}}</b>
|
||||
* <b>/each}}</b>
|
||||
|
||||
some paragraph to fix showdown's four space parsing below.
|
||||
|
||||
{{hi}}
|
||||
/each}}
|
||||
|
||||
<b>{{hi}}</b>
|
||||
<b>/each</b>
|
||||
<b>/each}}</b>
|
||||
|
||||
>
|
||||
|
||||
* >
|
||||
|
||||
`>`
|
||||
|
||||
>
|
||||
|
||||
>
|
||||
|
||||
* >
|
||||
|
||||
`>`
|
||||
|
||||
>
|
||||
|
||||
`{{hi}}`
|
||||
@@ -323,19 +332,29 @@
|
||||
`<b>{{hi}}</b>`
|
||||
`<b>/each}}`
|
||||
|
||||
{{/markdown}}
|
||||
{{/markdown}}
|
||||
{{/with}}
|
||||
</template>
|
||||
|
||||
<template name="spacebars_template_test_markdown_if">
|
||||
{{#markdown}}
|
||||
|
||||
{{#if cond}}true{{else}}false{{/if}}
|
||||
|
||||
<b>{{#if cond}}true{{else}}false{{/if}}</b>
|
||||
|
||||
* {{#if cond}}true{{else}}false{{/if}}
|
||||
|
||||
* <b>{{#if cond}}true{{else}}false{{/if}}</b>
|
||||
|
||||
some paragraph to fix showdown's four space parsing below.
|
||||
|
||||
{{#if cond}}true{{else}}false{{/if}}
|
||||
|
||||
<b>{{#if cond}}true{{else}}false{{/if}}</b>
|
||||
|
||||
`{{#if cond}}true{{else}}false{{/if}}`
|
||||
|
||||
`<b>{{#if cond}}true{{else}}false{{/if}}</b>`
|
||||
|
||||
{{/markdown}}
|
||||
@@ -345,12 +364,21 @@
|
||||
{{#markdown}}
|
||||
|
||||
{{#each seq}}{{.}}{{/each}}
|
||||
|
||||
<b>{{#each seq}}{{.}}{{/each}}</b>
|
||||
|
||||
* {{#each seq}}{{.}}{{/each}}
|
||||
|
||||
* <b>{{#each seq}}{{.}}{{/each}}</b>
|
||||
|
||||
some paragraph to fix showdown's four space parsing below.
|
||||
|
||||
{{#each seq}}{{.}}{{/each}}
|
||||
|
||||
<b>{{#each seq}}{{.}}{{/each}}</b>
|
||||
|
||||
`{{#each seq}}{{.}}{{/each}}`
|
||||
|
||||
`<b>{{#each seq}}{{.}}{{/each}}</b>`
|
||||
|
||||
{{/markdown}}
|
||||
|
||||
@@ -946,16 +946,76 @@ Tinytest.add('spacebars - templates - constant #each argument', function (test)
|
||||
// @returns {String} simplified html content
|
||||
var divContentForMarkdown = function (div) {
|
||||
return trim(stripComments(div.innerHTML))
|
||||
.replace(/\<br\>/g, '\n');
|
||||
.replace(/\<br\>/g, '\n')
|
||||
.replace(/<(\/?\S+)>/g, function (s) { return s.toLowerCase(); }); // for IE
|
||||
};
|
||||
|
||||
// extract a multi-line string from a comment within a function.
|
||||
// @param f {Function} eg function () { /* [[[...content...]]] */ }
|
||||
// @returns {String} eg "content"
|
||||
var textFromFunction = function(f) {
|
||||
return f.toString().match(/\[\[\[([\S\s]*)\]\]\]/m)[1]
|
||||
.replace(/[ ]*\/\/ \d+$/gm, ''); // remove line number comments
|
||||
};
|
||||
|
||||
Tinytest.add('spacebars - templates - #markdown - basic', function (test) {
|
||||
var tmpl = Template.spacebars_template_test_markdown_basic;
|
||||
tmpl.obj = {snippet: "<i>hi</i>"};
|
||||
tmpl.hi = function () {
|
||||
return "<i>hi</i>";
|
||||
return this.snippet;
|
||||
};
|
||||
var div = renderToDiv(tmpl);
|
||||
test.equal(divContentForMarkdown(div), "FIXME");
|
||||
test.equal(divContentForMarkdown(div), textFromFunction(function () { /*
|
||||
[[[<p><i>hi</i>
|
||||
/each}}</p>
|
||||
|
||||
<p><b><i>hi</i></b>
|
||||
<b>/each}}</b></p>
|
||||
|
||||
<ul>
|
||||
<li><i>hi</i></li>
|
||||
<li><p>/each}}</p></li>
|
||||
<li><p><b><i>hi</i></b></p></li>
|
||||
<li><b>/each}}</b></li>
|
||||
</ul>
|
||||
|
||||
<p>some paragraph to fix showdown's four space parsing below.</p>
|
||||
|
||||
<pre><code><i>hi</i>
|
||||
/each}}
|
||||
|
||||
<b><i>hi</i></b>
|
||||
<b>/each}}</b>
|
||||
</code></pre>
|
||||
|
||||
<p>&gt</p>
|
||||
|
||||
<ul>
|
||||
<li>&gt</li>
|
||||
</ul>
|
||||
|
||||
<p><code>&gt</code></p>
|
||||
|
||||
<pre><code>&gt
|
||||
</code></pre>
|
||||
|
||||
<p>></p>
|
||||
|
||||
<ul>
|
||||
<li>></li>
|
||||
</ul>
|
||||
|
||||
<p><code>&gt;</code></p>
|
||||
|
||||
<pre><code>&gt;
|
||||
</code></pre>
|
||||
|
||||
<p><code><i>hi</i></code>
|
||||
<code>/each}}</code></p>
|
||||
|
||||
<p><code><b><i>hi</i></b></code>
|
||||
<code><b>/each}}</code></p>]]] */
|
||||
}));
|
||||
});
|
||||
|
||||
Tinytest.add('spacebars - templates - #markdown - if', function (test) {
|
||||
@@ -964,10 +1024,50 @@ Tinytest.add('spacebars - templates - #markdown - if', function (test) {
|
||||
tmpl.cond = function () { return R.get(); };
|
||||
|
||||
var div = renderToDiv(tmpl);
|
||||
test.equal(divContentForMarkdown(div), "FIXME(false)");
|
||||
test.equal(divContentForMarkdown(div), textFromFunction(function () { /*
|
||||
[[[<p>false</p>
|
||||
|
||||
<p><b>false</b></p>
|
||||
|
||||
<ul>
|
||||
<li><p>false</p></li>
|
||||
<li><p><b>false</b></p></li>
|
||||
</ul>
|
||||
|
||||
<p>some paragraph to fix showdown's four space parsing below.</p>
|
||||
|
||||
<pre><code>false
|
||||
|
||||
<b>false</b>
|
||||
</code></pre>
|
||||
|
||||
<p><code>false</code></p>
|
||||
|
||||
<p><code><b>false</b></code></p>]]] */
|
||||
}));
|
||||
R.set(true);
|
||||
Deps.flush();
|
||||
test.equal(divContentForMarkdown(div), "FIXME(true)");
|
||||
test.equal(divContentForMarkdown(div), textFromFunction(function () { /*
|
||||
[[[<p>true</p>
|
||||
|
||||
<p><b>true</b></p>
|
||||
|
||||
<ul>
|
||||
<li><p>true</p></li>
|
||||
<li><p><b>true</b></p></li>
|
||||
</ul>
|
||||
|
||||
<p>some paragraph to fix showdown's four space parsing below.</p>
|
||||
|
||||
<pre><code>true
|
||||
|
||||
<b>true</b>
|
||||
</code></pre>
|
||||
|
||||
<p><code>true</code></p>
|
||||
|
||||
<p><code><b>true</b></code></p>]]] */
|
||||
}));
|
||||
});
|
||||
|
||||
Tinytest.add('spacebars - templates - #markdown - each', function (test) {
|
||||
@@ -976,10 +1076,47 @@ Tinytest.add('spacebars - templates - #markdown - each', function (test) {
|
||||
tmpl.seq = function () { return R.get(); };
|
||||
|
||||
var div = renderToDiv(tmpl);
|
||||
test.equal(divContentForMarkdown(div), "FIXME([])");
|
||||
test.equal(divContentForMarkdown(div), textFromFunction(function () { /*
|
||||
[[[<p><b></b></p>
|
||||
|
||||
<ul>
|
||||
<li></li>
|
||||
<li><b></b></li>
|
||||
</ul>
|
||||
|
||||
<p>some paragraph to fix showdown's four space parsing below.</p>
|
||||
|
||||
<pre><code><b></b>
|
||||
</code></pre>
|
||||
|
||||
<p>``</p>
|
||||
|
||||
<p><code><b></b></code></p>]]] */
|
||||
}));
|
||||
|
||||
R.set(["item"]);
|
||||
Deps.flush();
|
||||
test.equal(divContentForMarkdown(div), "FIXME([\"item\"])");
|
||||
test.equal(divContentForMarkdown(div), textFromFunction(function () { /*
|
||||
[[[<p>item</p>
|
||||
|
||||
<p><b>item</b></p>
|
||||
|
||||
<ul>
|
||||
<li><p>item</p></li>
|
||||
<li><p><b>item</b></p></li>
|
||||
</ul>
|
||||
|
||||
<p>some paragraph to fix showdown's four space parsing below.</p>
|
||||
|
||||
<pre><code>item
|
||||
|
||||
<b>item</b>
|
||||
</code></pre>
|
||||
|
||||
<p><code>item</code></p>
|
||||
|
||||
<p><code><b>item</b></code></p>]]] */
|
||||
}));
|
||||
});
|
||||
|
||||
Tinytest.add('spacebars - templates - #markdown - inclusion', function (test) {
|
||||
|
||||
@@ -12,7 +12,7 @@ UI.If = Component.extend({
|
||||
// of a Component during init (but presumably not before
|
||||
// or after)?
|
||||
},
|
||||
render: function (buf) {
|
||||
render: function () {
|
||||
var self = this;
|
||||
return function () {
|
||||
var condition = getCondition(self);
|
||||
@@ -54,7 +54,7 @@ UI.Unless = Component.extend({
|
||||
this.condition = this.data;
|
||||
this.data = undefined;
|
||||
},
|
||||
render: function (buf) {
|
||||
render: function () {
|
||||
var self = this;
|
||||
return function () {
|
||||
var condition = getCondition(self);
|
||||
@@ -68,7 +68,7 @@ UI.With = Component.extend({
|
||||
init: function () {
|
||||
this.condition = this.data;
|
||||
},
|
||||
render: function (buf) {
|
||||
render: function () {
|
||||
var self = this;
|
||||
return function () {
|
||||
var condition = getCondition(self);
|
||||
|
||||
Reference in New Issue
Block a user