Core.hs 2.6 KB

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