wxMaxima
MarkDown.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2015-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // SPDX-License-Identifier: GPL-2.0+
21 
28 #ifndef MARKDOWN_H
29 #define MARKDOWN_H
30 
31 #include "precomp.h"
32 #include <wx/wx.h>
33 #include <wx/string.h>
34 #include <wx/config.h>
35 #include <wx/tokenzr.h>
36 #include <wx/regex.h>
37 #include <list>
38 #include <memory>
39 #include "Configuration.h"
40 
46 {
47 protected:
48  Configuration *m_configuration;
49 
51  class RegexReplacer : public wxRegEx
52  {
53  public:
54  RegexReplacer(wxString from, const wxString &to) :
55  wxRegEx(from),
56  replaceBy(to)
57  {}
58 
59  void DoReplace(wxString &line) const
60  { Replace(&line, replaceBy); }
61 
62  private:
63  wxString replaceBy;
64  };
65 
66  typedef std::list<RegexReplacer> replaceList;
67  replaceList regexReplaceList;
68 public:
69  explicit MarkDownParser(Configuration *cfg);
70 
71  wxString MarkDown(wxString str);
72 
74  const replaceList &RegexReplaceList() const
75  { return regexReplaceList; }
76 
77 private:
78  virtual wxString itemizeBegin()=0;
79  virtual wxString itemizeEnd()=0;
80  virtual wxString quoteChar()=0;
81  virtual wxString quoteBegin()=0;
82  virtual wxString quoteEnd()=0;
83  virtual wxString itemizeItem()=0;
84  virtual wxString itemizeEndItem()=0;
85  virtual wxString NewLine()=0;
86 };
87 
90 {
91 public:
92  explicit MarkDownTeX(Configuration *cfg);
93 
94 private:
95  virtual wxString quoteBegin() override
96  { return wxT("\\begin{quote}\n"); }
97 
98  virtual wxString quoteEnd() override
99  { return wxT("\\end{quote}\n"); }
100 
101  virtual wxString quoteChar() override
102  { return wxT("\\ensuremath{>}"); }
103 
104  virtual wxString itemizeBegin() override
105  { return wxT("\\begin{itemize}\n"); }
106 
107  virtual wxString itemizeEnd() override
108  { return wxT("\\end{itemize}\n"); }
109 
110  virtual wxString itemizeItem() override
111  { return wxT("\\item "); }
112 
113  virtual wxString itemizeEndItem() override
114  { return wxEmptyString; }
115 
116  virtual wxString NewLine() override
117  { return wxT("\n\n"); }
118 
119 };
120 
123 {
124 public:
125  explicit MarkDownHTML(Configuration *cfg);
126 
127 private:
128  virtual wxString quoteChar() override
129  { return wxT("&gt;"); }
130 
131  virtual wxString quoteBegin() override
132  { return wxT("<blockquote>\n"); }
133 
134  virtual wxString quoteEnd() override
135  { return wxT("</blockquote>\n"); }
136 
137  virtual wxString itemizeBegin() override
138  { return wxT("<ul>\n"); }
139 
140  virtual wxString itemizeEnd() override
141  { return wxT("</ul>\n"); }
142 
143  virtual wxString itemizeItem() override
144  { return wxT("<li>"); }
145 
146  virtual wxString itemizeEndItem() override
147  { return wxT("</li>\n"); }
148 
149  virtual wxString NewLine() override
150  { return wxT("<br/>"); }
151 };
152 
153 #endif // MARKDOWN_H
MarkDownTeX
A markdown parser for TeX.
Definition: MarkDown.h:89
MarkDownParser::RegexReplacer
A pair of a regExp and a string that has to replace the matches.
Definition: MarkDown.h:51
MarkDownHTML
A markdown parser for HTML.
Definition: MarkDown.h:122
Configuration
Definition: Configuration.h:83
MarkDownParser
Definition: MarkDown.h:45
MarkDownParser::RegexReplaceList
const replaceList & RegexReplaceList() const
A list of things we want to replace.
Definition: MarkDown.h:74