自定义流星中的{{#markdown}}行为 [英] Customize {{#markdown}} behavior in Meteor

查看:87
本文介绍了自定义流星中的{{#markdown}}行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我爱Markdown.这个概念是我几年来作为程序员遇到的最优雅,最有用的概念之一.因此,我很高兴看到Meteor实现Showdown程序包并将其与{{#markdown}}块帮助程序一起使用.

I love Markdown. The concept is one of the most elegant and useful I've come across in my few years as a programmer. So I was excited to see Meteor implement a Showdown package and let me use it with the {{#markdown}} block helper.

但是,当我开始使用它时,突然出现了我的最低最喜欢的降价陷阱:缩进代码块.

However, when I started using it, my least favorite gotcha of markdown suddenly appeared: Indented Code Blocks.

写这个:

<template name="home">
    {{#markdown}}
        Hello!!! Welcome to *My Site*!!
    {{/markdown}}
</template>

结果:

My Hello!!! Welcome to *My Site*!!

格式化为CODE !!!!

Formatted as CODE!!!!

我讨厌缩进的代码块.他们完全试图在编程环境中使用 Markdown.代码是经过严格缩进的,并且有充分的理由.它可以使事情井井有条,并使行为明确.因此,Markdown规范多年来错过了这一事实,这让我感到惊讶. Github的带围栏的代码块是一种无限的智能方式,因为它不需要重复按Tab键或空格键,使编辑变得更加容易,并且文本中的内容也更加清晰

I hate indented code blocks. They completely screw with attempts to actually use Markdown in a programming environment. Code is wildly indented, and for good reasons. It keeps things organized and makes behavior clear. So the fact that Markdown specifications have for years missed this is flabbergasting to me. Github's fenced code blocks are an infinitely more intelligent way to do this, since it doesn't require repetitive punching of the tab or space key, making it easier to edit, and it's clearer what's happening in the text.

反正</rant>.

我想自定义流星正在使用的降价促销.如何??我浏览了气氛并搜索了降价促销,但没有找到合适的选择.另外,我不确定如何在流星环境中使用Showdown扩展程序.

I want to customize the markdown being used by meteor. How?? I've looked through Atmosphere and searched markdown, and found nothing applicable. Also, I'm not sure how to use a Showdown extension in the meteor environment.

欢迎任何解决方案!!我真正想要的是一个没有缩进代码块的markdown实现.他们很愚蠢.

Any solutions welcome!! All I really want is a markdown implementation that doesn't have indented code blocks. They're stupid.

推荐答案

为什么不实现自己的markdown助手:

Why not implement your very own markdown helper:

// this is based on showdown package in spark branch
Handlebars.registerHelper('markdown', function (options) {
  return UI.block(function () {
    var self = this;
    return function () {
      var renderer = new marked.Renderer();
      var text = UI.toRawText(self.__content, self /* parentComponent */);
      return HTML.Raw(marked(trimIndentation(text), { renderer: renderer }));
    };
  });
});

其中trimIndentation看起来或多或少是这样的:

where trimIndentation can look more or less like this:

function trimIndentation(text) {
  var regexp = null,
      result = "";
  return text.split('\n').map(function (line) {
    var match = (regexp || /(\s*)(\s*[^\s]+.*)/).exec(line);
    if (match) {
      !regexp && (regexp = new RegExp("(\\s{" + match[1].length + "})(.*)"));
      return match[2];
    }
    return line;
  }).join('\n');
}

在上面的示例中,我使用了新模板引擎的语法,并且使用了已标记库,而不是旧的 showdown (或者我应该说 pagedown ?),但是您当然可以通过自己选择的设置来做同样的事情.

In the above example I used the syntax of the new templating engine as well as I used the marked library instead of good old showdown (or should I say pagedown?), but you can of course do the same thing with a setup of your own choice.

这篇关于自定义流星中的{{#markdown}}行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