azu / gitbook-plugin-include-codeblock

GitBook plugin for including file
Other
40 stars 25 forks source link

Option to omit link to file #7

Closed orlade closed 8 years ago

orlade commented 8 years ago

When including files that are outside of the GitBook scope, the included link will be a 404. If this is expected, I would prefer to omit the link since it could be confusing.

Alternatively, if the referenced file is not in _book, copy it there.

An example would be including snippets from source files in a project in which the book lives under /docs.

azu commented 8 years ago

the included link will be a 404. If this is expected

This is indeeded behavior.

I would prefer to omit the link since it could be confusing.

I agree with.

Or if the referenced file is not in _book, throw Error.

The design of this plugin is for GitHub and GitBook. It means that it work as a relative link in GitHub and work as a CodeBlock in GitBook.

johnlindquist commented 8 years ago

I've just manually ripped out the link in from https://github.com/azu/gitbook-plugin-include-codeblock/blob/master/src/parser.js#L65

return "``` " + lang + "\n" + content + "\n```";

My use case is explaining the same file broken into pieces:

Import `bootstrap`:
[import:1-1, lang-typescript](./code/src/main.ts)
The line above will blah, blah, blah

Import your App
[import:2-2, lang-typescript](./code/src/main.ts)

Bootstrap your App
[import:4-5, lang-typescript](./code/src/main.ts)

And having "main.ts" show up over and over is distracting.

image

azu commented 8 years ago

If we introduced pluginsConfig like "embed-template", can you resolve this issue?

{
    "plugins": ["include-codeblock"],
    "pluginsConfig": {
        "include-codeblock": {
            "embed-template": "```${lang}\n${content}\n```"
        }
    }
}

if "embed-template" is defined, use it instead of built-in template.

johnlindquist commented 8 years ago

@azu that's actually a pretty neat solution...

Maybe it could switch between templates if you need multiple variations?

{
    "plugins": ["include-codeblock"],
    "pluginsConfig": {
        "include-codeblock": {
            "my-template": "```${lang}\n${content}\n```",
            "template-copyright": "```${content}\n copyright me```",
        }
    }
}
[import, my-template](./src/code.js)
[import, template-copyright](./src/code.js)

?