Markdown 内的把手、HAML 内的把手

发布于 2024-12-08 03:29:06 字数 943 浏览 0 评论 0原文

我知道这是一个非常不标准的用例,但我链接了 HAML、Markdown 和 Handlebars(在 SproutCore 2.0 中),距离“美丽”代码只有一步之遥。混合 HAML、Markdown 和 Javascript 并不理想。如果我想向 HAML 的整个输出添加后置过滤器,请将 {{text}} 替换为 ,最好的方法是什么?

我可以在 haml 之后修改构建后步骤,但我想将其变成可以回馈 SproutCore 社区的东西。

我想替换

%body
  javascript:
    {{handlebars}}

%body
  {{handlebars}}

Which 会给我

<body>
  <script>{{handlebars}}</script>
</body>

但是,我也希望它在嵌入到 markdown 中时也能工作。例如,

%body
  markdown:
    # Hello, {{handlebars}}

目前,获得此结果的唯一方法是

%body
  markdown:
    # Hello, <script>{{handlebars}}</script>

Which will Product

<body>
  <h1>Hello, <script>{{handlebars}}</script></h1>
</body>

I know that this is a very non-standard use case, but I'm chaining HAML, Markdown, and Handlebars (in SproutCore 2.0), and I'm 1 step away from 'beautiful' code. Intermingling HAML, Markdown, and Javascript is less ideal than it could be. If I wanted to add a post-filter to the entire output of HAML, replacing {{text}} with <script>{{text}}</script>, what would be the best way to do it?

I could just hack on a post-build step after haml, but I'd like to turn it into something that I can give back to the SproutCore community.

I want to replace

%body
  javascript:
    {{handlebars}}

With

%body
  {{handlebars}}

Which would give me

<body>
  <script>{{handlebars}}</script>
</body>

However, I also want this to work when embedded within markdown. For example,

%body
  markdown:
    # Hello, {{handlebars}}

Currently, the only way to get this is

%body
  markdown:
    # Hello, <script>{{handlebars}}</script>

Which would product

<body>
  <h1>Hello, <script>{{handlebars}}</script></h1>
</body>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2024-12-15 03:29:06

很久以后重新审视同一问题,HAML 似乎没有一个好的解决方案。然而,杰德几乎做了我想做的一切。

http://jade-lang.com/

输入

html
  script(type='text/x-handlebars')
    :markdown
      *Hello, {{handlebars}}!*

输出

<html>
  <script type="text/x-handlebars"><p><em>Hello, {{handlebars}}!</em></p>
  </script>
</html>

Revisiting the same issue much, much later, it appears that there's not a good solution for this with HAML. However, Jade does just about everything that I want.

http://jade-lang.com/

Input

html
  script(type='text/x-handlebars')
    :markdown
      *Hello, {{handlebars}}!*

Output

<html>
  <script type="text/x-handlebars"><p><em>Hello, {{handlebars}}!</em></p>
  </script>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文