Skip to content

Commit 828082f

Browse files
Add width argument to Documenter (#35)
* Add width argument to Documenter * Fix Asciinema player window by width * Update src/runner.jl * Fix when `kwargs` is `nothing` * Add docs for `width` --------- Co-authored-by: Eric Hanson <[email protected]>
1 parent 579da86 commit 828082f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

docs/src/documenter_usage.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,38 @@ Delay of 1:
172172
3
173173
```
174174

175+
### Window size
176+
177+
The size of the window can be set with `height` and `width`.
178+
179+
````markdown
180+
```@cast
181+
println("="^80)
182+
```
183+
````
184+
185+
```@cast; hide_inputs=true
186+
println("="^80)
187+
```
188+
189+
````markdown
190+
```@cast; width=50, height=10
191+
println("="^80)
192+
```
193+
````
194+
195+
```@cast; width=50, height=10, hide_inputs=true
196+
println("="^80)
197+
```
198+
175199
### All supported options in `@cast` Documenter blocks
176200

177201
* `hide_inputs::Bool=false`. Whether or not to hide the `@repl`-style inputs before the animated gif.
178202
* `allow_errors::Bool=false`. Whether or not the Documenter build should fail if exceptions are encountered during execution of the `@cast` block.
179203
* `delay::Float64=0.25`. The amount of delay between line executions (to emulate typing time).
180204
* `loop::Union{Int,Bool}=false`. Set to `true` for infinite looping, or an integer to loop a fixed number of times.
181205
* `height::Int`. Heuristically determined by default. Set to an integer to specify the number of lines.
206+
* `width::Int`. Set to `80` by default. Set to an integer to specify the number of columns.
182207

183208
### Reference docs
184209

src/Asciicast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function Base.show(io::IO, ::MIME"juliavscode/html", cast::Cast)
153153
end
154154

155155
function show_html(io::IO, cast::Cast)
156-
base64_str = base64encode(collect_bytes(cast))
156+
base64_str = base64encode(collect_bytes(cast))
157157
name = uuid4()
158158
# Note: the extra div with `margin` is me trying to make the asciinema player
159159
# have a little space around it, so it looks better in documenter pages etc.
@@ -164,7 +164,7 @@ function show_html(io::IO, cast::Cast)
164164
<script>
165165
AsciinemaPlayer.create(
166166
'data:text/plain;base64,$(base64_str)',
167-
document.getElementById('$(name)'), {autoPlay: true, fit: false, loop: $(cast.loop)}
167+
document.getElementById('$(name)'), {autoPlay: true, fit: "width", loop: $(cast.loop)}
168168
);
169169
</script>
170170
</div>

src/runner.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function Selectors.runner(::Type{CastBlocks}, node, page, doc)
3232
allow_errors = false
3333
delay = 0.25
3434
height = nothing
35+
width = nothing
3536
loop = false
3637
if kwargs !== nothing
3738
# ansicolor
@@ -58,6 +59,14 @@ function Selectors.runner(::Type{CastBlocks}, node, page, doc)
5859
height = parse(Int, matched[1])
5960
end
6061

62+
# width
63+
matched = match(r"\bwidth\s*=\s*([0-9]+)", kwargs)
64+
if matched !== nothing
65+
width = parse(Int, matched[1])
66+
else
67+
width = nothing
68+
end
69+
6170
# loop
6271
# bool:
6372
matched = match(r"\bloop\s*=\s*(true|false)\b", kwargs)
@@ -91,7 +100,8 @@ function Selectors.runner(::Type{CastBlocks}, node, page, doc)
91100

92101
# If `height` isn't provided, we guess the number of lines:
93102
height = something(height, min(n_lines * 2, 24))
94-
cast = Cast(IOBuffer(), Header(; height, idle_time_limit=1); delay, loop)
103+
width = something(width, 80)
104+
cast = Cast(IOBuffer(), Header(; height, width, idle_time_limit=1); delay, loop)
95105

96106
cast_from_string!(x.code, cast; doc, page, ansicolor, mod, multicodeblock, allow_errors, x)
97107

0 commit comments

Comments
 (0)