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

Adding support for rich display of Markdown cells #2346

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
273bbb3
Adding support for rich display of Markdown cells
NicholasWMRitchie Aug 3, 2020
e72d033
Fixing Markdown as "text/csv" and "text/plain"
NicholasWMRitchie Aug 4, 2020
a1d9619
Fix test error in Markdown to HTML in 32-bit systems
NicholasWMRitchie Aug 4, 2020
57a3b58
Fixing show and adding multi-codepoint tests
NicholasWMRitchie Aug 6, 2020
531e089
32 it is...
NicholasWMRitchie Aug 6, 2020
ea571e6
Use chomp to remove trailing '\n
NicholasWMRitchie Aug 7, 2020
c53598e
Fixing conflicts
NicholasWMRitchie Aug 24, 2020
5df96a6
Merge branch 'master' into master
bkamins Aug 24, 2020
a391912
Don't match on AbstractVector type parameter due to compiler crash (#…
quinnj Aug 24, 2020
5f5f121
Pulling df[i,j] out and optimizing ourshow.
NicholasWMRitchie Aug 25, 2020
73a9010
Merge branch 'master' of https://github.com/NicholasWMRitchie/DataFra…
NicholasWMRitchie Aug 25, 2020
3a85fbf
Formatting improvements
NicholasWMRitchie Aug 25, 2020
8928695
Additional formatting improvements
NicholasWMRitchie Aug 25, 2020
1a0fd3b
Update CONTRIBUTING.md
bkamins Aug 27, 2020
c1e38d4
Update CONTRIBUTING.md
bkamins Aug 27, 2020
be35852
Fixing triple-quoted strings in 1.0.X
NicholasWMRitchie Aug 27, 2020
7d4e5d0
Strip space in test case
NicholasWMRitchie Aug 27, 2020
2f5c2d3
Using @nalimilan suggestion
NicholasWMRitchie Aug 27, 2020
c05e3ea
Merge branch 'master' of https://github.com/NicholasWMRitchie/DataFra…
NicholasWMRitchie Aug 27, 2020
b90696d
Improving LaTeX output appearance, NEWS.md entry
NicholasWMRitchie Aug 28, 2020
606f3eb
Moved NEWS.md item to "Other relevant changes" section.
NicholasWMRitchie Aug 28, 2020
174d632
Correct NEWS.md item on rich display support
NicholasWMRitchie Aug 28, 2020
5414031
Adding support for rich display of Markdown cells
NicholasWMRitchie Aug 3, 2020
17b6e1b
Fixing Markdown as "text/csv" and "text/plain"
NicholasWMRitchie Aug 4, 2020
7a8c0de
Fix test error in Markdown to HTML in 32-bit systems
NicholasWMRitchie Aug 4, 2020
c112ef4
Fixing show and adding multi-codepoint tests
NicholasWMRitchie Aug 6, 2020
8a04964
32 it is...
NicholasWMRitchie Aug 6, 2020
9fbe264
Use chomp to remove trailing '\n
NicholasWMRitchie Aug 7, 2020
43a047c
Fixing conflicts
NicholasWMRitchie Aug 24, 2020
8ff0ff0
Pulling df[i,j] out and optimizing ourshow.
NicholasWMRitchie Aug 25, 2020
e67308e
Formatting improvements
NicholasWMRitchie Aug 25, 2020
ab4209c
Additional formatting improvements
NicholasWMRitchie Aug 25, 2020
4993be3
Fixing triple-quoted strings in 1.0.X
NicholasWMRitchie Aug 27, 2020
feb0f5d
Strip space in test case
NicholasWMRitchie Aug 27, 2020
bbd5143
Using @nalimilan suggestion
NicholasWMRitchie Aug 27, 2020
088c894
Improving LaTeX output appearance, NEWS.md entry
NicholasWMRitchie Aug 28, 2020
6a2ed0d
Moved NEWS.md item to "Other relevant changes" section.
NicholasWMRitchie Aug 28, 2020
b3866e5
Correct NEWS.md item on rich display support
NicholasWMRitchie Aug 28, 2020
0f6fb38
Merge remote-tracking branch 'origin/master'
NicholasWMRitchie Aug 28, 2020
1342b4b
Removing duplicate using lines
NicholasWMRitchie Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/abstractdataframe/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) =
ourshow(io, summary(x), styled=styled)
function ourshow(io::IO, x::Markdown.MD)
r = repr(x)
len = min(something(findfirst(c->c=='\n', r), length(r) + 1) - 1, 50)
len = min(length(r, 1, something(findfirst(c->c=='\n', r), lastindex(r)+1)-1), 50)
bkamins marked this conversation as resolved.
Show resolved Hide resolved
return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len))
bkamins marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using chars should give a slightly more efficient code:

Suggested change
return print(io, len < length(r) - 1 ? first(r, len)*"" : first(r, len))
return print(io, len < length(r) - 1 ? first(r, len)*'' : first(r, len))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

end

Expand Down
125 changes: 79 additions & 46 deletions test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,64 +204,97 @@ end

