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.
14 #include "general.h" /* must always come first */
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
)
42 if (*str
&& *str
!= first
)
48 static void makeMarkdownTag (const vString
* const name
, boolean name_before
)
51 initTagEntry (&e
, vStringValue(name
));
54 e
.lineNumber
--; /* we want the line before the underline chars */
55 e
.kindName
= "variable";
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] == '#') {
78 vStringCatS(name
, (const char *) line
);
79 vStringTerminate(name
);
80 makeMarkdownTag(name
, FALSE
);
85 vStringCatS(name
, (const char*) line
);
86 vStringTerminate(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
;