Skip to content

Commit

Permalink
video shortcode: Handle partially-specified width, height, aspectrati…
Browse files Browse the repository at this point in the history
…o attributes in HTML format (#6835)

* handle partially-specified height+width+aspectRatio in HTML videos
* smoke test
* changelog
  • Loading branch information
cscheid authored Sep 14, 2023
1 parent f955128 commit 27783bd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Add support for `body-right` and `body-left` layouts for Website Table of Contents ([#3473](https://github.com/quarto-dev/quarto-cli/issues/3473))
- ([#6430](https://github.com/quarto-dev/quarto-cli/issues/6430)): Fix layout issue with banner style title block authors when `page-layout:
- ([#5955](https://github.com/quarto-dev/quarto-cli/issues/5955)): Correct HTML callout appearance when title isn't present.
- ([#6833](https://github.com/quarto-dev/quarto-cli/issues/6833)): Handle partially-specified aspect ratio, width, and height attributes in `video` shortcode.

## Appendix

Expand Down
14 changes: 14 additions & 0 deletions src/resources/extensions/quarto/video/video.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ end

function htmlVideo(src, height, width, title, start, aspectRatio)

-- https://github.com/quarto-dev/quarto-cli/issues/6833
-- handle partially-specified width, height, and aspectRatio
if aspectRatio then
local strs = splitString(aspectRatio, 'x')
wr = tonumber(strs[1])
hr = tonumber(strs[2])
local aspectRatioNum = wr / hr
if height and not width then
width = math.floor(height * aspectRatioNum + 0.5)
elseif width and not height then
height = math.floor(width / aspectRatioNum + 0.5)
end
end

local videoSnippetAndType = getSnippetFromBuilders(src, height, width, title, start)
local videoSnippet

Expand Down
29 changes: 29 additions & 0 deletions tests/docs/smoke-all/2023/09/14/6833.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: "Video Test"
_quarto:
tests:
html:
ensureHtmlElements:
-
- "div.v2 iframe[height=\"360\"]"
- "div.v3 iframe[width=\"640\"]"
- []
---

::: v1

{{< video https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ width="640" height="360" >}}

:::

::: v2

{{< video https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ width="640" aspect-ratio="16x9" >}}

:::

::: v3

{{< video https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ height="360" aspect-ratio="16x9" >}}

:::

0 comments on commit 27783bd

Please sign in to comment.