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 */
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
)
43 if (*str
&& *str
!= first
)
49 static void makeMarkdownTag (const vString
* const name
, bool name_before
)
52 initTagEntry (&e
, vStringValue(name
), &(MarkdownKinds
[0]));
55 e
.lineNumber
--; /* we want the line before the underline chars */
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] == '#') {
77 vStringCatS(name
, (const char *) line
);
78 makeMarkdownTag(name
, false);
83 vStringCatS(name
, (const char*) line
);
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
;