pmh_parser.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* PEG Markdown Highlight
  2. * Copyright 2011-2016 Ali Rantakari -- http://hasseg.org
  3. * Licensed under the GPL2+ and MIT licenses (see LICENSE for more info).
  4. *
  5. * pmh_parser.h
  6. */
  7. #pragma GCC diagnostic ignored "-Wunused-parameter"
  8. /** \file
  9. * \brief Parser public interface.
  10. */
  11. #ifndef __cplusplus
  12. #include <stdbool.h>
  13. #endif
  14. #include <stdlib.h>
  15. #include <assert.h>
  16. #include "pmh_definitions.h"
  17. /**
  18. * \brief Parse Markdown text, return elements
  19. *
  20. * Parses the given Markdown text and returns the results as an
  21. * array of linked lists of elements, indexed by type.
  22. *
  23. * \param[in] text The Markdown text to parse for highlighting.
  24. * \param[in] extensions The extensions to use in parsing (a bitfield
  25. * of pmh_extensions values).
  26. * \param[out] out_result A pmh_element array, indexed by type, containing
  27. * the results of the parsing (linked lists of elements).
  28. * You must pass this to pmh_free_elements() when it's
  29. * not needed anymore.
  30. *
  31. * \sa pmh_element_type
  32. */
  33. void pmh_markdown_to_elements(char *text, int extensions,
  34. pmh_element **out_result[]);
  35. /**
  36. * \brief Sort elements in list by start offset.
  37. *
  38. * Sorts the linked lists of elements in the list returned by
  39. * pmh_markdown_to_elements() by their start offsets (pos).
  40. *
  41. * \param[in] element_lists Array of linked lists of elements (output
  42. * from pmh_markdown_to_elements()).
  43. *
  44. * \sa pmh_markdown_to_elements
  45. * \sa pmh_element::pos
  46. */
  47. void pmh_sort_elements_by_pos(pmh_element *element_lists[]);
  48. /**
  49. * \brief Free pmh_element array
  50. *
  51. * Frees an pmh_element array returned by pmh_markdown_to_elements().
  52. *
  53. * \param[in] elems The pmh_element array resulting from calling
  54. * pmh_markdown_to_elements().
  55. *
  56. * \sa pmh_markdown_to_elements
  57. */
  58. void pmh_free_elements(pmh_element **elems);
  59. /**
  60. * \brief Get element type name
  61. *
  62. * \param[in] type The type value to get the name for.
  63. *
  64. * \return The name of the given type as a null-terminated string.
  65. *
  66. * \sa pmh_element_type
  67. */
  68. char *pmh_element_name_from_type(pmh_element_type type);
  69. /**
  70. * \brief Get element type from a name
  71. *
  72. * \param[in] name The name of the type.
  73. *
  74. * \return The element type corresponding to the given name.
  75. *
  76. * \sa pmh_element_type
  77. */
  78. pmh_element_type pmh_element_type_from_name(char *name);