Cutelee 6.1.0
mediawikimarkupbuilder.cpp
1/*
2 This file is part of the Cutelee template system.
3
4 Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either version
9 2.1 of the Licence, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#include "mediawikimarkupbuilder.h"
22
23using namespace Cutelee;
24
25MediaWikiMarkupBuilder::MediaWikiMarkupBuilder() {}
26
27MediaWikiMarkupBuilder::~MediaWikiMarkupBuilder() {}
28
30{
31 m_text.append(QStringLiteral("'''"));
32}
34{
35 m_text.append(QStringLiteral("'''"));
36}
38{
39 m_text.append(QStringLiteral("''"));
40}
41void MediaWikiMarkupBuilder::endEmph() { m_text.append(QStringLiteral("''")); }
43{
44 m_text.append(QStringLiteral("<u>"));
45}
47{
48 m_text.append(QStringLiteral("</u>"));
49}
51{
52 m_text.append(QStringLiteral("<s>"));
53}
55{
56 m_text.append(QStringLiteral("</s>"));
57}
58
60{
61 m_text.append(QLatin1Char('\n'));
62}
63void MediaWikiMarkupBuilder::addNewline() { m_text.append(QLatin1Char('\n')); }
64
66 const QString &name)
67{
68 Q_UNUSED(name);
69 m_text.append(QStringLiteral("[%1 ").arg(href));
70}
71void MediaWikiMarkupBuilder::endAnchor() { m_text.append(QLatin1Char(']')); }
72
74{
75 switch (level) {
76 case 1:
77 m_text.append(QStringLiteral("= "));
78 break;
79 case 2:
80 m_text.append(QStringLiteral("== "));
81 break;
82 case 3:
83 m_text.append(QStringLiteral("=== "));
84 break;
85 case 4:
86 m_text.append(QStringLiteral("==== "));
87 break;
88 case 5:
89 m_text.append(QStringLiteral("===== "));
90 break;
91 case 6:
92 m_text.append(QStringLiteral("====== "));
93 break;
94 default:
95 break;
96 }
97}
98
100{
101 switch (level) {
102 case 1:
103 m_text.append(QStringLiteral(" =\n"));
104 break;
105 case 2:
106 m_text.append(QStringLiteral(" ==\n"));
107 break;
108 case 3:
109 m_text.append(QStringLiteral(" ===\n"));
110 break;
111 case 4:
112 m_text.append(QStringLiteral(" ====\n"));
113 break;
114 case 5:
115 m_text.append(QStringLiteral(" =====\n"));
116 break;
117 case 6:
118 m_text.append(QStringLiteral(" ======\n"));
119 break;
120 default:
121 break;
122 }
123}
124
125void MediaWikiMarkupBuilder::beginList(QTextListFormat::Style type)
126{
127 currentListItemStyles.append(type);
128 switch (type) {
129 case QTextListFormat::ListDisc:
130 case QTextListFormat::ListCircle:
131 case QTextListFormat::ListSquare:
132 case QTextListFormat::ListDecimal:
133 case QTextListFormat::ListLowerAlpha:
134 case QTextListFormat::ListUpperAlpha:
135 m_text.append(QLatin1Char('\n'));
136 break;
137 default:
138 break;
139 }
140}
141
143{
144 m_text.append(QLatin1Char('\n'));
145 currentListItemStyles.removeLast();
146}
147
149{
150 switch (currentListItemStyles.last()) {
151 case QTextListFormat::ListDisc:
152 case QTextListFormat::ListCircle:
153 case QTextListFormat::ListSquare:
154 m_text.append(QStringLiteral(
155 "* ")); // Unordered lists are all disc type in MediaWikiMarkup.
156 break;
157 case QTextListFormat::ListDecimal:
158 case QTextListFormat::ListLowerAlpha:
159 case QTextListFormat::ListUpperAlpha:
160 m_text.append(QStringLiteral("# "));
161 break;
162 default:
163 break;
164 }
165}
166
167void MediaWikiMarkupBuilder::endListItem() { m_text.append(QLatin1Char('\n')); }
168
170{
171 m_text.append(escape(text));
172}
173
175{
176 if (s.contains(QLatin1Char(
177 '<'))) { // TODO: This could contain more. "''" and "[" for example
178 return QStringLiteral("<nowiki>") + s + QStringLiteral("</nowiki>");
179 }
180 return s;
181}
182
184{
185 auto ret = m_text;
186 m_text.clear();
187 return ret;
188}
void appendLiteralText(const QString &text) override
void beginAnchor(const QString &href={}, const QString &name={}) override
const QString escape(const QString &s)
void beginList(QTextListFormat::Style type) override
The Cutelee namespace holds all public Cutelee API.
Definition Mainpage.dox:8