htmltemplatehelper.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef HTMLTEMPLATEHELPER_H
  2. #define HTMLTEMPLATEHELPER_H
  3. #include <QString>
  4. namespace vnotex
  5. {
  6. class MarkdownEditorConfig;
  7. class PdfViewerConfig;
  8. class MindMapEditorConfig;
  9. struct WebResource;
  10. // Global options to be passed to Web side at the very beginning for Markdown.
  11. struct MarkdownWebGlobalOptions
  12. {
  13. bool m_webPlantUml = true;
  14. QString m_plantUmlWebService;
  15. bool m_webGraphviz = true;
  16. QString m_mathJaxScript;
  17. bool m_sectionNumberEnabled = true;
  18. int m_sectionNumberBaseLevel = 2;
  19. bool m_constrainImageWidthEnabled = true;
  20. bool m_imageAlignCenterEnabled = true;
  21. bool m_protectFromXss = false;
  22. bool m_htmlTagEnabled = true;
  23. bool m_autoBreakEnabled = false;
  24. bool m_linkifyEnabled = true;
  25. bool m_indentFirstLineEnabled = false;
  26. bool m_codeBlockLineNumberEnabled = true;
  27. // Force to use transparent background.
  28. bool m_transparentBackgroundEnabled = false;
  29. // Whether the content elements are scrollable. Like PDF, it is false.
  30. bool m_scrollable = true;
  31. int m_bodyWidth = -1;
  32. int m_bodyHeight = -1;
  33. // Whether transform inlie SVG to PNG.
  34. // For wkhtmltopdf converter, it could not render some inline SVG correctly.
  35. // This is just a hint not mandatory. For now, PlantUML and Graphviz needs this.
  36. bool m_transformSvgToPngEnabled = false;
  37. // wkhtmltopdf will make the MathJax formula too small.
  38. qreal m_mathJaxScale = -1;
  39. // Whether remove the tool bar of code blocks added by Prism.js.
  40. bool m_removeCodeToolBarEnabled = false;
  41. QString toJavascriptObject() const;
  42. };
  43. // Help to generate and update HTML templates.
  44. class HtmlTemplateHelper
  45. {
  46. public:
  47. struct MarkdownParas
  48. {
  49. QString m_webStyleSheetFile;
  50. QString m_highlightStyleSheetFile;
  51. bool m_transparentBackgroundEnabled = false;
  52. bool m_scrollable = true;
  53. int m_bodyWidth = -1;
  54. int m_bodyHeight = -1;
  55. bool m_transformSvgToPngEnabled = false;
  56. qreal m_mathJaxScale = -1;
  57. bool m_removeCodeToolBarEnabled = false;
  58. };
  59. HtmlTemplateHelper() = delete;
  60. // For MarkdownViewer.
  61. static const QString &getMarkdownViewerTemplate();
  62. static void updateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config, bool p_force = false);
  63. static QString generateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config, const MarkdownParas &p_paras);
  64. static QString generateMarkdownExportTemplate(const MarkdownEditorConfig &p_config,
  65. bool p_addOutlinePanel);
  66. // For common HTML content manipulation.
  67. static void fillTitle(QString &p_template, const QString &p_title);
  68. static void fillStyleContent(QString &p_template, const QString &p_styles);
  69. static void fillHeadContent(QString &p_template, const QString &p_head);
  70. static void fillContent(QString &p_template, const QString &p_content);
  71. static void fillBodyClassList(QString &p_template, const QString &p_classList);
  72. static void fillOutlinePanel(QString &p_template, WebResource &p_exportResource, bool p_addOutlinePanel);
  73. // For PdfViewer.
  74. static const QString &getPdfViewerTemplate();
  75. static void updatePdfViewerTemplate(const PdfViewerConfig &p_config, bool p_force = false);
  76. static const QString &getPdfViewerTemplatePath();
  77. // For MindMapEditor.
  78. static const QString &getMindMapEditorTemplate();
  79. static void updateMindMapEditorTemplate(const MindMapEditorConfig &p_config, bool p_force = false);
  80. private:
  81. struct Template
  82. {
  83. int m_revision = -1;
  84. QString m_template;
  85. QString m_templatePath;
  86. };
  87. static QString errorPage();
  88. static void generatePdfViewerTemplate(const PdfViewerConfig &p_config, Template& p_template);
  89. static void generateMindMapEditorTemplate(const MindMapEditorConfig &p_config,
  90. const QString &p_webStyleSheetFile,
  91. Template& p_template);
  92. static Template s_markdownViewerTemplate;
  93. static Template s_pdfViewerTemplate;
  94. static Template s_mindMapEditorTemplate;
  95. };
  96. }
  97. #endif // HTMLTEMPLATEHELPER_H