tedi2lang.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * tedi2lang header file
  3. * Copyright (C) <2022> <alkeon> [alkeon@autistici.org]
  4. * Texdi is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * Texdi is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with tedi2lang. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __TEDI2LANG__
  18. #define __TEDI2LANG__
  19. #include <iostream>
  20. #include <string>
  21. using namespace std;
  22. struct tags_definition {
  23. tags_definition(){}
  24. string start_heading_first_level_tag;
  25. string start_heading_second_level_tag;
  26. string start_heading_third_level_tag;
  27. string start_heading_fourth_level_tag;
  28. string end_heading_first_level_tag;
  29. string end_heading_second_level_tag;
  30. string end_heading_third_level_tag;
  31. string end_heading_fourth_level_tag;
  32. string start_list_tag;
  33. string end_list_tag;
  34. string list_item_tag;
  35. string start_container_tag;
  36. string middle_container_tag;
  37. string end_container_tag;
  38. string start_link_tag;
  39. string middle_link_tag;
  40. string end_link_tag;
  41. string start_image_tag;
  42. string middle_image_tag;
  43. string end_image_tag;
  44. string start_table_tag;
  45. string end_table_tag;
  46. string start_table_row_tag;
  47. string end_table_row_tag;
  48. string start_table_data_tag;
  49. string end_table_data_tag;
  50. string end_paragraph_tag;
  51. };
  52. class tedi2lang{
  53. public:
  54. tedi2lang(tags_definition td);
  55. tedi2lang();
  56. virtual ~tedi2lang() = default;
  57. virtual string convert(string text, string header, string footer);
  58. virtual string convert_line(string& line);
  59. virtual string convert_line_heading(string& line, size_t hash_position);
  60. virtual string convert_line_list_start(string& line);
  61. virtual void convert_line_list_item(string& line, size_t li);
  62. virtual string convert_line_list_end(string& line);
  63. virtual void convert_line_quote(string& line);
  64. virtual void convert_unquoted_tags(string& line);
  65. virtual void convert_line_block(string& line);
  66. virtual void convert_line_image(string& line);
  67. virtual void convert_line_link(string& line);
  68. virtual string convert_line_table(string& line, size_t first_pipe);
  69. virtual string convert_line_table_row(string& line);
  70. virtual string convert_end_table(string& line);
  71. virtual string convert_end_table_control_tags(string& line);
  72. virtual string convert_line_ending(string& line);
  73. virtual string convert_line_control_tags(string& line);
  74. bool is_first_tag(string& line, int position);
  75. bool is_tag_escaped(string& line, size_t position);
  76. virtual size_t get_not_escaped_tag(string& line, string character_find, size_t position = string::npos);
  77. virtual int main_tag(string& line);
  78. virtual size_t correct_position(string line, unsigned position, char starting_char, char ending_char);
  79. virtual void check_ending_container(string& line);
  80. virtual bool found(size_t position){ return (position != string::npos); }
  81. string strip_escaping(string line);
  82. int replace(string& source, const string& find, const string& replace);
  83. protected:
  84. bool _is_converting_table;
  85. int _is_unordered_list;
  86. bool _has_block;
  87. int _open_brackets;
  88. const string _start_heading_first_level_tag;
  89. const string _start_heading_second_level_tag;
  90. const string _start_heading_third_level_tag;
  91. const string _start_heading_fourth_level_tag;
  92. const string _end_heading_first_level_tag;
  93. const string _end_heading_second_level_tag;
  94. const string _end_heading_third_level_tag;
  95. const string _end_heading_fourth_level_tag;
  96. const string _start_list_tag;
  97. const string _list_item_tag;
  98. const string _end_list_tag;
  99. const string _start_container_tag;
  100. const string _middle_container_tag;
  101. const string _end_container_tag;
  102. const string _start_link_tag;
  103. const string _middle_link_tag;
  104. const string _end_link_tag;
  105. const string _start_image_tag;
  106. const string _middle_image_tag;
  107. const string _end_image_tag;
  108. const string _start_table_tag;
  109. const string _end_table_tag;
  110. const string _start_table_row_tag;
  111. const string _end_table_row_tag;
  112. const string _start_table_data_tag;
  113. const string _end_table_data_tag;
  114. const string _end_paragraph_tag;
  115. };
  116. #endif