diff --git a/src/Lib.hs b/src/Lib.hs index 5685819..8baec97 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -17,16 +17,17 @@ import Text.Pandoc.Walk (query) import Data.Maybe (fromMaybe, mapMaybe) import System.Environment (lookupEnv) import Control.Applicative ((<|>)) +import WrapperElement (WrapperElement(..), wrapWithElement, wrapperElementFromMaybeString) extractDimensions :: [Inline] -> Maybe Dimensions extractDimensions = fmap fst <$> uncons . mapMaybe (parseDimensions . query (\(Str s) -> s)) -inlineHtmlVideo :: Maybe Dimensions -> Inline -> Maybe Inline -inlineHtmlVideo defaultDimensions (Image _ inlines (url, _)) = - rawHtml . renderVideoEmbed . (`Video` dimensions) <$> parseVideoId url +inlineHtmlVideo :: Maybe Dimensions -> WrapperElement -> Inline -> Maybe Inline +inlineHtmlVideo defaultDimensions wrapperEl (Image _ inlines (url, _)) = + rawHtml . wrapWithElement wrapperEl . renderVideoEmbed . (`Video` dimensions) <$> parseVideoId url where rawHtml = RawInline (Format "html") . LT.unpack dimensions = extractDimensions inlines <|> defaultDimensions -inlineHtmlVideo _ _ = Nothing +inlineHtmlVideo _ _ _ = Nothing onFormat :: Format -> (a -> Maybe a) -> Maybe Format -> a -> a onFormat format f maybeFormat x @@ -36,4 +37,5 @@ onFormat format f maybeFormat x process :: IO () process = do defaultDimensions <- lookupEnv "VIDEO_DIMENSIONS" - toJSONFilter $ onFormat (Format "html") (inlineHtmlVideo (defaultDimensions >>= parseDimensions)) + wrapperElementStr <- lookupEnv "VIDEO_WRAPPER_CSS_CLASS" + toJSONFilter $ onFormat (Format "html") (inlineHtmlVideo (defaultDimensions >>= parseDimensions) (wrapperElementFromMaybeString wrapperElementStr)) diff --git a/src/WrapperElement.hs b/src/WrapperElement.hs new file mode 100644 index 0000000..50f24fe --- /dev/null +++ b/src/WrapperElement.hs @@ -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 = + "