在HTML中为remark.js

时间:2017-01-12 07:28:00

标签: html html5 remarkjs

是否有(最好是轻量级方式)在HTML中包含markdown文件的原始内容?

我使用remark.js创建幻灯片,并且我希望将markdown文件与HTML分开,以便HTML非常简单(并且不会更改):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Test</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://gnab.github.io/remark/downloads/remark-latest.min.js"></script>
  </head>
  <body>
    <textarea id="source">
      >>'paste' markdown file test.md<<
    </textarea>
      <script>
        var slideshow = remark.create({
          highlightStyle: 'darkula',
          highlightLines: true
        });
      </script>
  </body>
</html>

理想情况下,它在本地计算机上脱机运行(不运行Web服务器)。粘贴&#39;粘贴&#39;降价文件test.md&#39;显然不起作用(因此我的问题)。我试过了:

  • object data="test.md"但会产生丑陋的iframe
  • This solution但我只是一个空页面(我使用了CDN for jQuery)。

1 个答案:

答案 0 :(得分:1)

根据remarkjs wiki,您需要添加以下行以包含降价文件

var slideshow = remark.create({
  sourceUrl: 'markdown.md'
});

以下是一个完整的例子

<!DOCTYPE html>
<html>
  <head>
    <title>A title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <style type="text/css">
      @import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
      @import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);

      body { font-family: 'Droid Serif'; }
      h1, h2, h3 {
        font-family: 'Yanone Kaffeesatz';
        font-weight: normal;
      }
      .remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
    </style>
  </head>
  <body>
    <script src="https://remarkjs.com/downloads/remark-latest.min.js" type="text/javascript">
    </script>
    <script type="text/javascript">
      var slideshow = remark.create({
      sourceUrl: 'your_file.md'
      });
    </script>
  </body>
</html>