Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to inject part of the code #49

Open
gajus opened this issue Jan 22, 2017 · 0 comments
Open

Add ability to inject part of the code #49

gajus opened this issue Jan 22, 2017 · 0 comments

Comments

@gajus
Copy link
Owner

gajus commented Jan 22, 2017

Example, if I want to include this fragment

gitdown/src/gitdown.js

Lines 27 to 50 in 12c91a4

/**
* 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, '');
});
});
};

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant