pmh_parser.h 2.4 KB

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