Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added syntax settings for Markdown and XML #308

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions Source/Viewer/include/Viewer/Highlighting/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Document final : public Scintilla::IDocument
std::string_view m_Text;
std::vector<uint32_t> m_Lines;
std::vector<int> m_LineStates;
std::vector<int> m_LineLevels;
std::vector<char> m_Styles;
Sci_Position m_StylingPosition = 0;
};
Expand Down
26 changes: 15 additions & 11 deletions Source/Viewer/source/Highlighting/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 256> g_UTF8Lengths = []() {
std::array<uint8_t, 256> lengths = {};
Expand Down Expand Up @@ -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;
Expand All @@ -109,32 +111,34 @@ 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<long>(m_Text.length()) ) {
return 0;
}
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<size_t>(_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<size_t>(_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;
}
Expand All @@ -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
Expand Down
Loading