rdiscountwl 1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+
2
+ /*
3
+ * github_flavoured -- implement the obnoxious "returns are hard newlines"
4
+ * feature in github flavoured markdown.
5
+ *
6
+ * Copyright (C) 2012 David L Parsons.
7
+ * The redistribution terms are provided in the COPYRIGHT file that must
8
+ * be distributed with this source code.
9
+ */
10
+ #include "config.h"
11
+ #include <stdio.h>
12
+ #include <stdlib.h>
13
+ #include <ctype.h>
14
+
15
+ #include "cstring.h"
16
+ #include "markdown.h"
17
+ #include "amalloc.h"
18
+
19
+ /* build a Document from any old input.
20
+ */
21
+ typedef int (*getc_func)(void*);
22
+
23
+ Document *
24
+ gfm_populate(getc_func getc, void* ctx, int flags)
25
+ {
26
+ Cstring line;
27
+ Document *a = __mkd_new_Document();
28
+ int c;
29
+ int pandoc = 0;
30
+
31
+ if ( !a ) return 0;
32
+
33
+ a->tabstop = (flags & MKD_TABSTOP) ? 4 : TABSTOP;
34
+
35
+ CREATE(line);
36
+
37
+ while ( (c = (*getc)(ctx)) != EOF ) {
38
+ if ( c == '\n' ) {
39
+ if ( pandoc != EOF && pandoc < 3 ) {
40
+ if ( S(line) && (T(line)[0] == '%') )
41
+ pandoc++;
42
+ else
43
+ pandoc = EOF;
44
+ }
45
+
46
+ if (pandoc == EOF) {
47
+ EXPAND(line) = ' ';
48
+ EXPAND(line) = ' ';
49
+ }
50
+ __mkd_enqueue(a, &line);
51
+ S(line) = 0;
52
+ }
53
+ else if ( isprint(c) || isspace(c) || (c & 0x80) )
54
+ EXPAND(line) = c;
55
+ }
56
+
57
+ if ( S(line) )
58
+ __mkd_enqueue(a, &line);
59
+
60
+ DELETE(line);
61
+
62
+ if ( (pandoc == 3) && !(flags & (MKD_NOHEADER|MKD_STRICT)) ) {
63
+ /* the first three lines started with %, so we have a header.
64
+ * clip the first three lines out of content and hang them
65
+ * off header.
66
+ */
67
+ Line *headers = T(a->content);
68
+
69
+ a->title = headers; __mkd_header_dle(a->title);
70
+ a->author= headers->next; __mkd_header_dle(a->author);
71
+ a->date = headers->next->next; __mkd_header_dle(a->date);
72
+
73
+ T(a->content) = headers->next->next->next;
74
+ }
75
+
76
+ return a;
77
+ }
78
+
79
+
80
+ /* convert a block of text into a linked list
81
+ */
82
+ Document *
83
+ gfm_string(const char *buf, int len, DWORD flags)
84
+ {
85
+ struct string_stream about;
86
+
87
+ about.data = buf;
88
+ about.size = len;
89
+
90
+ return gfm_populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK);
91
+ }
92
+
93
+
94
+ /* convert a file into a linked list
95
+ */
96
+ Document *
97
+ gfm_in(FILE *f, DWORD flags)
98
+ {
99
+ return gfm_populate((getc_func)fgetc, f, flags & INPUT_MASK);
100
+ }
data/ext/html5.c ADDED
@@ -0,0 +1,22 @@
1
+ /* block-level tags for passing html5 blocks through the blender
2
+ */
3
+ #include "tags.h"
4
+
5
+ void
6
+ mkd_with_html5_tags()
7
+ {
8
+ static int populated = 0;
9
+
10
+ if ( populated ) return;
11
+ populated = 1;
12
+
13
+ mkd_define_tag("ASIDE", 0);
14
+ mkd_define_tag("FOOTER", 0);
15
+ mkd_define_tag("HEADER", 0);
16
+ mkd_define_tag("HGROUP", 0);
17
+ mkd_define_tag("NAV", 0);
18
+ mkd_define_tag("SECTION", 0);
19
+ mkd_define_tag("ARTICLE", 0);
20
+
21
+ mkd_sort_tags();
22
+ }