carpentries / workbench

Repository for Discussions and Materials about The Carpentries Workbench
https://carpentries.github.io/workbench/
Creative Commons Attribution 4.0 International
17 stars 7 forks source link

Error: Arguments imply differing number of rows #29

Closed svenvanderburg closed 1 year ago

svenvanderburg commented 1 year ago

When building a website using this template, I get the following error message:

arguments imply differing number of rows: 842, 28
Section (div) tags for 02-preparing-data.md will not be labelledFALSE
── Validating Fenced Divs ──────────────────────────────────────────────────────
Error in data.frame(node = rep(seq_along(divs), lengths(divs)), div = unlist(divs,  : 
  arguments imply differing number of rows: 842, 28
Calls: <Anonymous> ... <Anonymous> -> label_div_tags -> make_div_pairs -> data.frame
In addition: Warning messages:
1: In lines[!fenced_divs] <- rep(get_linestart(nodes[!fenced_divs]),  :
  number of items to replace is not a multiple of replacement length
2: In lines[!fenced_divs] <- rep(get_linestart(nodes[!fenced_divs]),  :
  number of items to replace is not a multiple of replacement length
Execution halted
Error: Process completed with exit code 1.

See github action logs

Here is the file that I am trying to render. Locally it sometimes builds successfully, and sometimes I get the same error, I haven't figured out in which cases it is successful.

What could it be? And maybe it would be nice to add a more user-friendly error message.

svenvanderburg commented 1 year ago

Ah, I guess it is because I have html in my markdown files. I removed the html and now it works. Still I would suggest to improve the error-handling here. Something like: 'You have HTML in your markdown file, we currently do not support this'.

zkamvar commented 1 year ago

Thank you for the report (especially for including a copy of the error message and pointing to the permanent link to your episode :100:), @svenvanderburg!

This indeed is a bug as it is possible to include HTML in a lesson, but one catch with HTML blocks (especially for <div> blocks): blank lines stop the interpreter. I will create an issue in {pegboard} (where this originated) to see if I can provide a better error.

Solution

The solution is to remove the blank lines (288 and 292) in the <style> tag

Details of how this error occured

This is coming from {pegboard}, which uses the commonmark 0.29 spec (which is the foundation for pandoc markdown) for parsing documents. HTML blocks are allowed, but as stated in the spec, blank lines signal the end of a block (emphasis mine):

There are two reasons for disallowing [blank lines within HTML blocks] here. First, it removes the need to parse balanced tags, which is expensive and can require backtracking from the end of the document if no matching end tag is found. Second, it provides a very simple and flexible way of including Markdown content inside HTML tags: simply separate the Markdown from the HTML using blank lines [see example 157]...

... The main potential drawback is that one can no longer paste HTML blocks into Markdown documents with 100% reliability. However, in most cases this will work fine, because the blank lines in HTML are usually followed by HTML block tags. [see example 159] There are problems, however, if the inner tags are indented and separated by spaces, as then they will be interpreted as an indented code block [see example 160].

This was the situation your lesson found itself. As you can see in the HTML output of this preview, because of the blank line, the style block is parsed into three separate code blocks:

Output:
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
<p>Output:</p>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }
<pre><code>.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</code></pre>
</style>
<table border="1" class="dataframe">
svenvanderburg commented 1 year ago

OK, that clarifies! Thanks @zkamvar :pray:

zkamvar commented 1 year ago

I will close this because I assume it was fixed, but feel free to open if you feel otherwise.