tedi2md.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Main file of tedi2md
  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 tedi2md. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <iostream>
  18. #include <string>
  19. #include <fstream>
  20. #include <sstream>
  21. #include "../tedi2lang/tedi2lang.h"
  22. #include "tedi2md.h"
  23. #include "../tedi2lang/exception.h"
  24. using namespace std;
  25. #define BLOCK 2
  26. #define IMAGE 1
  27. #define LINK 0
  28. #define NO_TAG -1
  29. tedi2md::tedi2md(tags_definition td): tedi2lang(td){}
  30. tedi2md::tedi2md(): tedi2lang(default_tags_value()){}
  31. tags_definition tedi2md::default_tags_value(){
  32. tags_definition td;
  33. td.start_heading_first_level_tag = "# ";
  34. td.start_heading_second_level_tag = "## ";
  35. td.start_heading_third_level_tag = "### ";
  36. td.start_heading_fourth_level_tag = "#### ";
  37. td.end_heading_first_level_tag = "";
  38. td.end_heading_second_level_tag = "";
  39. td.end_heading_third_level_tag = "";
  40. td.end_heading_fourth_level_tag = "";
  41. td.start_list_tag = "";
  42. td.list_item_tag = "- ";
  43. td.end_list_tag = "";
  44. td.start_container_tag = "<div class=\"";
  45. td.middle_container_tag = "\">";
  46. td.end_container_tag = "</div>";
  47. td.start_link_tag = "<a href=\"";
  48. td.middle_link_tag = "\">";
  49. td.end_link_tag = "</a>";
  50. td.start_image_tag = "<img alt=\"";
  51. td.middle_image_tag = "\" src=\"";
  52. td.end_image_tag = "\">";
  53. td.start_table_tag = "<table>";
  54. td.end_table_tag = "</table>";
  55. td.start_table_row_tag = "<tr>";
  56. td.end_table_row_tag = "</tr>";
  57. td.start_table_data_tag = "<td>";
  58. td.end_table_data_tag = "</td>";
  59. return td;
  60. }
  61. /*
  62. * Control tags:
  63. * <!, <>, <+. <
  64. */
  65. string tedi2md::convert_line_control_tags(string& line){
  66. if(line[1] != '!') {
  67. if(line[1] == '>') {
  68. line = line.erase(0,2);
  69. return line + "\n";
  70. } else if(line[1] == '+') {
  71. line = line.erase(0,2);
  72. if(_is_paragraph) {
  73. _is_paragraph = false;
  74. return line + _end_paragraph_tag + "\n";
  75. } else
  76. return _start_paragraph_tag + line + _end_paragraph_tag + "\n";
  77. } else {
  78. line = line.erase(0,1);
  79. return line + "\n";
  80. }
  81. } else
  82. return "";
  83. }