In attempting to use the spec-pub GitHub action to validate PRs and Push actions, I found that it failed to validate the file due to what seems to be failure to load files from the local directory using data-include. I reproduced this using respec2html using the following:
respec2html --src index.html --out /tmp/foo.html
The relevant lines from index.html are:
<div class="informative hidden">
<!-- Terms included for referencability, but not displayed -->
<div data-include="common/terms.html"></div>
<div data-include="common/algorithm-terms.html"></div>
</div>
(By the way, it would be useful if --help or --version gave some ReSpec version info).
What happened (e.g., it crashed)?:
It failed with the following (abbreviated) output:
馃挜 ReSpec error: data-include failed for element: [object HTMLDivElement] TypeError: Failed to fetch
馃挜 ReSpec error: `data-include` failed: `common/terms.html` (Failed to fetch). See console for details.
馃挜 ReSpec error: data-include failed for element: [object HTMLDivElement] TypeError: Failed to fetch
馃挜 ReSpec error: `data-include` failed: `common/algorithm-terms.html` (Failed to fetch). See console for details.
I suspect that this is for the same reason that I need to run a local HTTP server for local development in the browser. However, the sand-box reasons for a browser to not load off of the local filesystem seem different than those for an NPM script.
Expected behavior (e.g., it shouldn't crash):
Validates document including loading resources.
Optional, steps to reproduce:
respec2html --src index.html --out /tmp/foo.html or similar.@marcoscaceres should we include a simple static server in respec2html?
I plan to run the server in spec-prod GitHub action, but might be worth adding it in ReSpec itself?
~Edit: Concern: Running a server in respec2html would mean services like spec-generator that call toHTML() often will end up creating lots of servers. Can be solved with config of course.~ Irrelevant as spec-generator uses toHTML() method but we're adding server to CLI.
Either way, need to fix docs for data-include
services like spec-generator that call toHTML() often will end up creating lots of servers
Also, it may be that once we get enough adoption of the github action, we don't need the spec-generator anymore.
Hmm.... I could go either way on this. Spinning up a local server and killing it after outputting the spec should be cheap.
I'd just like to have the ability to use data-include for relative files. I'm not sure why this should involve spinning up an HTTP server to access a file-relative resource, but the general case for data-include could be any URL; i just don't know how often that is actually used in specs. For my specs, the included files are always in a local directory. Perhaps your consideration is that the _correct_ way to do this is using an HTTP server.
It would be unfortunate if you decided to not support data-include for respec2html at all.
To clarify, respec2html does support data-include. It's just the browser doesn't want to fetch() URLs with file:// protocol (browsers treat it as a CORS failure (screenshot from Chrome devtools)).
Using data-include fairly common, so we're adding a --localhost flag to respec2html in https://github.com/w3c/respec/pull/3340.
Then following will be equivalent:
respec2html -s input.html --localhost
# same as:
python3 -m http.server # or some other static server
respec2html -s http://localhost:8080/input.html
Is there a way to specify the --localhost option when using the w3c/spec-prod@v1 GitHub Action? I get a timeout without it. Not presently documented.
Not v1, but w3c/spec-prod@v2 runs a local server without requiring any configuration.
Thanks, of course I didn't think about updating the version 馃う
Will close with #3340
Closed by #3340
@gkellogg, if you want to take it for a spin:
respec2html --localhost index.html
Let us know how you go!
@marcoscaceres Looks good! Thanks for adding this (and --version). The w3c/spec-prod@v2 action works great too.
Most helpful comment
@marcoscaceres Looks good! Thanks for adding this (and
--version). Thew3c/spec-prod@v2action works great too.