backend-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Language.Ltml.HTML.Common

Synopsis

Custom State Monad

type HtmlReaderState = ReaderStateMonad (Delayed (Html ())) Source #

The Reader Monad is used for local tracking (e.g. enumNestingLevel). The State Monad is used for global tracking (e.g. sectionIDs). The Delayed type is used for delaying the actual lookup of references in the GlobalState. This allows forward references, because at first a delayed object is build, which is then evaluated aterwards with the final GlobalState.

data GlobalState Source #

Constructors

GlobalState 

Fields

  • hasFlagged :: Bool

    Is set True at every (Flagged ...); used to determine if current Flagged has any Flagged children

  • currentSuperSectionID :: Int

    Tracks the current super-section number

  • currentSectionID :: Int

    Tracks the current section number

  • currentInsertedSectionID :: Int

    Tracks the current inserted section number

  • currentParagraphID :: Int

    Tracks the current paragraph number in the current section

  • currentSentenceID :: Int

    Tracks the current sentence number in the current paragraph

  • currentEnumItemID :: Int

    Tracks the current enum item number in the current enumeration

  • currentFootnoteID :: Int

    Tracks the id of the next footnote

  • usedFootnoteMap :: FootnoteMap

    Maps all used footnotes labels to their id as an Int as Html and their text as Delayed Html, since they can also include references; This map is build during rendering with entries from "footnoteMap" from ReaderState and an additional id; Note: This map is document-scoped. Thus, it is reset when entering the next document.

  • locallyUsedFootnotes :: FootnoteSet

    Holds a set of all footnotes that were used in the current section. When leaving a section, this is reset to the intial value. It is used to collect footnotes that should be rendered at the end of the current section (in ascending order of their footnote id).

  • labels :: [(Label, Html ())]

    Holds all labels and the Html element that should be displayed when this label is referenced

  • tableOfContents :: ToC

    Holds all entries for the table of contents as (Maybe key (e.g. § 1), title, HTML id as anchor link, category). The title is wrapped into Result. In case of an parse error this title will be set to an Error title. The Left constructor holds metadata for the Frontend, which is ignored when rendering the ToC.

  • mangledLabelName :: Text

    Mangled prefix name for generating new label names that do not exist in source language

  • mangledLabelID :: Int

    Mangled postfix ID which is incremented and added to mangledLabelName to create unique htmlID

  • enumStyles :: EnumStyleMap

    Maps EnumFormats to their css class name which implements the fitting Counter

  • mangledEnumCounterName :: Text

    Holds prefix for generating new css class names for enum counter styles

  • mangledEnumCounterID :: Int

    Holds postfix id which makes enum counter class name unique

  • exportSections :: [(Text, Delayed Text, Delayed (Html ()))]

    Collects all (non-super) sections as their their htmlID, their Html and their title

  • documentFallbackTitle :: Fallback NavTocHeading

    Holds a fallback ToC title to send to the Frontend, if parsing the main Document failes. This is set by the DocumentContainer.

  • mainDocumentTitleHtml :: Delayed (Html ())

    Styled title of the main Document for building exported sections

  • mainDocumentTitle :: Delayed Text

    Raw title of the main Document for building HTML headers

  • hasErrors :: Bool

    True if any error occured while parsing; Note: "soft" errors like undefined labels are not catched

data ReaderState Source #

Constructors

ReaderState 

Fields

SectionID Functions

incSectionID :: ReaderT r (State GlobalState) () Source #

Increments currentSectionID in GlobalState

incInsertedSectionID :: ReaderT r (State GlobalState) () Source #

Increments currentInsertedSectionID in GlobalState

resetInsertedSectionID :: ReaderT r (State GlobalState) () Source #

Reset currentInsertedSectionID to initial value

incSuperSectionID :: ReaderT r (State GlobalState) () Source #

Increments currentSuperSectionID in GlobalState

Footnotes

type FootnoteMap = [(Label, (Int, Html (), Delayed (Html ())))] Source #

Maps Label to (ID, Text) as int and (delayed) html

convertLabelMap :: FootnoteMap -> [(Label, Html ())] Source #

Converts FootnoteMap to Label Map used for "normal" references

addUsedFootnotes Source #

Arguments

:: GlobalState

Base State

-> GlobalState

Add State

-> GlobalState 

Adds used footnotes of base state to add state (appends at the front)

type FootnoteSet = Set NumLabel Source #

Set of footnote labels with their respective footnote id

newtype NumLabel Source #

Used for sorted insertion into the set of footnotes; The Labels must be sorted by their footnote id

Constructors

NumLabel 

Fields

Instances

Instances details
Eq NumLabel Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Ord NumLabel Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Table of Contents

type ToC = DList (Either PhantomTocEntry TocEntry) Source #

The ToC uses a difference list to get constant time appending at the end, which has no speed draw backs, since the list is evaluated only ones when building the ToC Html at the end of rendering.

type TocEntry = (Maybe (Html ()), Result (Delayed (Html ())), Text, TocCategory) Source #

data TocCategory Source #

Constructors

SomeSection 
Other 

addTocEntry :: Maybe (Html ()) -> Result (Delayed (Html ())) -> Maybe Label -> TocCategory -> ReaderStateMonad Text Source #

