gajus/gitdown

Add ability to inject part of the code

Open

#49 创建于 2017年1月22日

在 GitHub 查看
 (0 评论) (3 反应) (0 负责人)JavaScript (51 fork)github user discovery
help wanted

仓库指标

Star
 (450 star)
PR 合并指标
 (PR 指标待抓取)

描述

Example, if I want to include this fragment https://github.com/gajus/gitdown/blob/12c91a46f33a0c926a1baed381d0636968c4f0f9/src/gitdown.js#L27-L50

I would surround the code fragment with comments such as:

// gitdown-template-start: foo-fragment
/**
 * Process template.
 *
 * @returns {Promise}
 */
gitdown.get = () => {
  return parser
    .play(input)
    .then((state) => {
      let markdown;

      markdown = state.markdown;

      if (gitdown.getConfig().headingNesting.enabled) {
        markdown = Gitdown.nestHeadingIds(markdown);
      }

      return gitdown
            .resolveURLs(markdown)
            .then(() => {
              return markdown.replace(/<!--\sgitdown:\s(:?off|on)\s-->/g, '');
            });
    });
};
// gitdown-template-end: foo-fragment

where "foo-fragment" is name of the fragment.

Then this snippet can be included into a README document using:

{"gitdown": "snippet", "file": "./src/gitdown.js", "name": "foo-fragment"}

This would be used to inject type declarations, etc. to documentation without needing to repeat them.

贡献者指南