@testset "Markdown as text/plain and as text/csv" begin
df = DataFrame(
A=Int64[1,4,9,16,25],
A=Int64[1,4,9,16,25,36,49,64],
B = [
md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)",
md"``\frac{x^2}{x^2+y^2}``",
md"# Header",
md"This is *very*, **very**, very, very, very, very, very, very, very long line" ,
md""]
md"",
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" *
"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"*
" * ∞7∫αγ\n"*
" * ∞8∫αγ\n"*
" * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"*
" * γ∞1∫α\n"*
" * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
]
)
@test sprint(show, "text/plain", df) ==
"5×2 DataFrame\n" *
"│ Row │ A │ B │\n" *
"│ │ Int64 │ Markdown.MD │\n" *
"├─────┼───────┼─────────────────────────────────────────────────────┤\n" *
"│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │\n" *
"│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │\n" *
"│ 3 │ 9 │ # Header │\n" *
"│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │\n" *
"│ 5 │ 25 │ │"
@test sprint(show, "text/csv", df) ==
"\"A\",\"B\"\n"*
"1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"\n"*
"4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"\n"*
"9,\"# Header\"\n"*
"16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"\n"*
"25,\"\"\n"
@test sprint(show, "text/plain", df) == """
8×2 DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add 8-characters indentation. Same below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still applies.

│ Row │ A │ B │
│ │ Int64 │ Markdown.MD │
├─────┼───────┼─────────────────────────────────────────────────────┤
│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │
│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │
│ 3 │ 9 │ # Header │
│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │
│ 5 │ 25 │ │
│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │
│ 7 │ 49 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ… │
│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │"""

@test sprint(show, "text/csv", df) == """
\"A\",\"B\"
1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"
4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"
9,\"# Header\"
16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"
25,\"\"
36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\"
49,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\\n\\n * ∞7∫αγ\\n * ∞8∫αγ\\n * ∞9∫αγ∞0∫α\\n\\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\"
64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\"
"""
end

@testset "Markdown as HTML" begin
df = DataFrame(
A=Int64[1,4,9,16,25],
B = [
md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)",
md"``\frac{x^2}{x^2+y^2}``",
Markdown.parse("# Multi-line\nThis is a multi-line\n\n**Markdown**"),
md"This is *very*, **very**, very, very, very, very, very, very, very long line" ,
md""
]
A=Int64[1,4,9,16,25,36,49,64],
B = [
md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)",
md"``\frac{x^2}{x^2+y^2}``",
md"# Header",
md"This is *very*, **very**, very, very, very, very, very, very, very long line" ,
md"",
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" *
"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"*
" * ∞7∫αγ\n"*
" * ∞8∫αγ\n"*
" * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"*
" * γ∞1∫α\n"*
" * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"),
]
)
@test sprint(show,"text/html",df) ==
"<table class=\"data-frame\"><thead>"*
"<tr><th></th><th>A</th><th>B</th></tr>" *
"<tr><th></th><th>Int64</th><th>MD…</th></tr></thead>" *
"<tbody><p>5 rows × 2 columns</p>" *
"<tr><th>1</th><td>1</td><td>" *
"<div class=\"markdown\"><p><a href=\"http://juliadata.github.io/DataFrames.jl\">DataFrames.jl</a></p>\n</div>" *
"</td></tr>" *
"<tr><th>2</th><td>4</td><td>" *
"<div class=\"markdown\"><p>&#36;\\frac&#123;x^2&#125;&#123;x^2&#43;y^2&#125;&#36;</p>\n</div>" *
"</td></tr>" *
"<tr><th>3</th><td>9</td><td><div class=\"markdown\"><h1>Multi-line</h1>\n" *
"<p>This is a multi-line</p>\n" *
"<p><strong>Markdown</strong></p>\n" *
"</div></td></tr>" *
"<tr><th>4</th><td>16</td><td>" *
"<div class=\"markdown\"><p>This is <em>very</em>, <strong>very</strong>, very, very, very," *
" very, very, very, very long line</p>\n" *
"</div></td></tr>" *
"<tr><th>5</th><td>25</td><td><div class=\"markdown\"></div></td></tr></tbody></table>"
"<table class=\"data-frame\"><thead>" *
"<tr><th></th><th>A</th><th>B</th></tr>" *
"<tr><th></th><th>Int64</th><th>MD…</th></tr>" *
"</thead>" *
"<tbody>" * "<p>8 rows × 2 columns</p>" *
"<tr><th>1</th><td>1</td><td><div class=\"markdown\">" *
"<p><a href=\"http://juliadata.github.io/DataFrames.jl\">DataFrames.jl</a></p>\n</div></td></tr>" *
"<tr><th>2</th><td>4</td><td><div class=\"markdown\"><p>&#36;\\frac&#123;x^2&#125;&#123;x^2&#43;y^2&#125;&#36;</p>\n</div></td></tr>" *
"<tr><th>3</th><td>9</td><td><div class=\"markdown\"><h1>Header</h1>\n</div></td></tr>" *
"<tr><th>4</th><td>16</td><td><div class=\"markdown\">" *
"<p>This is <em>very</em>, <strong>very</strong>, very, very, very, very, very, very, very long line</p>\n" *
"</div></td></tr>" *
"<tr><th>5</th><td>25</td><td><div class=\"markdown\"></div></td></tr>" *
"<tr><th>6</th><td>36</td><td><div class=\"markdown\">" *
"<p>∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0</p>\n" *
"</div></td></tr>" *
"<tr><th>7</th><td>49</td><td><div class=\"markdown\">" *
"<p>∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ</p>\n<ul>\n<li><p>∞7∫αγ</p>\n</li>\n<li><p>∞8∫αγ</p>\n</li>\n<li><p>∞9∫αγ∞0∫α</p>\n</li>\n</ul>\n<p>γ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0</p>\n" *
"</div></td></tr>" *
"<tr><th>8</th><td>64</td><td><div class=\"markdown\">" *
"<p>∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α</p>" *
"\n<ul>\n" *
"<li><p>γ∞1∫α</p>\n</li>\n" *
"<li><p>γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0</p>\n</li>\n" *
"</ul>\n" * "</div></td></tr></tbody></table>"
end

@testset "empty data frame and DataFrameRow" begin
Expand Down