最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How does one actually use Markdown with Meteor - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Jun 10, 2013 at 18:56 user1624005user1624005 1,0071 gold badge13 silver badges18 bronze badges 1
  • I use markdown in superchat.meteor. but with the package marked. It's the same syntax. Just take a look at the code: github./gabrielhpugliese/meteor_superchat/blob/master/client/… – gabrielhpugliese Commented Jun 10, 2013 at 19:18
Add a ment  | 

1 Answer 1

Reset to default 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.

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>");

发布评论

评论列表(0)

  1. 暂无评论