Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML serialization of dataset produces invalid html #91

Open
ufechner7 opened this issue Oct 3, 2022 · 3 comments
Open

HTML serialization of dataset produces invalid html #91

ufechner7 opened this issue Oct 3, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@ufechner7
Copy link

ufechner7 commented Oct 3, 2022

Example:

using InMemoryDatasets

const HTML_HEADER = """
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
"""
const HTML_FOOTER = """
</body>
</html>
"""

function save_summary(ds)
    fullname = "summary.html"
    file = open(fullname, "w")
    println(file, HTML_HEADER)
    show(file, "text/html", ds)
    println(file, HTML_FOOTER)
    close(file)
end

ds = Dataset(var1 = [1, 2, 3],
                var2 = [1.2, 0.5, 3.3],
                var3 = ["C1", "C2", "C3"])

save_summary(ds)

Content of the file summary.html after running this script:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<table class="data-set"><thead><tr><th></th><th>var1</th><th>var2</th><th>var3</th></tr><th></th><th>identity</th><th>identity</th><th>identity</th></tr><tr><th></th><th title="Union{Missing, Int64}">Int64?</th><th title="Union{Missing, Float64}">Float64?</th><th title="Union{Missing, String}">String?</th></tr></thead><tbody><p>3 rows × 3 columns</p><tr><th>1</th><td>1</td><td>1.2</td><td>C1</td></tr><tr><th>2</th><td>2</td><td>0.5</td><td>C2</td></tr><tr><th>3</th><td>3</td><td>3.3</td><td>C3</td></tr></tbody></table></body>
</html>

Checking if the file is correct using the program tidy:

ufechner@ubuntu:~/repos/Dataset2Html/data$ tidy -e summary.html 
line 8 column 89 - Warning: missing <tr>
line 8 column 328 - Warning: <p> isn't allowed in <tbody> elements
line 8 column 321 - Info: <tbody> previously mentioned
Info: Document content looks like HTML5
Tidy found 2 warnings and 0 errors!


About HTML Tidy: https://github.com/htacg/tidy-html5
Bug reports and comments: https://github.com/htacg/tidy-html5/issues
Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/
Latest HTML specification: http://dev.w3.org/html5/spec-author-view/
Validate your HTML documents: http://validator.w3.org/nu/
Lobby your company to join the W3C: http://www.w3.org/Consortium

This is not only a theoretical problems, this html fails to render with some renderers.

@sl-solution sl-solution added the bug Something isn't working label Oct 3, 2022
@sl-solution
Copy link
Owner

The first warning is a bug, and I am fixing it, however, for the second warning I need to learn how to fix it. Probably PrettyTables version 2 will fix it.

PS We will move the showing functionality to PrettyTables version 2 soon. The reason why we haven't move to the new version of the package yet is that the change will be breaking, thus a little more study would be a good idea.

@ufechner7
Copy link
Author

In case it helps, the program tidy fixes the output into this form:

<!DOCTYPE html>
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 for Linux version 5.2.0">
<title></title>
</head>
<body>
<p>3 rows × 3 columns</p>
<table class="data-set">
<thead>
<tr>
<th></th>
<th>var1</th>
<th>var2</th>
<th>var3</th>
</tr>
<tr>
<th></th>
<th>identity</th>
<th>identity</th>
<th>identity</th>
</tr>
<tr>
<th></th>
<th title="Union{Missing, Int64}">Int64?</th>
<th title="Union{Missing, Float64}">Float64?</th>
<th title="Union{Missing, String}">String?</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>1</td>
<td>1.2</td>
<td>C1</td>
</tr>
<tr>
<th>2</th>
<td>2</td>
<td>0.5</td>
<td>C2</td>
</tr>
<tr>
<th>3</th>
<td>3</td>
<td>3.3</td>
<td>C3</td>
</tr>
</tbody>
</table>
</body>
</html>

@sl-solution
Copy link
Owner

This is helpful. If I understand it correctly, it suggests putting the

..

out of table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants