File indexing completed on 2024-12-22 04:48:10
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2023 Louis Schul <schul9louis@gmail.com> 0004 */ 0005 0006 // CREDIT TO ORIGINAL IDEA: https://marked.js.org/ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 #include <QSet> 0012 0013 #include "../plugins/pluginHelper.h" 0014 #include "blockLexer.h" 0015 #include "inlineLexer.h" 0016 0017 class Parser : public QObject 0018 { 0019 Q_OBJECT 0020 Q_PROPERTY(QString notePath WRITE setNotePath) 0021 // NoteMapper 0022 Q_PROPERTY(QStringList headerInfo WRITE setHeaderInfo) 0023 Q_PROPERTY(QString headerLevel READ headerLevel CONSTANT) 0024 public: 0025 explicit Parser(QObject *parent = nullptr); 0026 0027 Q_INVOKABLE QString parse(QString src); 0028 0029 QString getNotePath() const; 0030 void setNotePath(const QString ¬ePath); 0031 QVector<QVariantMap> tokens; 0032 QMap<QString, QMap<QString, QString>> links; 0033 0034 PluginHelper *getPluginHelper() const; 0035 0036 // NoteMapper 0037 void setHeaderInfo(const QStringList &headerInfo); 0038 QString headerLevel() const; 0039 0040 Q_SIGNALS: 0041 // NoteMapper 0042 void newLinkedNotesInfos(const QSet<QStringList> &linkedNotesInfos); 0043 void noteHeadersSent(const QString ¬ePath, const QStringList ¬eHeaders); 0044 0045 public Q_SLOTS: 0046 // Syntax highlight 0047 void newHighlightStyle(); 0048 // PUML 0049 void pumlDarkChanged(); 0050 0051 private: 0052 QString tok(); 0053 QString parseText(); 0054 QString peekType() const; 0055 bool getNextToken(); 0056 0057 BlockLexer blockLexer = BlockLexer(this); 0058 InlineLexer inlineLexer = InlineLexer(this); 0059 PluginHelper *pluginHelper = new PluginHelper(this); 0060 0061 QString m_notePath; 0062 QVariantMap m_token; 0063 };