File indexing completed on 2024-10-27 04:39:16
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2024 Louis Schul <schul9louis@gmail.com> 0004 */ 0005 0006 #include "highlightParserUtils.h" 0007 0008 #include "logic/parser/renderer.h" 0009 0010 void HighlightParserUtils::clearInfo() 0011 { 0012 m_noteCodeBlocks.clear(); 0013 } 0014 0015 void HighlightParserUtils::clearPreviousInfo() 0016 { 0017 m_previousNoteCodeBlocks.clear(); 0018 } 0019 0020 void HighlightParserUtils::addToNoteCodeBlocks(const QString &codeBlock) 0021 { 0022 m_noteCodeBlocks.append(codeBlock); 0023 } 0024 0025 void HighlightParserUtils::newHighlightStyle() 0026 { 0027 m_newHighlightStyle = true; 0028 } 0029 0030 void HighlightParserUtils::preTok() 0031 { 0032 m_sameCodeBlocks = m_previousNoteCodeBlocks == m_noteCodeBlocks && !m_noteCodeBlocks.isEmpty(); 0033 if (!m_sameCodeBlocks || m_newHighlightStyle) { 0034 m_previousNoteCodeBlocks = m_noteCodeBlocks; 0035 m_previousHighlightedBlocks.clear(); 0036 m_newHighlightStyle = false; 0037 m_sameCodeBlocks = false; 0038 } 0039 m_currentBlockIndex = 0; 0040 } 0041 0042 QString HighlightParserUtils::renderCode(const bool highlight, const QString &_text, const QString &lang) 0043 { 0044 QString returnValue; 0045 if (m_sameCodeBlocks && highlight) { // Only the highlighted values are stored in here 0046 returnValue = m_previousHighlightedBlocks[m_currentBlockIndex]; 0047 m_currentBlockIndex++; 0048 } else { 0049 QString text = _text; 0050 returnValue = Renderer::code(text, lang, highlight); 0051 if (highlight) { // We want to store only the highlighted values 0052 m_previousHighlightedBlocks.append(returnValue); 0053 } 0054 } 0055 return returnValue; 0056 }