forked from jgm/cmark-hs
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMarkGFM.hsc
682 lines (568 loc) · 25 KB
/
CMarkGFM.hsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
{-# LANGUAGE CPP, ForeignFunctionInterface, GeneralizedNewtypeDeriving,
DeriveGeneric, DeriveDataTypeable, FlexibleContexts #-}
module CMarkGFM (
commonmarkToHtml
, commonmarkToXml
, commonmarkToMan
, commonmarkToLaTeX
, commonmarkToNode
, nodeToHtml
, nodeToXml
, nodeToMan
, nodeToLaTeX
, nodeToCommonmark
, optSourcePos
, optHardBreaks
, optSmart
, optSafe
, optUnsafe
, optFootnotes
, extStrikethrough
, extTable
, extAutolink
, extTagfilter
, extTaskList
, Node(..)
, NodeType(..)
, PosInfo(..)
, DelimType(..)
, ListType(..)
, ListAttributes(..)
, Url
, Title
, Level
, Info
, TableCellAlignment(..)
, CMarkOption
, CMarkExtension
) where
import Foreign
import Foreign.C.Types
import Foreign.C.String (CString, withCString)
import qualified System.IO.Unsafe as Unsafe
import Data.Maybe (fromMaybe)
import GHC.Generics (Generic)
import Data.Data (Data)
import Data.Typeable (Typeable)
import Data.Text (Text, empty, snoc)
import qualified Data.Text.Foreign as TF
import Data.ByteString.Unsafe (unsafePackMallocCString)
import Data.Text.Encoding (decodeUtf8)
import Control.Applicative ((<$>), (<*>))
#include <cmark-gfm.h>
#include <cmark-gfm-core-extensions.h>
-- | Ensure core extensions are registered.
ensurePluginsRegistered :: IO ()
ensurePluginsRegistered = c_cmark_gfm_core_extensions_ensure_registered
-- | Frees a cmark linked list, produced by extsToLlist.
freeLlist :: LlistPtr a -> IO ()
freeLlist = c_cmark_llist_free c_cmark_mem
-- | Converts a list of resolved extension pointers to a single cmark
-- linked list, which can be passed to functions requiring a list of
-- extensions.
extsToLlist :: [ExtensionPtr] -> IO (LlistPtr ExtensionPtr)
extsToLlist [] = return nullPtr
extsToLlist (h:t) = do
t' <- extsToLlist t
c_cmark_llist_append c_cmark_mem t' (castPtr h)
-- | Resolves CMarkExtensions to pointers.
resolveExts :: [CMarkExtension] -> IO [ExtensionPtr]
resolveExts exts = do
ensurePluginsRegistered
mapM resolveExt exts
where resolveExt ext = do p <- withCString (unCMarkExtension ext) c_cmark_find_syntax_extension
if p == nullPtr then
fail $ "could not load extension " ++ unCMarkExtension ext
else
return p
-- | Convert CommonMark formatted text to Html, using cmark's
-- built-in renderer.
commonmarkToHtml :: [CMarkOption] -> [CMarkExtension] -> Text -> Text
commonmarkToHtml opts exts =
commonmarkToX render_html opts exts Nothing
where exts' = Unsafe.unsafePerformIO $ resolveExts exts
render_html n o _ = do
llist <- extsToLlist exts'
r <- c_cmark_render_html n o llist
freeLlist llist
return r
-- | Convert CommonMark formatted text to CommonMark XML, using cmark's
-- built-in renderer.
commonmarkToXml :: [CMarkOption] -> [CMarkExtension] -> Text -> Text
commonmarkToXml opts exts = commonmarkToX render_xml opts exts Nothing
where render_xml n o _ = c_cmark_render_xml n o
-- | Convert CommonMark formatted text to groff man, using cmark's
-- built-in renderer.
commonmarkToMan :: [CMarkOption] -> [CMarkExtension] -> Maybe Int -> Text -> Text
commonmarkToMan = commonmarkToX c_cmark_render_man
-- | Convert CommonMark formatted text to latex, using cmark's
-- built-in renderer.
commonmarkToLaTeX :: [CMarkOption] -> [CMarkExtension] -> Maybe Int -> Text -> Text
commonmarkToLaTeX = commonmarkToX c_cmark_render_latex
-- | Convert CommonMark formatted text to a structured 'Node' tree,
-- which can be transformed or rendered using Haskell code.
commonmarkToNode :: [CMarkOption] -> [CMarkExtension] -> Text -> Node
commonmarkToNode opts exts s = Unsafe.unsafePerformIO $ do
exts' <- resolveExts exts
parser <- c_cmark_parser_new (combineOptions opts)
mapM_ (c_cmark_parser_attach_syntax_extension parser) exts'
TF.withCStringLen s $! \(ptr, len) ->
c_cmark_parser_feed parser ptr len
nptr <- c_cmark_parser_finish parser
c_cmark_parser_free parser
fptr <- newForeignPtr c_cmark_node_free nptr
withForeignPtr fptr toNode
nodeToHtml :: [CMarkOption] -> [CMarkExtension] -> Node -> Text
nodeToHtml opts exts =
nodeToX render_html opts Nothing
where exts' = Unsafe.unsafePerformIO $ resolveExts exts
render_html n o _ = do
llist <- extsToLlist exts'
r <- c_cmark_render_html n o llist
freeLlist llist
return r
nodeToXml :: [CMarkOption] -> Node -> Text
nodeToXml opts = nodeToX render_xml opts Nothing
where render_xml n o _ = c_cmark_render_xml n o
nodeToMan :: [CMarkOption] -> Maybe Int -> Node -> Text
nodeToMan = nodeToX c_cmark_render_man
nodeToLaTeX :: [CMarkOption] -> Maybe Int -> Node -> Text
nodeToLaTeX = nodeToX c_cmark_render_latex
nodeToCommonmark :: [CMarkOption] -> Maybe Int -> Node -> Text
nodeToCommonmark = nodeToX c_cmark_render_commonmark
type Renderer = NodePtr -> CInt -> Int -> IO CString
nodeToX :: Renderer -> [CMarkOption] -> Maybe Int -> Node -> Text
nodeToX renderer opts mbWidth node = Unsafe.unsafePerformIO $ do
nptr <- fromNode node
fptr <- newForeignPtr c_cmark_node_free nptr
withForeignPtr fptr $ \ptr -> do
cstr <- renderer ptr (combineOptions opts) (fromMaybe 0 mbWidth)
decodeUtf8 <$> unsafePackMallocCString cstr
commonmarkToX :: Renderer
-> [CMarkOption]
-> [CMarkExtension]
-> Maybe Int
-> Text
-> Text
commonmarkToX renderer opts exts mbWidth s = Unsafe.unsafePerformIO $
TF.withCStringLen s $ \(ptr, len) -> do
let opts' = combineOptions opts
exts' <- resolveExts exts
parser <- c_cmark_parser_new opts'
mapM_ (c_cmark_parser_attach_syntax_extension parser) exts'
c_cmark_parser_feed parser ptr len
nptr <- c_cmark_parser_finish parser
c_cmark_parser_free parser
fptr <- newForeignPtr c_cmark_node_free nptr
withForeignPtr fptr $ \p -> do
str <- renderer p opts' (fromMaybe 0 mbWidth)
decodeUtf8 <$> unsafePackMallocCString str
data ParserPhantom
type ParserPtr = Ptr ParserPhantom
data NodePhantom
type NodePtr = Ptr NodePhantom
data LlistPhantom a
type LlistPtr a = Ptr (LlistPhantom a)
data MemPhantom
type MemPtr = Ptr MemPhantom
data ExtensionPhantom
type ExtensionPtr = Ptr ExtensionPhantom
data Node = Node (Maybe PosInfo) NodeType [Node]
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
data DelimType =
PERIOD_DELIM
| PAREN_DELIM
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
data ListType =
BULLET_LIST
| ORDERED_LIST
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
data ListAttributes = ListAttributes{
listType :: ListType
, listTight :: Bool
, listStart :: Int
, listDelim :: DelimType
} deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
type Url = Text
type Title = Text
type Level = Int
type Info = Text
type OnEnter = Text
type OnExit = Text
data TableCellAlignment = NoAlignment | LeftAligned | CenterAligned | RightAligned
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
data NodeType =
DOCUMENT
| THEMATIC_BREAK
| PARAGRAPH
| BLOCK_QUOTE
| HTML_BLOCK Text
| CUSTOM_BLOCK OnEnter OnExit
| CODE_BLOCK Info Text
| HEADING Level
| LIST ListAttributes
| ITEM
| TEXT Text
| SOFTBREAK
| LINEBREAK
| HTML_INLINE Text
| CUSTOM_INLINE OnEnter OnExit
| CODE Text
| EMPH
| STRONG
| LINK Url Title
| IMAGE Url Title
| STRIKETHROUGH
| TABLE [TableCellAlignment]
| TABLE_ROW
| TABLE_CELL
| FOOTNOTE_REFERENCE
| FOOTNOTE_DEFINITION
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
data PosInfo = PosInfo{ startLine :: Int
, startColumn :: Int
, endLine :: Int
, endColumn :: Int
}
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
newtype CMarkOption = CMarkOption { unCMarkOption :: CInt }
-- | Combine a list of options into a single option, using bitwise or.
combineOptions :: [CMarkOption] -> CInt
combineOptions = foldr ((.|.) . unCMarkOption) 0
-- | Include a @data-sourcepos@ attribute on block elements.
optSourcePos :: CMarkOption
optSourcePos = CMarkOption #const CMARK_OPT_SOURCEPOS
-- | Render @softbreak@ elements as hard line breaks.
optHardBreaks :: CMarkOption
optHardBreaks = CMarkOption #const CMARK_OPT_HARDBREAKS
-- | Convert straight quotes to curly, @---@ to em-dash, @--@ to en-dash.
optSmart :: CMarkOption
optSmart = CMarkOption #const CMARK_OPT_SMART
-- | optSafe is defined here for API compatibility, but it no longer has any
-- effect. "Safe" mode is now the default: set optUnsafe to disable it.
optSafe :: CMarkOption
optSafe = CMarkOption #const CMARK_OPT_SAFE
-- | Allow rendering of raw HTML and potentially dangerous URLs in links
-- and images.
optUnsafe :: CMarkOption
optUnsafe = CMarkOption #const CMARK_OPT_UNSAFE
-- | Enable footnote syntax support (equivalent of footnotes extension for official cmark-gfm)
optFootnotes :: CMarkOption
optFootnotes = CMarkOption #const CMARK_OPT_FOOTNOTES
newtype CMarkExtension = CMarkExtension { unCMarkExtension :: String }
extStrikethrough :: CMarkExtension
extStrikethrough = CMarkExtension "strikethrough"
extTable :: CMarkExtension
extTable = CMarkExtension "table"
extAutolink :: CMarkExtension
extAutolink = CMarkExtension "autolink"
extTagfilter :: CMarkExtension
extTagfilter = CMarkExtension "tagfilter"
extTaskList :: CMarkExtension
extTaskList = CMarkExtension "tasklist"
ptrToNodeType :: NodePtr -> IO NodeType
ptrToNodeType ptr = do
nodeType <- c_cmark_node_get_type ptr
case nodeType of
#const CMARK_NODE_DOCUMENT
-> return DOCUMENT
#const CMARK_NODE_THEMATIC_BREAK
-> return THEMATIC_BREAK
#const CMARK_NODE_PARAGRAPH
-> return PARAGRAPH
#const CMARK_NODE_BLOCK_QUOTE
-> return BLOCK_QUOTE
#const CMARK_NODE_HTML_BLOCK
-> HTML_BLOCK <$> literal
#const CMARK_NODE_CUSTOM_BLOCK
-> CUSTOM_BLOCK <$> onEnter <*> onExit
#const CMARK_NODE_CODE_BLOCK
-> CODE_BLOCK <$> info
<*> literal
#const CMARK_NODE_LIST
-> LIST <$> listAttr
#const CMARK_NODE_ITEM
-> return ITEM
#const CMARK_NODE_HEADING
-> HEADING <$> level
#const CMARK_NODE_EMPH
-> return EMPH
#const CMARK_NODE_STRONG
-> return STRONG
#const CMARK_NODE_LINK
-> LINK <$> url <*> title
#const CMARK_NODE_IMAGE
-> IMAGE <$> url <*> title
#const CMARK_NODE_TEXT
-> TEXT <$> literal
#const CMARK_NODE_CODE
-> CODE <$> literal
#const CMARK_NODE_HTML_INLINE
-> HTML_INLINE <$> literal
#const CMARK_NODE_CUSTOM_INLINE
-> CUSTOM_INLINE <$> onEnter <*> onExit
#const CMARK_NODE_SOFTBREAK
-> return SOFTBREAK
#const CMARK_NODE_LINEBREAK
-> return LINEBREAK
#const CMARK_NODE_FOOTNOTE_DEFINITION
-> return FOOTNOTE_DEFINITION
#const CMARK_NODE_FOOTNOTE_REFERENCE
-> return FOOTNOTE_REFERENCE
_ -> if nodeType == fromIntegral (Unsafe.unsafePerformIO $ peek c_CMARK_NODE_STRIKETHROUGH) then
return STRIKETHROUGH
else if nodeType == fromIntegral (Unsafe.unsafePerformIO $ peek c_CMARK_NODE_TABLE) then
TABLE <$> alignments
else if nodeType == fromIntegral (Unsafe.unsafePerformIO $ peek c_CMARK_NODE_TABLE_ROW) then
return TABLE_ROW
else if nodeType == fromIntegral (Unsafe.unsafePerformIO $ peek c_CMARK_NODE_TABLE_CELL) then
return TABLE_CELL
else
error $ "Unknown node type " ++ (show nodeType)
where literal = c_cmark_node_get_literal ptr >>= totext
level = c_cmark_node_get_heading_level ptr
onEnter = c_cmark_node_get_on_enter ptr >>= totext
onExit = c_cmark_node_get_on_exit ptr >>= totext
listAttr = do
listtype <- c_cmark_node_get_list_type ptr
listdelim <- c_cmark_node_get_list_delim ptr
tight <- c_cmark_node_get_list_tight ptr
start <- c_cmark_node_get_list_start ptr
return ListAttributes{
listType = case listtype of
(#const CMARK_ORDERED_LIST) -> ORDERED_LIST
(#const CMARK_BULLET_LIST) -> BULLET_LIST
_ -> BULLET_LIST
, listDelim = case listdelim of
(#const CMARK_PERIOD_DELIM) -> PERIOD_DELIM
(#const CMARK_PAREN_DELIM) -> PAREN_DELIM
_ -> PERIOD_DELIM
, listTight = tight
, listStart = start
}
url = c_cmark_node_get_url ptr >>= totext
title = c_cmark_node_get_title ptr >>= totext
info = c_cmark_node_get_fence_info ptr >>= totext
alignments = do
ncols <- c_cmark_gfm_extensions_get_table_columns ptr
cols <- c_cmark_gfm_extensions_get_table_alignments ptr
mapM (fmap ucharToAlignment . peekElemOff cols) [0..(fromIntegral ncols) - 1]
ucharToAlignment (CUChar 108) = LeftAligned
ucharToAlignment (CUChar 99) = CenterAligned
ucharToAlignment (CUChar 114) = RightAligned
ucharToAlignment _ = NoAlignment
getPosInfo :: NodePtr -> IO (Maybe PosInfo)
getPosInfo ptr = do
startline <- c_cmark_node_get_start_line ptr
endline <- c_cmark_node_get_end_line ptr
startcol <- c_cmark_node_get_start_column ptr
endcol <- c_cmark_node_get_end_column ptr
if startline + endline + startcol + endcol == 0
then return Nothing
else return $ Just PosInfo{ startLine = startline
, startColumn = startcol
, endLine = endline
, endColumn = endcol }
toNode :: NodePtr -> IO Node
toNode ptr = do
let handleNodes ptr' =
if ptr' == nullPtr
then return []
else do
x <- toNode ptr'
xs <- c_cmark_node_next ptr' >>= handleNodes
return $! (x:xs)
nodeType <- ptrToNodeType ptr
children <- c_cmark_node_first_child ptr >>= handleNodes
posinfo <- getPosInfo ptr
return $! Node posinfo nodeType children
fromNode :: Node -> IO NodePtr
fromNode (Node _ nodeType children) = do
node <- case nodeType of
DOCUMENT -> c_cmark_node_new (#const CMARK_NODE_DOCUMENT)
THEMATIC_BREAK -> c_cmark_node_new (#const CMARK_NODE_THEMATIC_BREAK)
PARAGRAPH -> c_cmark_node_new (#const CMARK_NODE_PARAGRAPH)
BLOCK_QUOTE -> c_cmark_node_new (#const CMARK_NODE_BLOCK_QUOTE)
HTML_BLOCK literal -> do
n <- c_cmark_node_new (#const CMARK_NODE_HTML_BLOCK)
withtext literal (c_cmark_node_set_literal n)
return n
CUSTOM_BLOCK onEnter onExit -> do
n <- c_cmark_node_new (#const CMARK_NODE_CUSTOM_BLOCK)
withtext onEnter (c_cmark_node_set_on_enter n)
withtext onExit (c_cmark_node_set_on_exit n)
return n
CODE_BLOCK info literal -> do
n <- c_cmark_node_new (#const CMARK_NODE_CODE_BLOCK)
withtext literal (c_cmark_node_set_literal n)
withtext info (c_cmark_node_set_fence_info n)
return n
LIST attr -> do
n <- c_cmark_node_new (#const CMARK_NODE_LIST)
c_cmark_node_set_list_type n $ case listType attr of
ORDERED_LIST -> #const CMARK_ORDERED_LIST
BULLET_LIST -> #const CMARK_BULLET_LIST
c_cmark_node_set_list_delim n $ case listDelim attr of
PERIOD_DELIM -> #const CMARK_PERIOD_DELIM
PAREN_DELIM -> #const CMARK_PAREN_DELIM
c_cmark_node_set_list_tight n $ listTight attr
c_cmark_node_set_list_start n $ listStart attr
return n
ITEM -> c_cmark_node_new (#const CMARK_NODE_ITEM)
HEADING lev -> do
n <- c_cmark_node_new (#const CMARK_NODE_HEADING)
c_cmark_node_set_heading_level n lev
return n
EMPH -> c_cmark_node_new (#const CMARK_NODE_EMPH)
STRONG -> c_cmark_node_new (#const CMARK_NODE_STRONG)
LINK url title -> do
n <- c_cmark_node_new (#const CMARK_NODE_LINK)
withtext url (c_cmark_node_set_url n)
withtext title (c_cmark_node_set_title n)
return n
IMAGE url title -> do
n <- c_cmark_node_new (#const CMARK_NODE_IMAGE)
withtext url (c_cmark_node_set_url n)
withtext title (c_cmark_node_set_title n)
return n
TEXT literal -> do
n <- c_cmark_node_new (#const CMARK_NODE_TEXT)
withtext literal (c_cmark_node_set_literal n)
return n
CODE literal -> do
n <- c_cmark_node_new (#const CMARK_NODE_CODE)
withtext literal (c_cmark_node_set_literal n)
return n
HTML_INLINE literal -> do
n <- c_cmark_node_new (#const CMARK_NODE_HTML_INLINE)
withtext literal (c_cmark_node_set_literal n)
return n
CUSTOM_INLINE onEnter onExit -> do
n <- c_cmark_node_new (#const CMARK_NODE_CUSTOM_INLINE)
withtext onEnter (c_cmark_node_set_on_enter n)
withtext onExit (c_cmark_node_set_on_exit n)
return n
SOFTBREAK -> c_cmark_node_new (#const CMARK_NODE_SOFTBREAK)
LINEBREAK -> c_cmark_node_new (#const CMARK_NODE_LINEBREAK)
STRIKETHROUGH -> c_cmark_node_new (fromIntegral . Unsafe.unsafePerformIO $ peek c_CMARK_NODE_STRIKETHROUGH)
TABLE _ -> error "constructing table not supported"
TABLE_ROW -> error "constructing table row not supported"
TABLE_CELL -> error "constructing table cell not supported"
FOOTNOTE_DEFINITION -> error "constructing footnotes not supported"
FOOTNOTE_REFERENCE -> error "constructing footnotes not supported"
mapM_ (\child -> fromNode child >>= c_cmark_node_append_child node) children
return node
totext :: CString -> IO Text
totext str
| str == nullPtr = return empty
| otherwise = TF.peekCStringLen (str, c_strlen str)
withtext :: Text -> (CString -> IO a) -> IO a
withtext t f = TF.withCStringLen (snoc t '\0') (f . fst)
foreign import ccall "string.h strlen"
c_strlen :: CString -> Int
foreign import ccall "cmark-gfm.h cmark_node_new"
c_cmark_node_new :: Int -> IO NodePtr
foreign import ccall "cmark-gfm.h cmark_render_html"
c_cmark_render_html :: NodePtr -> CInt -> LlistPtr ExtensionPtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_render_xml"
c_cmark_render_xml :: NodePtr -> CInt -> IO CString
foreign import ccall "cmark-gfm.h cmark_render_man"
c_cmark_render_man :: NodePtr -> CInt -> Int -> IO CString
foreign import ccall "cmark-gfm.h cmark_render_latex"
c_cmark_render_latex :: NodePtr -> CInt -> Int -> IO CString
foreign import ccall "cmark-gfm.h cmark_render_commonmark"
c_cmark_render_commonmark :: NodePtr -> CInt -> Int -> IO CString
foreign import ccall "cmark-gfm.h cmark_parser_new"
c_cmark_parser_new :: CInt -> IO ParserPtr
foreign import ccall "cmark-gfm.h cmark_parser_feed"
c_cmark_parser_feed :: ParserPtr -> CString -> Int -> IO ()
foreign import ccall "cmark-gfm.h cmark_parser_finish"
c_cmark_parser_finish :: ParserPtr -> IO NodePtr
foreign import ccall "cmark-gfm.h cmark_parser_free"
c_cmark_parser_free :: ParserPtr -> IO ()
foreign import ccall "cmark-gfm.h cmark_node_get_type"
c_cmark_node_get_type :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_first_child"
c_cmark_node_first_child :: NodePtr -> IO NodePtr
foreign import ccall "cmark-gfm.h cmark_node_next"
c_cmark_node_next :: NodePtr -> IO NodePtr
foreign import ccall "cmark-gfm.h cmark_node_get_literal"
c_cmark_node_get_literal :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_get_url"
c_cmark_node_get_url :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_get_title"
c_cmark_node_get_title :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_get_heading_level"
c_cmark_node_get_heading_level :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_list_type"
c_cmark_node_get_list_type :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_list_tight"
c_cmark_node_get_list_tight :: NodePtr -> IO Bool
foreign import ccall "cmark-gfm.h cmark_node_get_list_start"
c_cmark_node_get_list_start :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_list_delim"
c_cmark_node_get_list_delim :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_fence_info"
c_cmark_node_get_fence_info :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_get_start_line"
c_cmark_node_get_start_line :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_start_column"
c_cmark_node_get_start_column :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_end_line"
c_cmark_node_get_end_line :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_end_column"
c_cmark_node_get_end_column :: NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_get_on_enter"
c_cmark_node_get_on_enter :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_get_on_exit"
c_cmark_node_get_on_exit :: NodePtr -> IO CString
foreign import ccall "cmark-gfm.h cmark_node_append_child"
c_cmark_node_append_child :: NodePtr -> NodePtr -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_literal"
c_cmark_node_set_literal :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_url"
c_cmark_node_set_url :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_title"
c_cmark_node_set_title :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_heading_level"
c_cmark_node_set_heading_level :: NodePtr -> Int -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_list_type"
c_cmark_node_set_list_type :: NodePtr -> Int -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_list_tight"
c_cmark_node_set_list_tight :: NodePtr -> Bool -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_list_start"
c_cmark_node_set_list_start :: NodePtr -> Int -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_list_delim"
c_cmark_node_set_list_delim :: NodePtr -> Int -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_fence_info"
c_cmark_node_set_fence_info :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_on_enter"
c_cmark_node_set_on_enter :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h cmark_node_set_on_exit"
c_cmark_node_set_on_exit :: NodePtr -> CString -> IO Int
foreign import ccall "cmark-gfm.h &cmark_node_free"
c_cmark_node_free :: FunPtr (NodePtr -> IO ())
foreign import ccall "cmark-gfm-core-extensions.h cmark_gfm_core_extensions_ensure_registered"
c_cmark_gfm_core_extensions_ensure_registered :: IO ()
foreign import ccall "cmark-gfm-extension_api.h cmark_find_syntax_extension"
c_cmark_find_syntax_extension :: CString -> IO ExtensionPtr
foreign import ccall "cmark-gfm.h cmark_llist_append"
c_cmark_llist_append :: MemPtr -> LlistPtr a -> Ptr () -> IO (LlistPtr a)
foreign import ccall "cmark-gfm.h cmark_llist_free"
c_cmark_llist_free :: MemPtr -> LlistPtr a -> IO ()
foreign import ccall "cmark-gfm.h cmark_get_default_mem_allocator"
c_cmark_mem :: MemPtr
foreign import ccall "cmark-gfm-extension_api.h cmark_parser_attach_syntax_extension"
c_cmark_parser_attach_syntax_extension :: ParserPtr -> ExtensionPtr -> IO ()
foreign import ccall "strikethrough.h &CMARK_NODE_STRIKETHROUGH"
c_CMARK_NODE_STRIKETHROUGH :: Ptr #type cmark_node_type
foreign import ccall "table.h &CMARK_NODE_TABLE"
c_CMARK_NODE_TABLE :: Ptr #type cmark_node_type
foreign import ccall "table.h &CMARK_NODE_TABLE_ROW"
c_CMARK_NODE_TABLE_ROW :: Ptr #type cmark_node_type
foreign import ccall "table.h &CMARK_NODE_TABLE_CELL"
c_CMARK_NODE_TABLE_CELL :: Ptr #type cmark_node_type
foreign import ccall "cmark-gfm-core-extensions.h cmark_gfm_extensions_get_table_columns"
c_cmark_gfm_extensions_get_table_columns :: NodePtr -> IO CUShort
foreign import ccall "cmark-gfm-core-extensions.h cmark_gfm_extensions_get_table_alignments"
c_cmark_gfm_extensions_get_table_alignments :: NodePtr -> IO (Ptr CUChar)