honkit / honkit

:book: HonKit is building beautiful books using Markdown - Fork of GitBook

Home Page:https://honkit.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error occured of "include file not found" by using asciidoc include directive.

UsedPartsJapan opened this issue · comments

Summary

When using the include directive in an AsciiDoc file, an "include file not found" error occurs.

asciidoctor: ERROR: : line 3: include file not found: D:/Document/share/TechnicalSiteGenerator/HonKit/resources/included1.txt
asciidoctor: ERROR: : line 8: include file not found: Q:/Document/share/TechnicalSiteGenerator/HonKit/resources/included2.txt
asciidoctor: ERROR: : line 13: include file not found: Q:/Document/share/TechnicalSiteGenerator/HonKit/resources/included3.txt

  • HonKit version: 4.0.8

Step to reproduce

  1. make content1.adoc file like bellow.
----
include:: ./resources/included1.txt[]
----
  1. build
    npx honkit build

Expected results

This is the included text1 !

Actual results

Unresolved directive in - include::./resources/included1.txt[]

$ npx honkit build --log=debug
debug: readme found at README.adoc
debug: summary file found at SUMMARY.adoc
debug: cleanup folder "Q:\Document\share\TechnicalSiteGenerator\HonKit_book"
info: 4 plugins are installed
info: 4 explicitly listed
info: plugin "search-pro-fixed" is loaded
info: plugin "highlight" is loaded
info: plugin "fontsettings" is loaded
info: plugin "theme-default" is loaded
info: found 3 pages
info: found 3 asset files
debug: calling hook "config"
debug: calling hook "init"
debug: copy assets from theme Q:\Document\share\TechnicalSiteGenerator\HonKit\node_modules@honkit\honkit-plugin-theme-default_assets\website
debug: copy resources from plugin Q:\Document\share\TechnicalSiteGenerator\HonKit\node_modules\gitbook-plugin-fontsettings\assets
debug: copy resources from plugin Q:\Document\share\TechnicalSiteGenerator\HonKit\node_modules@honkit\honkit-plugin-highlight\css
debug: copy resources from plugin Q:\Document\share\TechnicalSiteGenerator\HonKit\node_modules\gitbook-plugin-search-pro-fixed\assets
debug: copy asset "chapter-1\resources\included1.txt"
debug: copy asset "chapter-1\resources\included2.txt"
debug: copy asset "chapter-1\resources\included3.txt"
debug: calling hook "page:before"
debug: calling hook "page:before"
debug: calling hook "page:before"
asciidoctor: ERROR: : line 3: include file not found1: Q:/Document/share/TechnicalSiteGenerator/HonKit/resources/included1.txt
asciidoctor: ERROR: : line 8: include file not found1: Q:/Document/share/TechnicalSiteGenerator/HonKit/resources/included2.txt
asciidoctor: ERROR: : line 13: include file not found1: Q:/Doc
ument/share/TechnicalSiteGenerator/HonKit/resources/included3.txt
debug: calling hook "page"
debug: calling hook "page"
debug: calling hook "page"
debug: index page README.adoc
debug: index page chapter-1/README.adoc
debug: index page chapter-1/content1.adoc
debug: calling hook "finish:before"
debug: calling hook "finish"
debug: write search index
info: >> generation finished with success in 29.6s !

commented

Thanks for report.

I confirmed it.
It is failed on Windows/Linux.
https://github.com/azu/honkit-issue-356/actions/runs/5564350767/jobs/10163899453

The cause seems to be that the base directory is not taken into convert function.

  • Actual: Q:/Document/share/TechnicalSiteGenerator/HonKit/resources/included1.txt
  • Expected: Q:/Document/share/TechnicalSiteGenerator/HonKit/docs/chapter-1/resources/included1.txt
----
include:: ./docs/chapter-1resources/included1.txt[]
----

This will works but is not user-friendly.

Currently, the execution directory, not the file, seems to have become the starting point for path resolution.

Note: how to fix

📝 I dig it, but it is a bit complex…

I want to pass base directory to these convert method.

function asciidocToHTML(content: string) {
return asciidoctor.convert(content, { safe: "server", attributes: { showtitle: "", icons: "font@" } });
}
// Render Asciidoc to HTML (inline)
function asciidocToHTMLInline(content: string) {
return asciidoctor.convert(content, { doctype: "inline" });
}

Call Stack

  • wrap asciidocToHTML

const parser: any = {
summary: compose(toHTML.block, htmlParser.summary),
glossary: compose(toHTML.block, htmlParser.glossary),
langs: compose(toHTML.block, htmlParser.langs),
readme: compose(toHTML.block, htmlParser.readme),
page: compose(toHTML.block, htmlParser.page),
inline: compose(toHTML.inline, htmlParser.page),
};

  • toHTML(args[0]) call asciidocToHTML

args[0] = toHTML(args[0]);

We need to add second argument for passing base dir.

type AbstractConvertOptions = {
  baseDir: string;
};
function compose(toHTML, fn) {
    return function WRAP_TO_HTML(content: string, options: AbstractConvertOptions) {
        const args = _.toArray(arguments);
        args[0] = toHTML(content, options);
        return fn.apply(null, args);
    };
}
  1. pass second args when call the WRAP_TO_HTML function

parseReadme(content: any) {
const readme = this.get("readme");
return Promise(readme(content));
}
parseSummary(content: any) {
const summary = this.get("summary");
return Promise(summary(content));
}
parseGlossary(content: any) {
const glossary = this.get("glossary");
return Promise(glossary(content));
}
preparePage(content: any) {
const page = this.get("page");
if (!page.prepare) {
return Promise(content);
}
return Promise(page.prepare(content));
}
parsePage(content: any) {
const page = this.get("page");
return Promise(page(content));
}
parseInline(content: any) {
const inline = this.get("inline");
return Promise(inline(content));
}
parseLanguages(content: any) {
const langs = this.get("langs");
return Promise(langs(content));
}
// TO TEXT
renderLanguages(content: any) {
const langs = this.get("langs");
return Promise(langs.toText(content));
}
renderSummary(content: any) {
const summary = this.get("summary");
return Promise(summary.toText(content));
}
renderGlossary(content: any) {
const glossary = this.get("glossary");
return Promise(glossary.toText(content));
}

This change will be breaking changes.

Related

commented

This issue is fixed in https://github.com/honkit/honkit/releases/tag/v5.0.0

please try it!