aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2011-08-26 08:57:10 +1000
committernyamatongwe <devnull@localhost>2011-08-26 08:57:10 +1000
commit2ee57393e9f6b240b76184d6d7f52c184025f091 (patch)
tree846f37f7e58b8eb6c8c9bea4430709ae9893d0a2
parente9c97ea9bc0420a20f340dfd6b17ca1cf78a7308 (diff)
downloadscintilla-mirror-2ee57393e9f6b240b76184d6d7f52c184025f091.tar.gz
Fixing Markdown lexer to not change state inside term. Bug #3398184.
From Eric Promislow at ActiveState.
-rw-r--r--lexers/LexMarkdown.cxx23
1 files changed, 15 insertions, 8 deletions
diff --git a/lexers/LexMarkdown.cxx b/lexers/LexMarkdown.cxx
index 393712033..a92697707 100644
--- a/lexers/LexMarkdown.cxx
+++ b/lexers/LexMarkdown.cxx
@@ -113,6 +113,10 @@ static bool HasPrevLineContent(StyleContext &sc) {
return false;
}
+static bool AtTermStart(StyleContext &sc) {
+ return sc.currentPos == 0 || isspacechar(sc.chPrev);
+}
+
static bool IsValidHrule(const unsigned int endPos, StyleContext &sc) {
int c, count = 1;
unsigned int i = 0;
@@ -373,35 +377,38 @@ static void ColorizeMarkdownDoc(unsigned int startPos, int length, int initStyle
}
}
// Code - also a special case for alternate inside spacing
- if (sc.Match("``") && sc.GetRelative(3) != ' ') {
+ if (sc.Match("``") && sc.GetRelative(3) != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_CODE2);
sc.Forward();
}
- else if (sc.ch == '`' && sc.chNext != ' ') {
+ else if (sc.ch == '`' && sc.chNext != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_CODE);
}
// Strong
- else if (sc.Match("**") && sc.GetRelative(2) != ' ') {
+ else if (sc.Match("**") && sc.GetRelative(2) != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_STRONG1);
sc.Forward();
}
- else if (sc.Match("__") && sc.GetRelative(2) != ' ') {
+ else if (sc.Match("__") && sc.GetRelative(2) != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_STRONG2);
sc.Forward();
}
// Emphasis
- else if (sc.ch == '*' && sc.chNext != ' ')
+ else if (sc.ch == '*' && sc.chNext != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_EM1);
- else if (sc.ch == '_' && sc.chNext != ' ')
+ }
+ else if (sc.ch == '_' && sc.chNext != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_EM2);
+ }
// Strikeout
- else if (sc.Match("~~") && sc.GetRelative(2) != ' ') {
+ else if (sc.Match("~~") && sc.GetRelative(2) != ' ' && AtTermStart(sc)) {
sc.SetState(SCE_MARKDOWN_STRIKEOUT);
sc.Forward();
}
// Beginning of line
- else if (IsNewline(sc.ch))
+ else if (IsNewline(sc.ch)) {
sc.SetState(SCE_MARKDOWN_LINE_BEGIN);
+ }
}
// Advance if not holding back the cursor for this iteration.
if (!freezeCursor)