Skip to content

Commit

Permalink
Merge pull request #11 from PumasAI/jk/svg-in-readme
Browse files Browse the repository at this point in the history
Switch back to svgs in readme, simplify ids to combat mismatches on CI
  • Loading branch information
jkrumbiegel authored May 4, 2024
2 parents 3e91b47 + fb6ddc8 commit 04aa322
Show file tree
Hide file tree
Showing 8 changed files with 1,852 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ table_one(
)
```

![](README_files/figure-commonmark/cell-3-output-1.png)
![](README_files/figure-commonmark/cell-3-output-1.svg)

``` julia
data = DataFrame(
Expand All @@ -62,7 +62,7 @@ listingtable(
)
```

![](README_files/figure-commonmark/cell-4-output-1.png)
![](README_files/figure-commonmark/cell-4-output-1.svg)

``` julia
categories = ["Deciduous", "Deciduous", "Evergreen", "Evergreen", "Evergreen"]
Expand All @@ -87,7 +87,7 @@ Table(hcat(
))
```

![](README_files/figure-commonmark/cell-5-output-1.png)
![](README_files/figure-commonmark/cell-5-output-1.svg)

## Comparison with PrettyTables.jl

Expand Down
Binary file removed README_files/figure-commonmark/cell-3-output-1.png
Binary file not shown.
607 changes: 607 additions & 0 deletions README_files/figure-commonmark/cell-3-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed README_files/figure-commonmark/cell-4-output-1.png
Binary file not shown.
682 changes: 682 additions & 0 deletions README_files/figure-commonmark/cell-4-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
541 changes: 541 additions & 0 deletions README_files/figure-commonmark/cell-5-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions _readme/README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using SummaryTables, DataFrames, Statistics, Typst_jll
Base.delete_method(only(methods(Base.show, (IO, MIME"text/html", SummaryTables.Table))))
function Base.show(io::IO, ::MIME"image/png", tbl::SummaryTables.Table)
function Base.show(io::IO, ::MIME"image/svg+xml", tbl::SummaryTables.Table)
mktempdir() do dir
input = joinpath(dir, "input.typ")
open(input, "w") do io
Expand All @@ -42,9 +42,25 @@ function Base.show(io::IO, ::MIME"image/png", tbl::SummaryTables.Table)
""")
show(io, MIME"text/typst"(), tbl)
end
output = joinpath(dir, "output.png")
output = joinpath(dir, "output.svg")
run(`$(typst()) compile $input $output`)
print(io, read(output, String))
str = read(output, String)
ids = Dict{String,Int}()
function simple_id(s)
string(get!(ids, s) do
length(ids)
end, base = 16)
end
# typst uses ids that are not stable across runs or OSes or something,
# also they're quite long so as we don't use inlined svg we just simplify them
# to the position at which they appear first
replace(io, str,
r"(?<=xlink:href=\"#).*?(?=\")" => simple_id,
r"(?<=id=\").*?(?=\")" => simple_id,
r"(?<=url\(#).*?(?=\))" => simple_id,
)
end
end
```
Expand Down

0 comments on commit 04aa322

Please sign in to comment.