Add entry to table of contents with: key Html (e.g. § 1), title Html and html anchor link id; If Label is present uses it as the anchor link id, otherwise it creates a new mangled label name; the used label name is returned;

addPhantomTocEntry :: Result (Html ()) -> ReaderStateMonad () Source #

Adds a phantom entry into the table of contents, which is ignored when rendering. Its only purpose is to tell the frontend if a parse error occured in this segment. This is only meant to be used for segments that do not have a normal Toc entry, like SimpleSections.

type PhantomTocEntry = (Maybe (Html ()), Result (Html ())) Source #

Toc Entry that only exists to send info to the Frontend; It is ignored when rendering a ToC

type RenderedTocEntry = (Maybe ByteString, Result ByteString) Source #

Type of exported ToC Entries (especially for Frontend); Result signals if the generated title was parsed successfully or not

data Result a Source #

Constructors

Success a 
Error a 

Instances

Instances details
Functor Result Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

fmap :: (a -> b) -> Result a -> Result b #

(<$) :: a -> Result b -> Result a #

FromJSON a => FromJSON (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

parseJSON :: Value -> Parser (Result a)

parseJSONList :: Value -> Parser [Result a]

omittedField :: Maybe (Result a)

ToJSON a => ToJSON (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

toJSON :: Result a -> Value

toEncoding :: Result a -> Encoding

toJSONList :: [Result a] -> Value

toEncodingList :: [Result a] -> Encoding

omitField :: Result a -> Bool

Generic (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Associated Types

type Rep (Result a) 
Instance details

Defined in Language.Ltml.HTML.Common

type Rep (Result a) = D1 ('MetaData "Result" "Language.Ltml.HTML.Common" "backend-0.1.0.0-2H73EnUlGVcEtlIi2XNQz3" 'False) (C1 ('MetaCons "Success" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Error" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

from :: Result a -> Rep (Result a) x #

to :: Rep (Result a) x -> Result a #

Show a => Show (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

showsPrec :: Int -> Result a -> ShowS #

show :: Result a -> String #

showList :: [Result a] -> ShowS #

ToSchema a => ToSchema (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

declareNamedSchema :: Proxy (Result a) -> Declare (Definitions Schema) NamedSchema

type Rep (Result a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

type Rep (Result a) = D1 ('MetaData "Result" "Language.Ltml.HTML.Common" "backend-0.1.0.0-2H73EnUlGVcEtlIi2XNQz3" 'False) (C1 ('MetaCons "Success" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Error" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

result :: (a -> b) -> (a -> b) -> Result a -> b Source #

Takes a Result a, a success function and an error function. Applies one of the two functions depending on the Result constructor.

Enum Styles

type EnumStyleMap = [(EnumFormat, Text)] Source #

Maps EnumFormat to css class name which implements the counter: Is used for reusing already existing classes, if the same EnumFormat occurs again

Labels

type LabelWrapper = Label -> Html () -> Html () Source #

Type of function thats used to wrap Label information around Html; e.g. for adding anchor links

anchorLink :: LabelWrapper Source #

Converts Label into href = "#<label"> for jumping to a HTML id

pageLink Source #

Arguments

:: FilePath

Path prefix

-> TocEntryWrapper 

Converts Label into href = "<path/label.html"> for jumping to another page

mainPageAnchorLink :: FilePath -> LabelWrapper Source #

Converts Label into href = "<path#label"> for jumping to another pages anchor

collectExportSection :: Text -> Delayed Text -> Delayed (Html ()) -> ReaderStateMonad () Source #

Adds a Section with htmlId and HTML title to GlobalState

exportLink :: FilePath -> LabelWrapper Source #

Builds a link with labelPath, prefix "Zur Einzelansicht" and adds some vertical spacing

setHasErrors :: ReaderStateMonad () Source #

Sets the hasErrors flag to True

Delayed data type

data Delayed a Source #

Constructors

Now a 
Later (GlobalState -> a) 

Instances

Instances details
Applicative Delayed Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

pure :: a -> Delayed a #

(<*>) :: Delayed (a -> b) -> Delayed a -> Delayed b #

liftA2 :: (a -> b -> c) -> Delayed a -> Delayed b -> Delayed c #

(*>) :: Delayed a -> Delayed b -> Delayed b #

(<*) :: Delayed a -> Delayed b -> Delayed a #

Functor Delayed Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

fmap :: (a -> b) -> Delayed a -> Delayed b #

(<$) :: a -> Delayed b -> Delayed a #

Monad Delayed Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

(>>=) :: Delayed a -> (a -> Delayed b) -> Delayed b #

(>>) :: Delayed a -> Delayed b -> Delayed b #

return :: a -> Delayed a #

Monoid a => Monoid (Delayed a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

mempty :: Delayed a #

mappend :: Delayed a -> Delayed a -> Delayed a #

mconcat :: [Delayed a] -> Delayed a #

Semigroup a => Semigroup (Delayed a) Source # 
Instance details

Defined in Language.Ltml.HTML.Common

Methods

(<>) :: Delayed a -> Delayed a -> Delayed a #

sconcat :: NonEmpty (Delayed a) -> Delayed a #

stimes :: Integral b => b -> Delayed a -> Delayed a #