一个人如何在Meteor中使用Markdown? [英] How does one actually use Markdown with Meteor
问题描述
我正在与Meteor合作开发一个项目,我希望它使用markdown,并且很高兴看到有一个包可以做到这一点。
因此,我加入流星摊牌,它工作,现在我可以做一些像
{{#markdown}}
#这是一个标题
这是一个段落
{{/ markdown}}
,它工作得很好。但是现在我想要在那里放些更有趣的东西。首先想到的是将其与textarea同步。我尝试了三件事。首先,我尝试了这一点:
$ b
$('。preview')。html('{{#markdown}}'+ $ ( '#text')VAL()+ '{{/降价}}');
其中.preview是我希望html显示的div,而#text是textarea在哪里打字。这不起作用,它只是显示{{#markdown}}和东西。
接下来,我试图设置这样的div: p>
< div class =preview>
{{#markdown}}
{{/ markdown}}
< / div>
并添加到它:
<$ p $(p。code> $('。preview')。html('#This is a H1?');
或
$('。preview')。append('* is this italics?*');
但是,它只是显示了文本,而不是html。
最后,我尝试在降价部分编写硬编码的东西,但显然不起作用。诸如
< div class =preview>
{{#markdown}}
< div class =previewInner>
< / div>
{{/ markdown}}
< / div>
或
< div class =span6 preview>
{{#markdown}}
{{> innerPreview}}
{{/ markdown}}
< / div>
所以基本上,我已经尝试过所有我能想到的东西,而且没有一个能做到我想要的。我尝试了几件事,但我认为你明白了。我应该如何使用它?
很容易:只需将标记放在{{#markdown}}中即可... {{/
Markdown内的所有内容都被视为降价,因此请确保您这样做:
{{#markdown}} {{> innerPreview}} {{/ markdown}}
code>
而不是
{ {#markdown}}
{{> innerPreview}}
{{/ markdown}}
jquery不起作用,因为在放置DOM之前呈现 {{markdown}}
。
改为使用会话
Template.hello.markdown_data = function(){return Session.get(markdown_data )});
然后您的模板
{{#markdown}} {{{markdown_data}}} {{/ markdown}}
然后将您的降价文件存储在
Session.set(markdown_data,< your markdown data>);
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.
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:
$('.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.
Next, I tried to just set up the div like this:
<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.
Finally, I tried hard coding stuff into the markdown section, but that just clearly didn't work. Things like
<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.
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.
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>");
这篇关于一个人如何在Meteor中使用Markdown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!