1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef CODEMARKER_H |
5 | #define CODEMARKER_H |
6 | |
7 | #include "atom.h" |
8 | #include "sections.h" |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class CodeMarker |
13 | { |
14 | public: |
15 | CodeMarker(); |
16 | virtual ~CodeMarker(); |
17 | |
18 | virtual void initializeMarker(); |
19 | virtual void terminateMarker(); |
20 | virtual bool recognizeCode(const QString & /*code*/) { return true; } |
21 | virtual bool recognizeExtension(const QString & /*extension*/) { return true; } |
22 | virtual bool recognizeLanguage(const QString & /*language*/) { return false; } |
23 | [[nodiscard]] virtual Atom::AtomType atomType() const { return Atom::Code; } |
24 | virtual QString markedUpCode(const QString &code, const Node * /*relative*/, |
25 | const Location & /*location*/) |
26 | { |
27 | return protect(string: code); |
28 | } |
29 | virtual QString markedUpSynopsis(const Node * /*node*/, const Node * /*relative*/, |
30 | Section::Style /*style*/) |
31 | { |
32 | return QString(); |
33 | } |
34 | virtual QString markedUpQmlItem(const Node *, bool) { return QString(); } |
35 | virtual QString markedUpName(const Node * /*node*/) { return QString(); } |
36 | virtual QString markedUpEnumValue(const QString & /*enumValue*/, const Node * /*relative*/) |
37 | { |
38 | return QString(); |
39 | } |
40 | virtual QString markedUpInclude(const QString & /*include*/) { return QString(); } |
41 | |
42 | static void initialize(); |
43 | static void terminate(); |
44 | static CodeMarker *markerForCode(const QString &code); |
45 | static CodeMarker *markerForFileName(const QString &fileName); |
46 | static CodeMarker *markerForLanguage(const QString &lang); |
47 | static const Node *nodeForString(const QString &string); |
48 | static QString stringForNode(const Node *node); |
49 | static QString (const Node *node, Section::Style style); |
50 | |
51 | QString typified(const QString &string, bool trailingSpace = false); |
52 | |
53 | protected: |
54 | static QString protect(const QString &string); |
55 | static void appendProtectedString(QString *output, QStringView str); |
56 | QString taggedNode(const Node *node); |
57 | QString taggedQmlNode(const Node *node); |
58 | QString linkTag(const Node *node, const QString &body); |
59 | |
60 | private: |
61 | static QString s_defaultLang; |
62 | static QList<CodeMarker *> s_markers; |
63 | }; |
64 | |
65 | QT_END_NAMESPACE |
66 | |
67 | #endif |
68 | |