项目作者: dwiyanr

项目描述 :
thin Docsify plugin to support templating languages on Docsify
高级语言: JavaScript
项目地址: git://github.com/dwiyanr/docsify-templating.git
创建时间: 2020-04-11T14:22:12Z
项目社区:https://github.com/dwiyanr/docsify-templating

开源协议:MIT License

下载


docsify-templating

A thin Docsify plugin to support templating languages on Docsify markdown.
Heavily inspired by docsify-mustache.

Installation

Add the following script into docsify document:

  1. <script src="//unpkg.com/docsify-templating/dist/docsify-templating.min.js"></script>

Usage

Using handlebars

Docsify configuration:

  1. <!-- Need template engine to be added to the html, this example use Handlebars -->
  2. <script src="//unpkg.com/handlebars/dist/handlebars.min.js"></script>
  3. <script >
  4. window.$docsify = {
  5. // ...
  6. templating: {
  7. render: (content, data) => Handlebars.compile(content)(data),
  8. data: {
  9. from: "me",
  10. to: "World"
  11. }
  12. }
  13. };
  14. </script>

Markdown File:

  1. Hello {{to}}!
  2. Greetings from {{from}}.

Rendered Markdown:

  1. Hello World!
  2. Greetings from me.

Using function as data

Docsify configuration:

  1. window.$docsify = {
  2. // ...
  3. templating: {
  4. render: renderFun,
  5. data: {
  6. fetchFunction: async () =>
  7. JSON.parse(await Docsify.get("resource/data.json"))
  8. }
  9. }
  10. };

Data file resource/data.json

  1. {
  2. "from": "me",
  3. "to": "world"
  4. }

Markdown File:

  1. Hello {{fetchFunction.to}}!
  2. Greetings from {{fetchFunction.from}}.

Rendered Markdown:

  1. Hello World!
  2. Greetings from me.

Options

Docsify template configuration options

templating.data

  1. object

The data to be used to render the template. By default, it is an empty object. The object can be a nested one. The first level of data can be a function that returns the value that wants to be used. This can be used to fetch the data from external sources or separate docsify resource.

templating.render

  1. function(markdown_template, data) => string

A render function that accepts docsify markdown content as the template and
the data that specified on templating.data.