Version bump.
[geany-mirror.git] / tagmanager / markdown.c
blobe5c669443e7a454d75ae5af5176ba5e14bbac8f2
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"
24 * DATA DEFINITIONS
27 static kindOption MarkdownKinds[] = {
28 { TRUE, 'v', "variable", "sections" }
32 * FUNCTION DEFINITIONS
35 /* checks if str is all the same character */
36 static boolean issame(const char *str)
38 char first = *str;
40 while (*(++str))
42 if (*str && *str != first)
43 return FALSE;
45 return TRUE;
48 static void makeMarkdownTag (const vString* const name, boolean name_before)
50 tagEntryInfo e;
51 initTagEntry (&e, vStringValue(name));
53 if (name_before)
54 e.lineNumber--; /* we want the line before the underline chars */
55 e.kindName = "variable";
56 e.kind = 'v';
58 makeTagEntry(&e);
62 static void findMarkdownTags (void)
64 vString *name = vStringNew();
65 const unsigned char *line;
67 while ((line = fileReadLine()) != NULL)
69 int name_len = vStringLength(name);
71 /* underlines must be the same length or more */
72 if (name_len > 0 && (line[0] == '=' || line[0] == '-') && issame((const char*) line))
74 makeMarkdownTag(name, TRUE);
76 else if (line[0] == '#') {
77 vStringClear(name);
78 vStringCatS(name, (const char *) line);
79 vStringTerminate(name);
80 makeMarkdownTag(name, FALSE);
82 else {
83 vStringClear (name);
84 if (! isspace(*line))
85 vStringCatS(name, (const char*) line);
86 vStringTerminate(name);
89 vStringDelete (name);
92 extern parserDefinition* MarkdownParser (void)
94 static const char *const patterns [] = { "*.md", NULL };
95 static const char *const extensions [] = { "md", NULL };
96 parserDefinition* const def = parserNew ("Markdown");
98 def->kinds = MarkdownKinds;
99 def->kindCount = KIND_COUNT (MarkdownKinds);
100 def->patterns = patterns;
101 def->extensions = extensions;
102 def->parser = findMarkdownTags;
103 return def;