| 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 | static void initialize(); |
| 41 | static void terminate(); |
| 42 | static CodeMarker *markerForCode(const QString &code); |
| 43 | static CodeMarker *markerForFileName(const QString &fileName); |
| 44 | static CodeMarker *markerForLanguage(const QString &lang); |
| 45 | static QString (const Node *node, Section::Style style); |
| 46 | |
| 47 | QString typified(const QString &string, bool trailingSpace = false); |
| 48 | |
| 49 | protected: |
| 50 | static QString protect(const QString &string); |
| 51 | static void appendProtectedString(QString *output, QStringView str); |
| 52 | QString taggedNode(const Node *node); |
| 53 | QString taggedQmlNode(const Node *node); |
| 54 | QString linkTag(const Node *node, const QString &body); |
| 55 | |
| 56 | private: |
| 57 | static QString s_defaultLang; |
| 58 | static QList<CodeMarker *> s_markers; |
| 59 | }; |
| 60 | |
| 61 | QT_END_NAMESPACE |
| 62 | |
| 63 | #endif |
| 64 | |