diff --git a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json index eb0832d0e..edcebed7c 100644 --- a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json +++ b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Main.json @@ -15,6 +15,16 @@ "settings": "JSON.json", "filemask": "*.json" }, + { + "name": "Markdown", + "settings": "Markdown.json", + "filemask": "*.md, *.markdown" + }, + { + "name": "XML", + "settings": "XML.json", + "filemask": "*.xml, *.plist" + }, { "name": "YAML", "settings": "YAML.json", diff --git a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Markdown.json b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Markdown.json new file mode 100644 index 000000000..e6c04299b --- /dev/null +++ b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/Markdown.json @@ -0,0 +1,31 @@ +{ + "lexer": "markdown", + "wordlists": [], + "properties": { + "lexer.markdown.header.eolfill": "1" + }, + "mapping": { + "SCE_MARKDOWN_DEFAULT": "default", + "SCE_MARKDOWN_LINE_BEGIN": "default", + "SCE_MARKDOWN_STRONG1": "number", + "SCE_MARKDOWN_STRONG2": "number", + "SCE_MARKDOWN_EM1": "comment", + "SCE_MARKDOWN_EM2": "comment", + "SCE_MARKDOWN_HEADER1": "keyword", + "SCE_MARKDOWN_HEADER2": "keyword", + "SCE_MARKDOWN_HEADER3": "keyword", + "SCE_MARKDOWN_HEADER4": "keyword", + "SCE_MARKDOWN_HEADER5": "keyword", + "SCE_MARKDOWN_HEADER6": "keyword", + "SCE_MARKDOWN_PRECHAR": "default", + "SCE_MARKDOWN_ULIST_ITEM": "preprocessor", + "SCE_MARKDOWN_OLIST_ITEM": "preprocessor", + "SCE_MARKDOWN_BLOCKQUOTE": "identifier", + "SCE_MARKDOWN_STRIKEOUT": "operator", + "SCE_MARKDOWN_HRULE": "default", + "SCE_MARKDOWN_LINK": "string", + "SCE_MARKDOWN_CODE": "string", + "SCE_MARKDOWN_CODE2": "string", + "SCE_MARKDOWN_CODEBK": "string" + } +} diff --git a/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json new file mode 100644 index 000000000..6176fb7f3 --- /dev/null +++ b/Source/NimbleCommander/NimbleCommander/Resources/SyntaxHighlighting/XML.json @@ -0,0 +1,35 @@ +{ + "lexer": "xml", + "wordlists": [], + "properties": { + }, + "mapping": { + "SCE_H_DEFAULT": "default", + "SCE_H_TAG": "keyword", + "SCE_H_TAGUNKNOWN": "comment", + "SCE_H_ATTRIBUTE": "identifier", + "SCE_H_ATTRIBUTEUNKNOWN": "comment", + "SCE_H_NUMBER": "number", + "SCE_H_DOUBLESTRING": "string", + "SCE_H_SINGLESTRING": "string", + "SCE_H_OTHER": "operator", + "SCE_H_COMMENT": "comment", + "SCE_H_ENTITY": "identifier", + "SCE_H_TAGEND": "default", + "SCE_H_XMLSTART": "comment", + "SCE_H_XMLEND": "comment", + "SCE_H_CDATA": "string", + "SCE_H_QUESTION": "preprocessor", + "SCE_H_VALUE": "default", + "SCE_H_SGML_DEFAULT": "default", + "SCE_H_SGML_COMMAND": "preprocessor", + "SCE_H_SGML_1ST_PARAM": "preprocessor", + "SCE_H_SGML_DOUBLESTRING": "string", + "SCE_H_SGML_SIMPLESTRING": "string", + "SCE_H_SGML_ERROR": "comment", + "SCE_H_SGML_SPECIAL": "identifier", + "SCE_H_SGML_ENTITY": "identifier", + "SCE_H_SGML_COMMENT": "comment", + "SCE_H_SGML_BLOCK_DEFAULT": "default" + } +} diff --git a/Source/Viewer/include/Viewer/Highlighting/Document.h b/Source/Viewer/include/Viewer/Highlighting/Document.h index 9f45f93a3..871a114c2 100644 --- a/Source/Viewer/include/Viewer/Highlighting/Document.h +++ b/Source/Viewer/include/Viewer/Highlighting/Document.h @@ -72,6 +72,7 @@ class Document final : public Scintilla::IDocument std::string_view m_Text; std::vector m_Lines; std::vector m_LineStates; + std::vector m_LineLevels; std::vector m_Styles; Sci_Position m_StylingPosition = 0; }; diff --git a/Source/Viewer/source/Highlighting/Document.cpp b/Source/Viewer/source/Highlighting/Document.cpp index b9d2e3ccd..9f2b09e9b 100644 --- a/Source/Viewer/source/Highlighting/Document.cpp +++ b/Source/Viewer/source/Highlighting/Document.cpp @@ -9,6 +9,7 @@ namespace nc::viewer::hl { static constexpr char g_CR = '\x0D'; static constexpr char g_LF = '\x0A'; +static constexpr int g_BaseLevel = 0x400; static constinit std::array g_UTF8Lengths = []() { std::array lengths = {}; @@ -90,6 +91,7 @@ Document::Document(const std::string_view _text) : m_Text(_text), m_Styles(_text } m_LineStates.resize(m_Lines.size() + 1); + m_LineLevels.resize(m_Lines.size(), g_BaseLevel); } Document::~Document() = default; @@ -109,7 +111,7 @@ bool Document::IsDBCSLeadByte(char) const noexcept return false; } -char Document::StyleAt(Sci_Position _position) const noexcept +char Document::StyleAt(const Sci_Position _position) const noexcept { if( _position < 0 || _position >= static_cast(m_Text.length()) ) { return 0; @@ -117,24 +119,26 @@ char Document::StyleAt(Sci_Position _position) const noexcept return m_Styles[_position]; } -int Document::GetLevel(Sci_Position /*_line*/) const noexcept +int Document::GetLevel(const Sci_Position _line) const noexcept { - abort(); - return 0; + return _line >= 0 && static_cast(_line) < m_LineLevels.size() ? m_LineLevels[_line] : g_BaseLevel; } -int Document::SetLevel(Sci_Position /*_line*/, int /*_level*/) noexcept +int Document::SetLevel(const Sci_Position _line, const int _level) noexcept { - abort(); - return 0; + if( _line >= 0 && static_cast(_line) < m_LineLevels.size() ) { + m_LineLevels[_line] = _level; + return _level; + } + return g_BaseLevel; } -int Document::GetLineState(Sci_Position _line) const noexcept +int Document::GetLineState(const Sci_Position _line) const noexcept { return m_LineStates.at(_line); } -int Document::SetLineState(Sci_Position _line, int _state) noexcept +int Document::SetLineState(const Sci_Position _line, const int _state) noexcept { return m_LineStates.at(_line) = _state; } @@ -145,9 +149,9 @@ int Document::GetLineIndentation(Sci_Position /*_line*/) noexcept return 0; } -Sci_Position Document::GetRelativePosition(Sci_Position _position, Sci_Position _offset) const noexcept +Sci_Position Document::GetRelativePosition(const Sci_Position _position, const Sci_Position _offset) const noexcept { - return _position + _offset; + return _position + _offset; // TODO: is _offset in bytes or in code units? } int Document::GetCharacterAndWidth(Sci_Position _position, Sci_Position *_width) const noexcept