manual: added documentation about replacement of 'untitled.ext' with filename (#1804)
[geany-mirror.git] / ctags / parsers / markdown.c
blob629925c4e31b0025d866a4d988fe5e6e94f441f5
1 /*
3 * Copyright (c) 2009, Jon Strait
5 * This source code is released for free distribution under the terms of the
6 * GNU General Public License.
8 * This module contains functions for generating tags for Markdown files.
9 */
12 * INCLUDE FILES
14 #include "general.h" /* must always come first */
16 #include <ctype.h>
17 #include <string.h>
19 #include "parse.h"
20 #include "read.h"
21 #include "vstring.h"
22 #include "routines.h"
25 * DATA DEFINITIONS
28 static kindOption MarkdownKinds[] = {
29 { true, 'v', "variable", "sections" }
33 * FUNCTION DEFINITIONS
36 /* checks if str is all the same character */
37 static bool issame(const char *str)
39 char first = *str;
41 while (*(++str))
43 if (*str && *str != first)
44 return false;
46 return true;
49 static void makeMarkdownTag (const vString* const name, bool name_before)
51 tagEntryInfo e;
52 initTagEntry (&e, vStringValue(name), &(MarkdownKinds [0]));
54 if (name_before)
55 e.lineNumber--; /* we want the line before the underline chars */
57 makeTagEntry(&e);
61 static void findMarkdownTags (void)
63 vString *name = vStringNew();
64 const unsigned char *line;
66 while ((line = readLineFromInputFile()) != NULL)
68 int name_len = vStringLength(name);
70 /* underlines must be the same length or more */
71 if (name_len > 0 && (line[0] == '=' || line[0] == '-') && issame((const char*) line))
73 makeMarkdownTag(name, true);
75 else if (line[0] == '#') {
76 vStringClear(name);
77 vStringCatS(name, (const char *) line);
78 makeMarkdownTag(name, false);
80 else {
81 vStringClear (name);
82 if (! isspace(*line))
83 vStringCatS(name, (const char*) line);
86 vStringDelete (name);
89 extern parserDefinition* MarkdownParser (void)
91 static const char *const patterns [] = { "*.md", NULL };
92 static const char *const extensions [] = { "md", NULL };
93 parserDefinition* const def = parserNew ("Markdown");
95 def->kinds = MarkdownKinds;
96 def->kindCount = ARRAY_SIZE (MarkdownKinds);
97 def->patterns = patterns;
98 def->extensions = extensions;
99 def->parser = findMarkdownTags;
100 return def;