packages feed

pandocz-0.0.1: src/Text/Pandoc/Z/Combinators.hs

{-# OPTIONS_GHC -Wall #-}

module Text.Pandoc.Z.Combinators where

import Control.Lens
import Text.Pandoc.Z.Text
import Text.Pandoc.Z.Definition

-- | str :: HasText s => s -> Inline
str ::
  (HasText s, AsInline i) =>
  s
  -> i
str =
  review _Str . view text

-- | plainStr :: HasText s => s -> Block
plainStr ::
  (HasText s, AsBlock t) =>
  s
  -> t
plainStr =
  review _Plain . pure . str

-- | paraStr :: HasText s => s -> Block
paraStr ::
  (HasText s, AsBlock t) =>
  s
  -> t
paraStr =
  review _Para . pure . str

-- | attribute :: HasText s => s -> Attr
attribute ::
  (HasText s, HasAttr a, Monoid a) =>
  s
  -> a
attribute s =
  mempty & identifier .~ view text s

-- | span :: HasText s => s -> Span
span' ::
  (HasText s, Monoid a, HasAttr a) =>
  s
  -> a
span' s =
  mempty & attr .~ attribute s

-- code' :: (HasText s1, HasText s2) => s1 -> s2 -> Code
code' ::
  (HasAttr a, Monoid a, HasText a, HasText s1, HasText s2) =>
  s1
  -> s2
  -> a
code' s1 s2 =
  mempty & attr .~ attribute s1
         & text .~ view text s2

displayMath ::
  HasText s =>
  s
  -> Math
displayMath =
  Math DisplayMath . view text

inlineMath ::
  HasText s =>
  s
  -> Math
inlineMath =
  Math InlineMath . view text

-- | cellXY :: RowSpan -> ColSpan -> Cell
cellXY ::
  (Monoid a, HasRowSpan a, HasColSpan a) =>
  RowSpan
  -> ColSpan
  -> a
cellXY x y =
  mempty
  & rowSpan .~ x
  & colSpan .~ y

linkImage ::
  Iso'
    Link
    Image
linkImage =
  iso
    (\(Link a i t) -> Image a i t)
    (\(Image a i t) -> Link a i t)