Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bt_plainhtml.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. //BibleTime includes
  10. #include "cswordmoduleinfo.h"
  11. #include "cswordbackend.h"
  12. #include "util/cpointers.h"
  13. #include "bt_plainhtml.h"
  14. //system includes
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. //Sword includes
  18. #include <utilxml.h>
  19. //Qt includes
  20. #include <tqregexp.h>
  21. #include <tqstring.h>
  22. using namespace Filters;
  23. BT_PLAINHTML::BT_PLAINHTML() : sword::SWFilter() {
  24. }
  25. /** No descriptions */
  26. char BT_PLAINHTML::processText(sword::SWBuf& text, const sword::SWKey * key, const sword::SWModule * module) {
  27. int count = 0;
  28. SWBuf orig = text;
  29. const char *from = orig.c_str();
  30. for (text = ""; *from; from++)
  31. {
  32. if ((*from == '\n') && (from[1] == '\n')) // two newlinea are a paragraph
  33. {
  34. text += "<P>";
  35. from++;
  36. continue;
  37. }
  38. //This is a special case: Newlines in the plaintext editor are stored as <br />, not as \n
  39. //we need to let them through
  40. else if ((*from == '<') && (from[1] == 'b') && (from[2] == 'r') && (from[3] == ' ') && (from[4] == '/') && (from[5] == '>')){
  41. text += "<br />";
  42. from += 5;
  43. continue;
  44. }
  45. else if ((*from == '\n')){ // only one new line
  46. text += "<BR>";
  47. continue;
  48. }
  49. else if (*from == '<') {
  50. text += "&lt;";
  51. continue;
  52. }
  53. else if (*from == '>') {
  54. text += "&gt;";
  55. continue;
  56. }
  57. else if (*from == '&'){
  58. text += "&amp;";
  59. continue;
  60. }
  61. else if (*from == '{') { //footnote start
  62. text += "<FONT COLOR=\"#80000\"><SMALL> (";
  63. continue;
  64. }
  65. else if (*from == '}') //footnote end
  66. {
  67. text += ") </SMALL></FONT>";
  68. continue;
  69. }
  70. else if ((*from == ' ') && (count > 5000))
  71. {
  72. text += "<WBR>";
  73. count = 0;
  74. continue;
  75. }
  76. text += *from;
  77. count++;
  78. }
  79. return 0;
  80. }