Core.hs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. module Text.Ptolemy.Core where
  2. import Data.Text (Text)
  3. import Data.Map.Strict (Map)
  4. import Data.Vector (Vector)
  5. type Reader = Text -> Either String Ptolemy
  6. type Writer = Ptolemy -> Text
  7. data Ptolemy = Ptolemy
  8. { meta :: Maybe Meta
  9. , document :: Document
  10. } deriving (Eq, Show, Read, Ord)
  11. data Meta = Meta { fromMeta :: Map Text MetaValue }
  12. deriving (Eq, Show, Read, Ord)
  13. data MetaValue = MetaValue
  14. deriving (Eq, Show, Read, Ord)
  15. type Document = Vector Block
  16. type DocumentList = Vector Document
  17. type Chunk = Vector Inline
  18. newtype PtolemyError = PtolemyError { ptolemyErrorMessage :: String }
  19. deriving (Eq, Show)
  20. vec :: [a] -> Vector a
  21. vec = V.fromList
  22. data Block
  23. = Plain Chunk
  24. | Para Chunk
  25. | CodeBlock Attr Text
  26. | RawBlock Format Text
  27. | BlockQuote Document
  28. | OrderedList ListAttributes DocumentList
  29. | BulletList DocumentList
  30. | DefinitionList (Vector Definition)
  31. | Header Int Attr Chunk
  32. | HorizontalRule
  33. -- | Table ???
  34. | Div Attr Document
  35. | Null
  36. deriving (Eq, Show, Read, Ord)
  37. data Definition = Definition
  38. { dfTerm :: Chunk
  39. , dfDefinition :: DocumentList
  40. } deriving (Eq, Show, Read, Ord)
  41. data Inline
  42. = Str Text
  43. | Emph Chunk
  44. | Strong Chunk
  45. | Strikeout Chunk
  46. | Superscript Chunk
  47. | Subscript Chunk
  48. | SmallCaps Chunk
  49. | Quoted QuoteType Chunk
  50. | Cite (Vector Citation) Chunk
  51. | Code Attr Text
  52. | Space
  53. | SoftBreak
  54. | LineBreak
  55. | Math MathType Text
  56. | RawInline Format Text
  57. | Link Attr Chunk Target
  58. | Image Attr Chunk Target
  59. | Note Document
  60. | Span Attr Chunk
  61. deriving (Eq, Show, Read, Ord)
  62. data Attr = Attr
  63. { attrIdentifier :: Text
  64. , attrClasses :: Vector Text
  65. , attrProps :: Vector (Text, Text)
  66. } deriving (Eq, Show, Read, Ord)
  67. emptyAttr :: Attr
  68. emptyAttr = Attr
  69. { attrIdentifier = ""
  70. , attrClasses = vec []
  71. , attrProps = vec []
  72. }
  73. data ListAttributes = ListAttributes
  74. { laWhatever :: Int -- XXX What is this field for?
  75. , laNumberStyle :: ListNumberStyle
  76. , laNumberDelim :: ListNumberDelim
  77. } deriving (Eq, Show, Read, Ord)
  78. data Citation = Citation
  79. { ciId :: Text
  80. , ciPrefix :: Chunk
  81. , ciSuffix :: Chunk
  82. , ciMode :: CitationMode
  83. , ciNoteNum :: Int
  84. , ciHash :: Int
  85. } deriving (Eq, Show, Read, Ord)
  86. data CitationMode
  87. = AuthorInText
  88. | SuppressAuthor
  89. | NormalCitation
  90. deriving (Eq, Show, Read, Ord)
  91. data ListNumberStyle
  92. = DefaultStyle
  93. | Example
  94. | Decimal
  95. | LowerRoman
  96. | UpperRoman
  97. | LowerAlpha
  98. | UpperAlpha
  99. deriving (Eq, Show, Read, Ord)
  100. data ListNumberDelim
  101. = DefaultDelim
  102. | Period
  103. | OneParen
  104. | TwoParens
  105. deriving (Eq, Show, Read, Ord)
  106. data QuoteType = SingleQuote | DoubleQuote
  107. deriving (Eq, Show, Read, Ord)
  108. data MathType = DisplayMath | InlineMath
  109. deriving (Eq, Show, Read, Ord)
  110. newtype Format = Format { fromFormat :: Text }
  111. deriving (Eq, Show, Read, Ord)
  112. data Target = Target
  113. { tgtURL :: Text
  114. , tgtTitle :: Text
  115. } deriving (Eq, Show, Read, Ord)