-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to wrap embedded video in a div
Set environment variable VIDEO_WRAPPER_CSS_CLASS="your-css-class" and the iframe will be embeded in a div with the provided class.
- Loading branch information
1 parent
887ff4e
commit 04b071d
Showing
4 changed files
with
36 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module WrapperElement where | ||
|
||
import qualified Data.Text.Lazy as LT | ||
|
||
data WrapperElement = DivWithClass String | NoWrapper | ||
|
||
wrapperElementFromMaybeString :: Maybe String -> WrapperElement | ||
wrapperElementFromMaybeString Nothing = NoWrapper | ||
wrapperElementFromMaybeString (Just str) = DivWithClass str | ||
|
||
wrapWithElement :: WrapperElement -> LT.Text -> LT.Text | ||
wrapWithElement NoWrapper innerText = innerText | ||
wrapWithElement (DivWithClass cssClass) innerText = | ||
"<div class=\"" <> (LT.pack cssClass) <> "\">" <> innerText <> "</div>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
import Test.Hspec | ||
import Text.Pandoc.Definition (Format(..), Inline(..), Attr(), nullAttr) | ||
import WrapperElement (WrapperElement(..)) | ||
import Lib (inlineHtmlVideo) | ||
|
||
main :: IO () | ||
main = hspec $ do | ||
describe "inlneHTMLVideo" $ do | ||
it "returns Nothing for non-image tag" $ do | ||
inlineHtmlVideo Nothing (Str "hello") `shouldBe` (Nothing) | ||
inlineHtmlVideo Nothing NoWrapper (Str "hello") `shouldBe` (Nothing) | ||
it "returns Vimeo iframe for correctly formatted image tag" $ do | ||
inlineHtmlVideo Nothing (Image nullAttr [] ("vimeo:123", "")) | ||
inlineHtmlVideo Nothing NoWrapper (Image nullAttr [] ("vimeo:123", "")) | ||
`shouldBe` (Just $ | ||
RawInline (Format "html") | ||
"<iframe allowfullscreen mozallowfullscreen frameborder=\"0\" src=\"https://player.vimeo.com/video/123?title=0&amp;portrait=0&amp;badge=0\" webkitallowfullscreen></iframe>") | ||
it "uses provided default dimensions" $ do | ||
inlineHtmlVideo (Just (10, 20)) (Image nullAttr [] ("vimeo:123", "")) | ||
inlineHtmlVideo (Just (10, 20)) NoWrapper (Image nullAttr [] ("vimeo:123", "")) | ||
`shouldBe` (Just $ | ||
RawInline (Format "html") | ||
"<iframe height=\"20\" width=\"10\" allowfullscreen mozallowfullscreen frameborder=\"0\" src=\"https://player.vimeo.com/video/123?title=0&amp;portrait=0&amp;badge=0\" webkitallowfullscreen></iframe>") | ||
it "overrides default dimensions" $ do | ||
inlineHtmlVideo Nothing (Image nullAttr [(Str "40x50")] ("vimeo:123", "")) | ||
inlineHtmlVideo Nothing NoWrapper (Image nullAttr [(Str "40x50")] ("vimeo:123", "")) | ||
`shouldBe` (Just $ | ||
RawInline (Format "html") | ||
"<iframe height=\"50\" width=\"40\" allowfullscreen mozallowfullscreen frameborder=\"0\" src=\"https://player.vimeo.com/video/123?title=0&amp;portrait=0&amp;badge=0\" webkitallowfullscreen></iframe>") | ||
it "wraps it in a div" $ do | ||
inlineHtmlVideo Nothing (DivWithClass "class1 class2") (Image nullAttr [] ("vimeo:123", "")) | ||
`shouldBe` (Just $ | ||
RawInline (Format "html") | ||
"<div class=\"class1 class2\"><iframe allowfullscreen mozallowfullscreen frameborder=\"0\" src=\"https://player.vimeo.com/video/123?title=0&amp;portrait=0&amp;badge=0\" webkitallowfullscreen></iframe></div>") | ||
it "doesn't wrap when no video" $ do | ||
inlineHtmlVideo Nothing (DivWithClass "testclass") (Str "hello") `shouldBe` (Nothing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters