aboutsummaryrefslogtreecommitdiff
path: root/man/man3/cmark.3
blob: cdfcfa50d5e67f2b01fc04089423fbab2e6866ee (plain)
  1. .TH cmark 3 "December 14, 2014" "LOCAL" "Library Functions Manual"
  2. .SH
  3. NAME
  4. .PP
  5. \f[B]cmark\f[] \- CommonMark parsing, manipulating, and rendering
  6. .SH
  7. DESCRIPTION
  8. .SS
  9. Simple Interface
  10. .PP
  11. .nf
  12. \fC
  13. .RS 0n
  14. #define CMARK_VERSION "0.1"
  15. .RE
  16. \f[]
  17. .fi
  18. .PP
  19. Current version of library.
  20. .PP
  21. \fIchar *\f[] \fBcmark_markdown_to_html\f[](\fIconst char *text\f[], \fIint len\f[])
  22. .PP
  23. Convert \f[I]text\f[] (assumed to be a UTF\-8 encoded string with length
  24. \f[I]len\f[] from CommonMark Markdown to HTML, returning a null\-terminated,
  25. UTF\-8\-encoded string.
  26. .SS
  27. Node Structure
  28. .SS
  29. Creating and Destroying Nodes
  30. .PP
  31. \fIcmark_node*\f[] \fBcmark_node_new\f[](\fIcmark_node_type type\f[])
  32. .PP
  33. Creates a new node of type \f[I]type\f[]\&. Note that the node may have
  34. other required properties, which it is the caller's responsibility
  35. to assign.
  36. .PP
  37. \fIvoid\f[] \fBcmark_node_free\f[](\fIcmark_node *node\f[])
  38. .PP
  39. Frees the memory allocated for a node.
  40. .SS
  41. Tree Traversal
  42. .PP
  43. \fIcmark_node*\f[] \fBcmark_node_next\f[](\fIcmark_node *node\f[])
  44. .PP
  45. Returns the next node in the sequence after \f[I]node\f[], or NULL if
  46. there is none.
  47. .PP
  48. \fIcmark_node*\f[] \fBcmark_node_previous\f[](\fIcmark_node *node\f[])
  49. .PP
  50. Returns the previous node in the sequence after \f[I]node\f[], or NULL if
  51. there is none.
  52. .PP
  53. \fIcmark_node*\f[] \fBcmark_node_parent\f[](\fIcmark_node *node\f[])
  54. .PP
  55. Returns the parent of \f[I]node\f[], or NULL if there is none.
  56. .PP
  57. \fIcmark_node*\f[] \fBcmark_node_first_child\f[](\fIcmark_node *node\f[])
  58. .PP
  59. Returns the first child of \f[I]node\f[], or NULL if \f[I]node\f[] has no children.
  60. .PP
  61. \fIcmark_node*\f[] \fBcmark_node_last_child\f[](\fIcmark_node *node\f[])
  62. .PP
  63. Returns the last child of \f[I]node\f[], or NULL if \f[I]node\f[] has no children.
  64. .SS
  65. Iterator
  66. .PP
  67. An iterator will walk through a tree of nodes, starting from a root
  68. node, returning one node at a time, together with information about
  69. whether the node is being entered or exited. The iterator will
  70. first descend to a child node, if there is one. When there is no
  71. child, the iterator will go to the next sibling. When there is no
  72. next sibling, the iterator will return to the parent (but with
  73. a \f[I]cmark_event_type\f[] of \f[C]CMARK_EVENT_EXIT\f[]). The iterator will
  74. return \f[C]CMARK_EVENT_DONE\f[] when it reaches the root node again.
  75. One natural application is an HTML renderer, where an \f[C]ENTER\f[] event
  76. outputs an open tag and an \f[C]EXIT\f[] event outputs a close tag.
  77. An iterator might also be used to transform an AST in some systematic
  78. way, for example, turning all level\-3 headers into regular paragraphs.
  79. .IP
  80. .nf
  81. \f[C]
  82. \f[]
  83. .fi
  84. .PP
  85. \fIcmark_iter*\f[] \fBcmark_iter_new\f[](\fIcmark_node *root\f[])
  86. .PP
  87. Creates a new iterator starting at \f[I]root\f[]\&.
  88. .PP
  89. \fIvoid\f[] \fBcmark_iter_free\f[](\fIcmark_iter *iter\f[])
  90. .PP
  91. Frees the memory allocated for an iterator.
  92. .PP
  93. \fIcmark_event_type\f[] \fBcmark_iter_next\f[](\fIcmark_iter *iter\f[])
  94. .PP
  95. Returns the event type (\f[C]CMARK_EVENT_ENTER\f[], \f[C]CMARK_EVENT_EXIT\f[],
  96. or \f[C]CMARK_EVENT_DONE\f[]) for the next node.
  97. .PP
  98. \fIcmark_node*\f[] \fBcmark_iter_get_node\f[](\fIcmark_iter *iter\f[])
  99. .PP
  100. Returns the next node in the sequence described above.
  101. .SS
  102. Accessors
  103. .PP
  104. \fIcmark_node_type\f[] \fBcmark_node_get_type\f[](\fIcmark_node *node\f[])
  105. .PP
  106. Returns the type of \f[I]node\f[], or \f[C]CMARK_NODE_NONE\f[] on error.
  107. .PP
  108. \fIconst char*\f[] \fBcmark_node_get_string_content\f[](\fIcmark_node *node\f[])
  109. .PP
  110. Returns the string contents of \f[I]node\f[], or NULL if none.
  111. .PP
  112. \fIint\f[] \fBcmark_node_set_string_content\f[](\fIcmark_node *node\f[], \fIconst char *content\f[])
  113. .PP
  114. Sets the string contents of \f[I]node\f[]\&. Returns 1 on success,
  115. 0 on failure.
  116. .PP
  117. \fIint\f[] \fBcmark_node_get_header_level\f[](\fIcmark_node *node\f[])
  118. .PP
  119. Returns the header level of \f[I]node\f[], or 0 if \f[I]node\f[] is not a header.
  120. .PP
  121. \fIint\f[] \fBcmark_node_set_header_level\f[](\fIcmark_node *node\f[], \fIint level\f[])
  122. .PP
  123. Sets the header level of \f[I]node\f[], returning 1 on success and 0 on error.
  124. .PP
  125. \fIcmark_list_type\f[] \fBcmark_node_get_list_type\f[](\fIcmark_node *node\f[])
  126. .PP
  127. Returns the list type of \f[I]node\f[], or \f[C]CMARK_NO_LIST\f[] if \f[I]node\f[]
  128. is not a list.
  129. .PP
  130. \fIint\f[] \fBcmark_node_set_list_type\f[](\fIcmark_node *node\f[], \fIcmark_list_type type\f[])
  131. .PP
  132. Sets the list type of \f[I]node\f[], returning 1 on success and 0 on error.
  133. .PP
  134. \fIint\f[] \fBcmark_node_get_list_start\f[](\fIcmark_node *node\f[])
  135. .PP
  136. Returns starting number of \f[I]node\f[], if it is an ordered list, otherwise 0.
  137. .PP
  138. \fIint\f[] \fBcmark_node_set_list_start\f[](\fIcmark_node *node\f[], \fIint start\f[])
  139. .PP
  140. Sets starting number of \f[I]node\f[], if it is an ordered list. Returns 1
  141. on success, 0 on failure.
  142. .PP
  143. \fIint\f[] \fBcmark_node_get_list_tight\f[](\fIcmark_node *node\f[])
  144. .PP
  145. Returns 1 if \f[I]node\f[] is a tight list, 0 otherwise.
  146. .PP
  147. \fIint\f[] \fBcmark_node_set_list_tight\f[](\fIcmark_node *node\f[], \fIint tight\f[])
  148. .PP
  149. Sets the "tightness" of a list. Returns 1 on success, 0 on failure.
  150. .PP
  151. \fIconst char*\f[] \fBcmark_node_get_fence_info\f[](\fIcmark_node *node\f[])
  152. .PP
  153. Returns the info string from a fenced code block, or NULL if none.
  154. .PP
  155. \fIint\f[] \fBcmark_node_set_fence_info\f[](\fIcmark_node *node\f[], \fIconst char *info\f[])
  156. .PP
  157. Sets the info string in a fenced code block, returning 1 on
  158. success and 0 on failure.
  159. .PP
  160. \fIconst char*\f[] \fBcmark_node_get_url\f[](\fIcmark_node *node\f[])
  161. .PP
  162. Gets the URL of a link or image \f[I]node\f[], or NULL if none.
  163. .PP
  164. \fIint\f[] \fBcmark_node_set_url\f[](\fIcmark_node *node\f[], \fIconst char *url\f[])
  165. .PP
  166. Sets the URL of a link or image \f[I]node\f[]\&. Returns 1 on success,
  167. 0 on failure.
  168. .PP
  169. \fIconst char*\f[] \fBcmark_node_get_title\f[](\fIcmark_node *node\f[])
  170. .PP
  171. Gets the title of a link or image \f[I]node\f[], or NULL if none.
  172. .PP
  173. \fIint\f[] \fBcmark_node_set_title\f[](\fIcmark_node *node\f[], \fIconst char *title\f[])
  174. .PP
  175. Sets the title of a link or image \f[I]node\f[]\&. Returns 1 on success,
  176. 0 on failure.
  177. .PP
  178. \fIint\f[] \fBcmark_node_get_start_line\f[](\fIcmark_node *node\f[])
  179. .PP
  180. Returns the line on which \f[I]node\f[] begins.
  181. .PP
  182. \fIint\f[] \fBcmark_node_get_start_column\f[](\fIcmark_node *node\f[])
  183. .PP
  184. Returns the column at which \f[I]node\f[] begins.
  185. .PP
  186. \fIint\f[] \fBcmark_node_get_end_line\f[](\fIcmark_node *node\f[])
  187. .PP
  188. Returns the line on which \f[I]node\f[] ends.
  189. .SS
  190. Tree Manipulation
  191. .PP
  192. \fIvoid\f[] \fBcmark_node_unlink\f[](\fIcmark_node *node\f[])
  193. .PP
  194. Unlinks a \f[I]node\f[], removing it from the tree, but not freeing its
  195. memory. (Use \f[I]cmark_node_free\f[] for that.)
  196. .PP
  197. \fIint\f[] \fBcmark_node_insert_before\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[])
  198. .PP
  199. Inserts \f[I]sibling\f[] before \f[I]node\f[]\&. Returns 1 on success, 0 on failure.
  200. .PP
  201. \fIint\f[] \fBcmark_node_insert_after\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[])
  202. .PP
  203. Inserts \f[I]sibling\f[] after \f[I]node\f[]\&. Returns 1 on success, 0 on failure.
  204. .PP
  205. \fIint\f[] \fBcmark_node_prepend_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[])
  206. .PP
  207. Adds \f[I]child\f[] to the beginning of the children of \f[I]node\f[]\&.
  208. Returns 1 on success, 0 on failure.
  209. .PP
  210. \fIint\f[] \fBcmark_node_append_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[])
  211. .PP
  212. Adds \f[I]child\f[] to the end of the children of \f[I]node\f[]\&.
  213. Returns 1 on success, 0 on failure.
  214. .SS
  215. Parsing
  216. .PP
  217. Simple interface:
  218. .IP
  219. .nf
  220. \f[C]
  221. \f[]
  222. .fi
  223. .PP
  224. Streaming interface:
  225. .IP
  226. .nf
  227. \f[C]
  228. \f[]
  229. .fi
  230. .PP
  231. \fIcmark_parser *\f[] \fBcmark_parser_new\f[](\fI\f[])
  232. .PP
  233. Creates a new parser object.
  234. .PP
  235. \fIvoid\f[] \fBcmark_parser_free\f[](\fIcmark_parser *parser\f[])
  236. .PP
  237. Frees memory allocated for a parser object.
  238. .PP
  239. \fIvoid\f[] \fBcmark_parser_feed\f[](\fIcmark_parser *parser\f[], \fIconst char *buffer\f[], \fIsize_t len\f[])
  240. .PP
  241. Feeds a string of length \f[I]len\f[] to \f[I]parser\f[]\&.
  242. .PP
  243. \fIcmark_node *\f[] \fBcmark_parser_finish\f[](\fIcmark_parser *parser\f[])
  244. .PP
  245. Finish parsing and return a pointer to a tree of nodes.
  246. .PP
  247. \fIcmark_node *\f[] \fBcmark_parse_document\f[](\fIconst char *buffer\f[], \fIsize_t len\f[])
  248. .PP
  249. Parse a CommonMark document in \f[I]buffer\f[] of length \f[I]len\f[]\&.
  250. Returns a pointer to a tree of nodes.
  251. .PP
  252. \fIcmark_node *\f[] \fBcmark_parse_file\f[](\fIFILE *f\f[])
  253. .PP
  254. Parse a CommonMark document in file \f[I]f\f[], returning a pointer to
  255. a tree of nodes.
  256. .SS
  257. Rendering
  258. .PP
  259. \fIchar *\f[] \fBcmark_render_ast\f[](\fIcmark_node *root\f[])
  260. .PP
  261. Render a \f[I]node\f[] tree for debugging purposes, showing
  262. the hierachy of nodes and their types and contents.
  263. .PP
  264. \fIchar *\f[] \fBcmark_render_html\f[](\fIcmark_node *root\f[])
  265. .PP
  266. Render a \f[I]node\f[] tree as an HTML fragment. It is up to the user
  267. to add an appropriate header and footer.
  268. .PP
  269. \fIchar *\f[] \fBcmark_render_man\f[](\fIcmark_node *root\f[])
  270. .PP
  271. Render a \f[I]node\f[] tree as a groff man page, without the header.
  272. .SH
  273. AUTHORS
  274. .PP
  275. John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.