-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Library for parsing, constructing, and printing BBCode -- -- This is a set of utilities for: Parsing BBCode into AST(providing -- related types), Building BBCode AST with simple DSL based on Semigroup -- and functions. Currently this library can only be used with a very -- specific BBCode dialect used on a resource I won't name. @package bbcode @version 0.1.0.2 -- | Usually you only need to import that module, which reexports most of -- the functionality. -- -- If you need lens definitions for types, import -- Text.BBCode.Lens -- -- If you need interface to parsing, see Text.BBCode.Parser module Text.BBCode -- | Newline -- --
-- nl == 'text' "\n" --nl :: BBCode -- | Horizontal line -- --
-- hr == 'ElVoid' 'HR' --hr :: BBCode -- | Line break -- --
-- br == 'ElVoid' 'BR' --br :: BBCode -- |
-- clear == 'ElVoid' 'Clear' --clear :: BBCode -- | Notice it is not a function, but a value. -- -- listEl represents "[*]" -- --
-- listEl == 'ElVoid' 'ListElement' --listEl :: BBCode -- |
-- text == 'ElText' --text :: Text -> BBCode -- | Wrap [BBCode] in ElDocument doc :: [BBCode] -> BBCode -- | intersperse list with nl and wrap it in -- ElDocument docNL :: [BBCode] -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. bold :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. italic :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. underline :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. strikethrough :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. indent :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. nfo :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. oneline :: BBCode -> BBCode -- | Code element contains plain text code :: Text -> BBCode -- | Preformatted element contains plain text pre :: Text -> BBCode -- | bold, italic, underline, and all the rest -- functions BBCode -> BBCode work the same way -- by wrapping argument in another element. box :: BBCode -> BBCode -- | Takes image URL image :: Text -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. quote :: BBCode -> BBCode -- | bold, italic, underline, and all the rest functions BBCode -- -> BBCode work the same way by wrapping argument in -- another element. spoiler :: BBCode -> BBCode -- | Each element of list is prepended with listElement, meaning -- you can't create list with contents but without elements -- --
-- >>> list [bold "10", italic "15"] -- ElSimple List (ElDocument [ElVoid ListElement,ElSimple Bold (ElText "10"),ElVoid ListElement,ElSimple Italic (ElText "15")]) --list :: [BBCode] -> BBCode -- | Like box but with alignment argument boxAlign :: BoxPosition -> BBCode -> BBCode -- | Like image but with alignment argument imageAlign :: ImagePosition -> Text -> BBCode -- | Named quote quoteNamed :: Text -> BBCode -> BBCode -- | Named spoiler spoilerNamed :: Text -> BBCode -> BBCode -- | Ordered list -- --
-- >>> listFlavor LatinUpper [bold "I am bald", boxAlign BoxRight "get boxxxed"] -- ElArg List "A" (ElDocument [ElVoid ListElement,ElSimple Bold (ElText "I am bald"),ElVoid ListElement,ElArg Box "right" (ElText "get boxxxed")]) --listFlavor :: Foldable t => ListFlavor -> t BBCode -> BBCode -- | Change color of inner BBCode First argument is either color name (e.g. -- blue) or hex color(e.g. #333 or #151515) color :: Text -> BBCode -> BBCode -- | Create a hyperlink -- -- first argument is expected to be valid URL url :: Text -> BBCode -> BBCode -- | Change font size of inner bbcode -- -- arg ∈ [10, 29] and arg is natural size :: Natural -> BBCode -> BBCode align :: AlignPosition -> BBCode -> BBCode -- | Change font of inner BBCode -- -- argument should be a valid font name font :: Text -> BBCode -> BBCode -- | BBCode AST data BBCode -- | Element that has neither closing part nor arguments -- -- ElVoid HR represents "[hr]" [ElVoid] :: El -> BBCode -- | Element that has closing part but no arguments -- -- ElSimple Bold (ElText "abc") represents -- "[b]abc[/b]" [ElSimple] :: El -> BBCode -> BBCode -- | Element that has closing part and exactly one argument -- -- ElArg Color "red" (ElText "I am red") -- represents "[color=red]I am red[/color]" [ElArg] :: El -> Text -> BBCode -> BBCode -- | Plain text -- -- ElText "I am text" represents "I am text"@ [ElText] :: Text -> BBCode -- | Just a list of BBCode elements, just as type signature says. -- -- ElDocument [ElSimple Bold (ElText -- "Bold not bald"), ElText "legit text"] represents -- "[b]Bold not bald[/b]legit text" [ElDocument] :: [BBCode] -> BBCode -- | Type of an element. BBCode declares three constructors for -- elements: ElVoid, ElSimple, ElArg. But El -- can be split into four cateogories: 1) void elements, 2) simple -- elements, 3) elements with optional argument, 4) element with one -- argument -- -- There is no enforcement of combining BBCode constuctors and -- El values, that means you can create ElSimple HR (ElText -- "smth") but that would make no sense. pretty would emit a -- runtime error if you try to pass such value. data El -- | void element HR :: El -- | void element BR :: El -- | void element Clear :: El -- | void element ListElement :: El -- | simple element Bold :: El -- | simple element Italic :: El -- | simple element Underline :: El -- | simple element Strikethrough :: El -- | simple element Indent :: El -- | simple element NFO :: El -- | simple element Oneline :: El -- | simple element Code :: El -- | simple element Preformatted :: El -- | element with optional argument Box :: El -- | element with optional argument Image :: El -- | element with optional argument Quote :: El -- | element with optional argument Spoiler :: El -- | element with optional argument List :: El -- | element with one argument Color :: El -- | element with one argument URL :: El -- | element with one argument Size :: El -- | element with one argument Align :: El -- | element with one argument Font :: El -- | Used for building BBCode safely. Instead of passing Text to -- builder functions, you pass values of types that implement -- IsArgument. Then toArgument is used to convert that -- value to Text. class IsArgument a toArgument :: IsArgument a => a -> Text -- | Argument to listFlavor data ListFlavor -- | Numeric 1, 2, 3,.. [Roman] :: ListFlavor -- | Arabic I, II, III,.. [ArabicUpper] :: ListFlavor -- | Arabic i, ii, iii,.. [ArabicLower] :: ListFlavor -- | Alphabetical A, B, C,.. [LatinUpper] :: ListFlavor -- | Alphabetical a, b, c,.. [LatinLower] :: ListFlavor -- | Argument to align data AlignPosition [AlignLeft] :: AlignPosition [AlignRight] :: AlignPosition [AlignCenter] :: AlignPosition [AlignJustify] :: AlignPosition -- | Argument to imageAlign data ImagePosition [ImageLeft] :: ImagePosition [ImageRight] :: ImagePosition -- | Argument to boxAlign data BoxPosition [BoxLeft] :: BoxPosition [BoxCenter] :: BoxPosition [BoxRight] :: BoxPosition -- | Serialize BBCode AST -- -- Parsing pretty x should give you x, but -- currently that rarely works mostly because of whitespaces. Whitespaces -- are appended when prettifying, but not stripped when parsing. This -- leads to redundant whitespaces in parsed AST -- -- Can cause error at runtime if unrepresentable element is passed -- --
-- >>> pretty $ ElSimple HR "abc" -- Prelude.undefined --pretty :: BBCode -> Text -- | Parse zero or more BBCode elements Doesn't necessarily return value -- wrapped in ElDocument, it returns (mempty :: -- BBCode) if it parses no elements, or just element if parses just -- one element. Otherwise it is ElDocument bbcode :: Parser BBCode -- | parseMaybe specialized for Parser runParserMaybeEnv :: ParsecT e s (Reader r) a -> r -> s -> Maybe a module Text.BBCode.Lens _ElArg :: Prism' BBCode (El, Text, BBCode) _ElDocument :: Prism' BBCode [BBCode] _ElSimple :: Prism' BBCode (El, BBCode) _ElText :: Prism' BBCode Text _ElVoid :: Prism' BBCode El _AlignCenter :: Prism' AlignPosition () _AlignJustify :: Prism' AlignPosition () _AlignLeft :: Prism' AlignPosition () _AlignRight :: Prism' AlignPosition () _ArabicLower :: Prism' ListFlavor () _ArabicUpper :: Prism' ListFlavor () _LatinLower :: Prism' ListFlavor () _LatinUpper :: Prism' ListFlavor () _Roman :: Prism' ListFlavor () _ImageLeft :: Prism' ImagePosition () _ImageRight :: Prism' ImagePosition () _Align :: Prism' El () _BR :: Prism' El () _Bold :: Prism' El () _Box :: Prism' El () _Clear :: Prism' El () _Code :: Prism' El () _Color :: Prism' El () _Font :: Prism' El () _HR :: Prism' El () _Image :: Prism' El () _Indent :: Prism' El () _Italic :: Prism' El () _List :: Prism' El () _ListElement :: Prism' El () _NFO :: Prism' El () _Oneline :: Prism' El () _Preformatted :: Prism' El () _Quote :: Prism' El () _Size :: Prism' El () _Spoiler :: Prism' El () _Strikethrough :: Prism' El () _URL :: Prism' El () _Underline :: Prism' El () module Text.BBCode.Parser -- | Parser with reader transformer inside. -- -- Reader environment contains current context for element. -- -- It is used for oneline because -- "[oneline][oneline][/oneline][/oneline]" should produce -- error. Same with nfo -- -- Also used by plaintext to end parsing on closing element of -- current environment. -- --
-- >>> parseTestEnv bbcode "[i]Bread[/b][/i]" -- ElSimple Italic (ElText "Bread[/b]") ---- -- Notice it parsed "[/b]". plaintext finishes parsing -- only on closing element that matches last parsed opening type Parser a = ParsecT Void Text (Reader [El]) a -- | runParser specialized for Parser runParserEnv :: ParsecT e s (Reader r) a -> r -> s -> Either (ParseErrorBundle s e) a -- | parseMaybe specialized for Parser runParserMaybeEnv :: ParsecT e s (Reader r) a -> r -> s -> Maybe a -- | parseTest specialized for Parser. Passes empty list to -- inner reader monad parseTestEnv :: Show a => Parser a -> Text -> IO () -- | All parsers used by bbcode and bbcode1 -- -- Keys are element names and values are associated element parsers. -- -- Values are lists because some elements have optional element. That -- means they are two separate parsers, e.g. Box element parsers -- are box (simple element) and boxAlign (element with -- parameter) parsers :: Map El [Parser BBCode] -- | Parse zero or more BBCode elements Doesn't necessarily return value -- wrapped in ElDocument, it returns (mempty :: -- BBCode) if it parses no elements, or just element if parses just -- one element. Otherwise it is ElDocument bbcode :: Parser BBCode -- | Similar to bbcode but parses one or more elements bbcode1 :: Parser BBCode hr :: Parser BBCode br :: Parser BBCode clear :: Parser BBCode bold :: Parser BBCode italic :: Parser BBCode underline :: Parser BBCode strikethrough :: Parser BBCode indent :: Parser BBCode nfo :: Parser BBCode oneline :: Parser BBCode everythingInElement :: El -> Parser BBCode code :: Parser BBCode preformatted :: Parser BBCode box :: Parser BBCode boxAlign :: Parser BBCode image :: Parser BBCode imageAlign :: Parser BBCode quote :: Parser BBCode quoteNamed :: Parser BBCode spoiler :: Parser BBCode spoilerNamed :: Parser BBCode listElement :: Parser BBCode list :: Parser BBCode listFlavor :: Parser BBCode colorName :: Parser BBCode colorHex :: Parser BBCode url :: Parser BBCode size :: Parser BBCode align :: Parser BBCode font :: Parser BBCode plaintext :: Parser BBCode