@@ -162,12 +162,14 @@ static vString *get_heading(const int kind, const unsigned char *line,
162162}
163163
164164
165- static bool is_indented (const unsigned char * line , int line_len )
165+ static int get_first_char_pos (const unsigned char * line , int line_len , bool * indented )
166166{
167167 int indent = 0 ;
168- for (int i = 0 ; i < line_len && isspace (line [i ]) && indent < 4 ; i ++ )
168+ int i ;
169+ for (i = 0 ; i < line_len && isspace (line [i ]); i ++ )
169170 indent += line [i ] == '\t' ? 4 : 1 ;
170- return indent >= 4 ;
171+ * indented = indent >= 4 ;
172+ return i ;
171173}
172174
173175
@@ -197,23 +199,25 @@ static void findMarkdownTags(void)
197199 {
198200 int line_len = strlen ((const char * ) line );
199201 bool line_processed = false;
202+ bool indented ;
203+ int pos = get_first_char_pos (line , line_len , & indented );
200204
201- for (int i = 0 ; i < 2 ; i ++ )
205+ for (int i = 0 ; i < 2 && ! indented ; i ++ )
202206 {
203207 char code_chars [] = { '`' , '~' };
204208 char c = code_chars [i % 2 ];
205209 char other_c = code_chars [(i + 1 ) % 2 ];
206210
207211 if (in_code_char != other_c && line_len >= 3 &&
208- line [0 ] == c && line [1 ] == c && line [2 ] == c )
212+ line [pos ] == c && line [pos + 1 ] == c && line [pos + 2 ] == c )
209213 {
210214 in_code_char = in_code_char ? 0 : c ;
211215 if (in_code_char )
212216 {
213217 startSourceLineNumber = getSourceLineNumber ();
214218 startLineNumber = getInputLineNumber ();
215219 vStringClear (codeLang );
216- vStringCatS (codeLang , (const char * )(line + 3 ));
220+ vStringCatS (codeLang , (const char * )(line + pos + 3 ));
217221 vStringStripLeading (codeLang );
218222 vStringStripTrailing (codeLang );
219223 }
@@ -234,23 +238,23 @@ static void findMarkdownTags(void)
234238 line_processed = true;
235239
236240 /* code block using indent */
237- else if (is_indented ( line , line_len ) )
241+ else if (indented )
238242 line_processed = true;
239243
240244 /* if it's a title underline, or a delimited block marking character */
241- else if (line [0 ] == '=' || line [0 ] == '-' || line [0 ] == '#' )
245+ else if (line [pos ] == '=' || line [pos ] == '-' || line [pos ] == '#' )
242246 {
243247 int n_same ;
244- for (n_same = 1 ; line [n_same ] == line [0 ]; ++ n_same );
248+ for (n_same = 1 ; line [n_same ] == line [pos ]; ++ n_same );
245249
246250 /* is it a two line title */
247- if (line [0 ] == '=' || line [0 ] == '-' )
251+ if (line [pos ] == '=' || line [pos ] == '-' )
248252 {
249- char marker [2 ] = { line [0 ], '\0' };
250- int kind = line [0 ] == '=' ? K_CHAPTER : K_SECTION ;
253+ char marker [2 ] = { line [pos ], '\0' };
254+ int kind = line [pos ] == '=' ? K_CHAPTER : K_SECTION ;
251255 bool whitespace_terminated = true;
252256
253- for (int i = n_same ; i < line_len ; i ++ )
257+ for (int i = pos + n_same ; i < line_len ; i ++ )
254258 {
255259 if (!isspace (line [i ]))
256260 {
@@ -265,7 +269,7 @@ static void findMarkdownTags(void)
265269 makeSectionMarkdownTag (prev_line , kind , marker );
266270 }
267271 /* otherwise is it a one line title */
268- else if (line [0 ] == '#' && n_same <= K_SECTION_COUNT && isspace (line [n_same ]))
272+ else if (line [pos ] == '#' && n_same <= K_SECTION_COUNT && isspace (line [n_same ]))
269273 {
270274 int kind = n_same - 1 ;
271275 bool delimited = false;
0 commit comments