wxMaxima
Loading...
Searching...
No Matches
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{
47protected:
48 Configuration *m_configuration = NULL;
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;
68public:
69 explicit MarkDownParser(Configuration *cfg);
70
71 wxString MarkDown(wxString str);
72
74 const replaceList &RegexReplaceList() const
75 { return regexReplaceList; }
76
77private:
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{
91public:
92 explicit MarkDownTeX(Configuration *cfg);
93
94private:
95 virtual wxString quoteBegin() override
96 { return wxS("\\begin{quote}\n"); }
97
98 virtual wxString quoteEnd() override
99 { return wxS("\\end{quote}\n"); }
100
101 virtual wxString quoteChar() override
102 { return wxS("\\ensuremath{>}"); }
103
104 virtual wxString itemizeBegin() override
105 { return wxS("\\begin{itemize}\n"); }
106
107 virtual wxString itemizeEnd() override
108 { return wxS("\\end{itemize}\n"); }
109
110 virtual wxString itemizeItem() override
111 { return wxS("\\item "); }
112
113 virtual wxString itemizeEndItem() override
114 { return wxEmptyString; }
115
116 virtual wxString NewLine() override
117 { return wxS("\n\n"); }
118};
119
122{
123public:
124 explicit MarkDownHTML(Configuration *cfg);
125
126private:
127 virtual wxString quoteChar() override
128 { return wxS("&gt;"); }
129
130 virtual wxString quoteBegin() override
131 { return wxS("<blockquote>\n"); }
132
133 virtual wxString quoteEnd() override
134 { return wxS("</blockquote>\n"); }
135
136 virtual wxString itemizeBegin() override
137 { return wxS("<ul>\n"); }
138
139 virtual wxString itemizeEnd() override
140 { return wxS("</ul>\n"); }
141
142 virtual wxString itemizeItem() override
143 { return wxS("<li>"); }
144
145 virtual wxString itemizeEndItem() override
146 { return wxS("</li>\n"); }
147
148 virtual wxString NewLine() override
149 { return wxS("<br/>"); }
150};
151
152#endif // MARKDOWN_H
The configuration storage for the current worksheet.
Definition: Configuration.h:85
A markdown parser for HTML.
Definition: MarkDown.h:122
A pair of a regExp and a string that has to replace the matches.
Definition: MarkDown.h:52
A generic markdown Parser.
Definition: MarkDown.h:46
const replaceList & RegexReplaceList() const
A list of things we want to replace.
Definition: MarkDown.h:74
A markdown parser for TeX.
Definition: MarkDown.h:90