-
Notifications
You must be signed in to change notification settings - Fork 0
/
WikiDocument.h
54 lines (40 loc) · 1.25 KB
/
WikiDocument.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef WIKIDOCUMENT_H
#define WIKIDOCUMENT_H
#include <QTextDocument>
#include <QTextBlock>
#include <QTextBrowser>
#include <QTextDocumentFragment>
/**
* @brief A QTextDocument with support for wikisyntax
*/
class WikiDocument : public QTextDocument
{
Q_OBJECT
public:
WikiDocument(QObject *parent);
void toggleCollapsable(const QString &name);
QMap<QString, QString> m_collapsableHiddenNames;
QMap<QString, QString> m_collapsableShowNames;
QMap<QString, QTextDocumentFragment> m_hiddenFragments;
QHash<QString, bool> m_shownCollapsables;
};
class WikiBrowser : public QTextBrowser
{
Q_OBJECT
public:
WikiBrowser(QWidget *parent) : QTextBrowser(parent) { }
public slots:
void setSource(const QUrl &url) override;
protected:
QVariant loadResource(int type, const QUrl &name) override;
private:
bool preprocess(QString *content, int depth=0);
QString parseTable(const QString &tableText);
QString parseCollapsable(QString content);
QString getFileContents(const QString &filePath);
QString createHtml(const QString &path);
QMap<QString, QString> m_collapsableHiddenNames;
QMap<QString, QString> m_collapsableShowNames;
QHash<QString, bool> m_shownCollapsables;
};
#endif // WIKIDOCUMENT_H