I'm working on a project with Meteor, and I want it to use markdown, and it was very nice to see that there is a package to do that with.
我正在与Meteor合作开发一个项目,我希望它能使用markdown,很高兴看到有一个包用来做这件事。
So I meteor added showdown, it worked, and now I can do something like
所以我流星添加摊牌,它工作,现在我可以做类似的事情
{{#markdown}}
#This is a header
this is a paragraph
{{/markdown}}
and it works just fine. But now I want to actually put something more interesting in there. First thought was to sync it up with a textarea. I tried three things. First, I tried this:
它工作得很好。但现在我想在那里放一些更有趣的东西。首先想到的是将它与textarea同步。我尝试了三件事。首先,我试过这个:
$('.preview').html('{{#markdown}}'+$('#text').val()+'{{/markdown}}');
Where .preview is a div that I want to html to show up in, and #text is the textarea where someone is typing. This doesn't work though, it just shows the {{#markdown}} and stuff.
其中.preview是我希望html显示的div,而#text是某人正在键入的textarea。这不起作用,它只显示{{#markdown}}和东西。
Next, I tried to just set up the div like this:
接下来,我试着像这样设置div:
<div class="preview">
{{#markdown}}
{{/markdown}}
</div>
And add to it with:
并添加到:
$('.preview').html('#Is this an H1?');
or
$('.preview').append('*is this italics?*');
But again, it just showed the text, not the html.
但同样,它只显示了文本,而不是html。
Finally, I tried hard coding stuff into the markdown section, but that just clearly didn't work. Things like
最后,我尝试将内容编写到markdown部分,但这显然不起作用。像
<div class="preview">
{{#markdown}}
<div class="previewInner">
</div>
{{/markdown}}
</div>
or
<div class="span6 preview">
{{#markdown}}
{{>innerPreview}}
{{/markdown}}
</div>
So basically, I've tried everything I can think of and none of it does what I want. I tried I few more things, but I think you get the idea. How am I supposed to use this?
所以基本上,我已经尝试了所有我能想到的东西,而且没有一个能满足我的需求。我尝试了更多的东西,但我认为你明白了。我怎么用这个?
It's easy: just put your markdown inside {{#markdown}} ... {{/markdown}} tags.
这很简单:只需将标记放在{{#markdown}} ... {{/ markdown}}标记内。
1 个解决方案
#1
15
Everything inside markdown is considered markdown so make sure you do this:
降价内的所有内容都被视为降价,因此请确保执行此操作:
{{#markdown}}{{>innerPreview}}{{/markdown}}
Instead of
{{#markdown}}
{{>innerPreview}}
{{/markdown}}
The jquery wouldn't work because {{markdown}}
is rendered before the DOM is put in place.
jquery不起作用,因为{{markdown}}在DOM到位之前呈现。
Instead use a session
而是使用会话
Template.hello.markdown_data = function() {return Session.get("markdown_data")});
Then your template
然后你的模板
{{#markdown}}{{{markdown_data}}}{{/markdown}}
Then store your markdown document in
然后将您的降价文档存储在
Session.set("markdown_data","<your markdown data>");
Session.set(“markdown_data”,“ <你的降价数据> ”);
#1
15
Everything inside markdown is considered markdown so make sure you do this:
降价内的所有内容都被视为降价,因此请确保执行此操作:
{{#markdown}}{{>innerPreview}}{{/markdown}}
Instead of
{{#markdown}}
{{>innerPreview}}
{{/markdown}}
The jquery wouldn't work because {{markdown}}
is rendered before the DOM is put in place.
jquery不起作用,因为{{markdown}}在DOM到位之前呈现。
Instead use a session
而是使用会话
Template.hello.markdown_data = function() {return Session.get("markdown_data")});
Then your template
然后你的模板
{{#markdown}}{{{markdown_data}}}{{/markdown}}
Then store your markdown document in
然后将您的降价文档存储在
Session.set("markdown_data","<your markdown data>");
Session.set(“markdown_data”,“ <你的降价数据> ”);