azu / gitbook-plugin-include-codeblock

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

Getting error from link that contains 'import' #65

Closed q0rban closed 6 years ago

q0rban commented 6 years ago

I have a link in a Markdown file like this:

...
may be necessary to dump/import your data into the database server your preview
will connect to. For an example see the [MySQL import
example](/build-script/examples/import-mysql-database/index.md).
...

After installing this plugin, I get the following error during gitbook build:

warn: Error: file not found: /build-script/examples/import-mysql-database/index.md

If I remove the link or change the text (removing import), the error goes away.

I think the issue may be here. It seems to be checking for any occurrence of import|include throughout the entire array of possible "commands", which in the above case, I am assuming is:

commands = ["MySQL", "import", "example"];

It seems like the parser should only continue if import or include is the first command. Could the containIncludeCommand() function simply be something like the following?

export function containIncludeCommand(commands = []) {
    const reg = /^(include|import)$/;
    return commands.length > 0 ? reg.test(commands[0].trim()) : false;
}