~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to scintilla/LexMarkdown.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  there is a following blank line issue that can't be ignored, 
19
19
 *  explained in the next paragraph. Embedded HTML and code 
20
20
 *  blocks would be better supported with language specific 
21
 
 *  highlighting; something Scintilla isn't really architected 
22
 
 *  to support yet.
 
21
 *  highlighting.
23
22
 * 
24
23
 *  The highlighting aims to accurately reflect correct syntax,
25
24
 *  but a few restrictions are relaxed. Delimited code blocks are
30
29
 * 
31
30
 *  Written by Jon Strait - jstrait@moonloop.net
32
31
 *
33
 
 *   This source code is released for free distribution under the
34
 
 *   terms of the GNU General Public License.
 
32
 *  The License.txt file describes the conditions under which this
 
33
 *  software may be distributed.
35
34
 *
36
35
 *****************************************************************/
37
36
 
59
58
}
60
59
 
61
60
// True if can follow ch down to the end with possibly trailing whitespace
62
 
static bool FollowToLineEnd(const int ch, const int state, const int endPos, StyleContext &sc) {
63
 
    int i = 0;
 
61
static bool FollowToLineEnd(const int ch, const int state, const unsigned int endPos, StyleContext &sc) {
 
62
    unsigned int i = 0;
64
63
    while (sc.GetRelative(++i) == ch)
65
64
        ;
66
65
    // Skip over whitespace
78
77
// Set the state on text section from current to length characters, 
79
78
// then set the rest until the newline to default, except for any characters matching token
80
79
static void SetStateAndZoom(const int state, const int length, const int token, StyleContext &sc) {
81
 
    int i = 0;
82
80
    sc.SetState(state);
83
81
    sc.Forward(length);
84
82
    sc.SetState(SCE_MARKDOWN_DEFAULT);
85
83
    sc.Forward();
 
84
    bool started = false;
86
85
    while (sc.More() && !IsNewline(sc.ch)) {
87
 
        bool started = false;
88
86
        if (sc.ch == token && !started) {
89
87
            sc.SetState(state);
90
88
            started = true;
113
111
    return false;
114
112
}
115
113
 
116
 
static bool IsValidHrule(const int endPos, StyleContext &sc) {
117
 
    int c, i = 0, count = 1;
 
114
static bool IsValidHrule(const unsigned int endPos, StyleContext &sc) {
 
115
    int c, count = 1;
 
116
    unsigned int i = 0;
118
117
    while (++i) {
119
118
        c = sc.GetRelative(i);
120
119
        if (c == sc.ch) 
131
130
            }
132
131
            else {
133
132
                sc.SetState(SCE_MARKDOWN_DEFAULT);
134
 
                return false;
 
133
                return false;
135
134
            }
136
135
        }
137
136
    }
138
 
}
139
 
 
140
 
// Only consume if already valid.  Doesn't work for delimiting multiple lines.
141
 
static void ConsumeEnd(const int state, const int origPos, const int endPos, 
142
 
        const char *token, StyleContext &sc) {
143
 
    int targetPos;
144
 
    while (sc.currentPos + 1 < endPos) {
145
 
        sc.Forward();
146
 
        if (sc.Match(token) && sc.chPrev != '\\' && sc.chPrev != ' ') {
147
 
            targetPos = sc.currentPos + strlen(token);
148
 
            sc.currentPos = origPos;
149
 
            sc.SetState(state);
150
 
            sc.Forward(targetPos - origPos);
151
 
            sc.SetState(SCE_MARKDOWN_DEFAULT);
152
 
            break;
153
 
        }
154
 
    }
 
137
    return false;
155
138
}
156
139
 
157
140
static void ColorizeMarkdownDoc(unsigned int startPos, int length, int initStyle,
158
 
                               WordList *keywordlists[], Accessor &styler) {
159
 
 
160
 
    int digitCount = 0;
161
 
    int endPos = startPos + length;
162
 
    int precharCount;
 
141
                               WordList **, Accessor &styler) {
 
142
    unsigned int endPos = startPos + length;
 
143
    int precharCount = 0;
163
144
    // Don't advance on a new loop iteration and retry at the same position.
164
145
    // Useful in the corner case of having to start at the beginning file position
165
146
    // in the default state.
330
311
            }
331
312
            // Ordered list
332
313
            else if (IsADigit(sc.ch)) {
333
 
                digitCount = 0;
 
314
                int digitCount = 0;
334
315
                while (IsADigit(sc.GetRelative(++digitCount)))
335
316
                    ;
336
317
                if (sc.GetRelative(digitCount) == '.' && 
354
335
        
355
336
        // New state anywhere in doc
356
337
        if (sc.state == SCE_MARKDOWN_DEFAULT) {
357
 
            int origPos = sc.currentPos;
358
338
            if (sc.atLineStart && sc.ch == '#') {
359
339
                sc.SetState(SCE_MARKDOWN_LINE_BEGIN);
360
340
                freezeCursor = true;
430
410
}
431
411
 
432
412
LexerModule lmMarkdown(SCLEX_MARKDOWN, ColorizeMarkdownDoc, "markdown");
433