bluecloth 2.0.6.pre120-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +363 -0
- data/LICENSE +27 -0
- data/LICENSE.discount +47 -0
- data/README +81 -0
- data/Rakefile +349 -0
- data/Rakefile.local +43 -0
- data/bin/bluecloth +84 -0
- data/ext/Csio.c +61 -0
- data/ext/VERSION +1 -0
- data/ext/amalloc.h +29 -0
- data/ext/bluecloth.c +391 -0
- data/ext/bluecloth.h +19 -0
- data/ext/config.h +55 -0
- data/ext/css.c +76 -0
- data/ext/cstring.h +75 -0
- data/ext/docheader.c +43 -0
- data/ext/extconf.rb +52 -0
- data/ext/generate.c +1602 -0
- data/ext/markdown.c +1078 -0
- data/ext/markdown.h +146 -0
- data/ext/mkdio.c +303 -0
- data/ext/mkdio.h +79 -0
- data/ext/resource.c +155 -0
- data/ext/version.c +28 -0
- data/ext/xml.c +82 -0
- data/ext/xmlpage.c +48 -0
- data/lib/1.8/bluecloth_ext.so +0 -0
- data/lib/1.9/bluecloth_ext.so +0 -0
- data/lib/bluecloth.rb +164 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/helpers.rb +434 -0
- data/rake/hg.rb +273 -0
- data/rake/manual.rb +782 -0
- data/rake/packaging.rb +126 -0
- data/rake/publishing.rb +269 -0
- data/rake/rdoc.rb +30 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +187 -0
- data/rake/verifytask.rb +64 -0
- data/rake/win32.rb +190 -0
- data/spec/bluecloth/101_changes_spec.rb +141 -0
- data/spec/bluecloth/autolinks_spec.rb +49 -0
- data/spec/bluecloth/blockquotes_spec.rb +145 -0
- data/spec/bluecloth/code_spans_spec.rb +164 -0
- data/spec/bluecloth/emphasis_spec.rb +164 -0
- data/spec/bluecloth/entities_spec.rb +65 -0
- data/spec/bluecloth/hrules_spec.rb +90 -0
- data/spec/bluecloth/images_spec.rb +92 -0
- data/spec/bluecloth/inline_html_spec.rb +238 -0
- data/spec/bluecloth/links_spec.rb +171 -0
- data/spec/bluecloth/lists_spec.rb +294 -0
- data/spec/bluecloth/paragraphs_spec.rb +75 -0
- data/spec/bluecloth/titles_spec.rb +305 -0
- data/spec/bluecloth_spec.rb +281 -0
- data/spec/bugfix_spec.rb +172 -0
- data/spec/contributions_spec.rb +85 -0
- data/spec/data/antsugar.txt +34 -0
- data/spec/data/markdowntest/Amps and angle encoding.html +17 -0
- data/spec/data/markdowntest/Amps and angle encoding.text +21 -0
- data/spec/data/markdowntest/Auto links.html +18 -0
- data/spec/data/markdowntest/Auto links.text +13 -0
- data/spec/data/markdowntest/Backslash escapes.html +118 -0
- data/spec/data/markdowntest/Backslash escapes.text +120 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.html +15 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.text +11 -0
- data/spec/data/markdowntest/Code Blocks.html +18 -0
- data/spec/data/markdowntest/Code Blocks.text +14 -0
- data/spec/data/markdowntest/Code Spans.html +5 -0
- data/spec/data/markdowntest/Code Spans.text +5 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/spec/data/markdowntest/Horizontal rules.html +71 -0
- data/spec/data/markdowntest/Horizontal rules.text +67 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).html +15 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).text +15 -0
- data/spec/data/markdowntest/Inline HTML (Simple).html +72 -0
- data/spec/data/markdowntest/Inline HTML (Simple).text +69 -0
- data/spec/data/markdowntest/Inline HTML comments.html +13 -0
- data/spec/data/markdowntest/Inline HTML comments.text +13 -0
- data/spec/data/markdowntest/Links, inline style.html +11 -0
- data/spec/data/markdowntest/Links, inline style.text +12 -0
- data/spec/data/markdowntest/Links, reference style.html +52 -0
- data/spec/data/markdowntest/Links, reference style.text +71 -0
- data/spec/data/markdowntest/Links, shortcut references.html +9 -0
- data/spec/data/markdowntest/Links, shortcut references.text +20 -0
- data/spec/data/markdowntest/Literal quotes in titles.html +3 -0
- data/spec/data/markdowntest/Literal quotes in titles.text +7 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.html +314 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.text +306 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.html +942 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.text +888 -0
- data/spec/data/markdowntest/Nested blockquotes.html +9 -0
- data/spec/data/markdowntest/Nested blockquotes.text +5 -0
- data/spec/data/markdowntest/Ordered and unordered lists.html +148 -0
- data/spec/data/markdowntest/Ordered and unordered lists.text +131 -0
- data/spec/data/markdowntest/Strong and em together.html +7 -0
- data/spec/data/markdowntest/Strong and em together.text +7 -0
- data/spec/data/markdowntest/Tabs.html +25 -0
- data/spec/data/markdowntest/Tabs.text +21 -0
- data/spec/data/markdowntest/Tidyness.html +8 -0
- data/spec/data/markdowntest/Tidyness.text +5 -0
- data/spec/data/ml-announce.txt +17 -0
- data/spec/data/re-overflow.txt +67 -0
- data/spec/data/re-overflow2.txt +281 -0
- data/spec/discount_spec.rb +184 -0
- data/spec/lib/constants.rb +5 -0
- data/spec/lib/helpers.rb +137 -0
- data/spec/lib/matchers.rb +235 -0
- data/spec/markdowntest_spec.rb +79 -0
- metadata +205 -0
data/ext/markdown.h
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
#ifndef _MARKDOWN_D
|
2
|
+
#define _MARKDOWN_D
|
3
|
+
|
4
|
+
#include "cstring.h"
|
5
|
+
|
6
|
+
/* reference-style links (and images) are stored in an array
|
7
|
+
* of footnotes.
|
8
|
+
*/
|
9
|
+
typedef struct footnote {
|
10
|
+
Cstring tag; /* the tag for the reference link */
|
11
|
+
Cstring link; /* what this footnote points to */
|
12
|
+
Cstring title; /* what it's called (TITLE= attribute) */
|
13
|
+
int height, width; /* dimensions (for image link) */
|
14
|
+
int dealloc; /* deallocation needed? */
|
15
|
+
} Footnote;
|
16
|
+
|
17
|
+
/* each input line is read into a Line, which contains the line,
|
18
|
+
* the offset of the first non-space character [this assumes
|
19
|
+
* that all tabs will be expanded to spaces!], and a pointer to
|
20
|
+
* the next line.
|
21
|
+
*/
|
22
|
+
typedef struct line {
|
23
|
+
Cstring text;
|
24
|
+
struct line *next;
|
25
|
+
int dle;
|
26
|
+
} Line;
|
27
|
+
|
28
|
+
|
29
|
+
/* a paragraph is a collection of Lines, with links to the next paragraph
|
30
|
+
* and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
|
31
|
+
* paragraph.
|
32
|
+
*/
|
33
|
+
typedef struct paragraph {
|
34
|
+
struct paragraph *next; /* next paragraph */
|
35
|
+
struct paragraph *down; /* recompiled contents of this paragraph */
|
36
|
+
struct line *text; /* all the text in this paragraph */
|
37
|
+
char *ident; /* %id% tag for QUOTE */
|
38
|
+
enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
|
39
|
+
HTML, STYLE, DL, UL, OL, AL, LISTITEM,
|
40
|
+
HDR, HR, TABLE, SOURCE } typ;
|
41
|
+
enum { IMPLICIT=0, PARA, CENTER} align;
|
42
|
+
int hnumber; /* <Hn> for typ == HDR */
|
43
|
+
} Paragraph;
|
44
|
+
|
45
|
+
enum { ETX, SETEXT }; /* header types */
|
46
|
+
|
47
|
+
|
48
|
+
typedef struct block {
|
49
|
+
enum { bTEXT, bSTAR, bUNDER } b_type;
|
50
|
+
int b_count;
|
51
|
+
char b_char;
|
52
|
+
Cstring b_text;
|
53
|
+
Cstring b_post;
|
54
|
+
} block;
|
55
|
+
|
56
|
+
typedef STRING(block) Qblock;
|
57
|
+
|
58
|
+
|
59
|
+
/* a magic markdown io thing holds all the data structures needed to
|
60
|
+
* do the backend processing of a markdown document
|
61
|
+
*/
|
62
|
+
typedef struct mmiot {
|
63
|
+
Cstring out;
|
64
|
+
Cstring in;
|
65
|
+
Qblock Q;
|
66
|
+
int isp;
|
67
|
+
STRING(Footnote) *footnotes;
|
68
|
+
int flags;
|
69
|
+
#define DENY_A 0x0001
|
70
|
+
#define DENY_IMG 0x0002
|
71
|
+
#define DENY_SMARTY 0x0004
|
72
|
+
#define DENY_HTML 0x0008
|
73
|
+
#define STRICT 0x0010
|
74
|
+
#define INSIDE_TAG 0x0020
|
75
|
+
#define NO_PSEUDO_PROTO 0x0040
|
76
|
+
#define CDATA_OUTPUT 0x0080
|
77
|
+
#define NOTABLES 0x0400
|
78
|
+
#define TOC 0x1000
|
79
|
+
#define MKD_1_COMPAT 0x2000
|
80
|
+
#define AUTOLINK 0x4000
|
81
|
+
#define SAFELINK 0x8000
|
82
|
+
#define USER_FLAGS 0xFCFF
|
83
|
+
#define EMBEDDED DENY_A|DENY_IMG|NO_PSEUDO_PROTO|CDATA_OUTPUT
|
84
|
+
char *base;
|
85
|
+
} MMIOT;
|
86
|
+
|
87
|
+
|
88
|
+
/*
|
89
|
+
* the mkdio text input functions return a document structure,
|
90
|
+
* which contains a header (retrieved from the document if
|
91
|
+
* markdown was configured * with the * --enable-pandoc-header
|
92
|
+
* and the document begins with a pandoc-style header) and the
|
93
|
+
* root of the linked list of Lines.
|
94
|
+
*/
|
95
|
+
typedef struct document {
|
96
|
+
Line *headers; /* title -> author(s) -> date */
|
97
|
+
ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
|
98
|
+
Paragraph *code; /* intermediate code generated by compile() */
|
99
|
+
int compiled; /* set after mkd_compile() */
|
100
|
+
int html; /* set after (internal) htmlify() */
|
101
|
+
int tabstop; /* for properly expanding tabs (ick) */
|
102
|
+
MMIOT *ctx; /* backend buffers, flags, and structures */
|
103
|
+
char *base; /* url basename for url fragments */
|
104
|
+
} Document;
|
105
|
+
|
106
|
+
|
107
|
+
extern int mkd_firstnonblank(Line *);
|
108
|
+
extern int mkd_compile(Document *, int);
|
109
|
+
extern int mkd_document(Document *, char **);
|
110
|
+
extern int mkd_generatehtml(Document *, FILE *);
|
111
|
+
extern int mkd_css(Document *, char **);
|
112
|
+
extern int mkd_generatecss(Document *, FILE *);
|
113
|
+
#define mkd_style mkd_generatecss
|
114
|
+
extern int mkd_xml(char *, int , char **);
|
115
|
+
extern int mkd_generatexml(char *, int, FILE *);
|
116
|
+
extern void mkd_cleanup(Document *);
|
117
|
+
extern int mkd_line(char *, int, char **, int);
|
118
|
+
extern int mkd_generateline(char *, int, FILE*, int);
|
119
|
+
#define mkd_text mkd_generateline
|
120
|
+
extern void mkd_basename(Document*, char *);
|
121
|
+
extern void mkd_string_to_anchor(char*,int, void(*)(int,void*), void*);
|
122
|
+
|
123
|
+
extern Document *mkd_in(FILE *, int);
|
124
|
+
extern Document *mkd_string(char*,int, int);
|
125
|
+
|
126
|
+
#define NO_HEADER 0x0100
|
127
|
+
#define STD_TABSTOP 0x0200
|
128
|
+
#define INPUT_MASK (NO_HEADER|STD_TABSTOP)
|
129
|
+
|
130
|
+
|
131
|
+
/* internal resource handling functions.
|
132
|
+
*/
|
133
|
+
extern void ___mkd_freeLine(Line *);
|
134
|
+
extern void ___mkd_freeLines(Line *);
|
135
|
+
extern void ___mkd_freeParagraph(Paragraph *);
|
136
|
+
extern void ___mkd_freefootnote(Footnote *);
|
137
|
+
extern void ___mkd_freefootnotes(MMIOT *);
|
138
|
+
extern void ___mkd_initmmiot(MMIOT *, void *);
|
139
|
+
extern void ___mkd_freemmiot(MMIOT *, void *);
|
140
|
+
extern void ___mkd_freeLineRange(Line *, Line *);
|
141
|
+
extern void ___mkd_xml(char *, int, FILE *);
|
142
|
+
extern void ___mkd_reparse(char *, int, int, MMIOT*);
|
143
|
+
extern void ___mkd_emblock(MMIOT*);
|
144
|
+
extern void ___mkd_tidy(Cstring *);
|
145
|
+
|
146
|
+
#endif/*_MARKDOWN_D*/
|
data/ext/mkdio.c
ADDED
@@ -0,0 +1,303 @@
|
|
1
|
+
/*
|
2
|
+
* mkdio -- markdown front end input functions
|
3
|
+
*
|
4
|
+
* Copyright (C) 2007 David L Parsons.
|
5
|
+
* The redistribution terms are provided in the COPYRIGHT file that must
|
6
|
+
* be distributed with this source code.
|
7
|
+
*/
|
8
|
+
#include "config.h"
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <ctype.h>
|
12
|
+
|
13
|
+
#include "cstring.h"
|
14
|
+
#include "markdown.h"
|
15
|
+
#include "amalloc.h"
|
16
|
+
|
17
|
+
typedef ANCHOR(Line) LineAnchor;
|
18
|
+
|
19
|
+
/* create a new blank Document
|
20
|
+
*/
|
21
|
+
static Document*
|
22
|
+
new_Document()
|
23
|
+
{
|
24
|
+
Document *ret = calloc(sizeof(Document), 1);
|
25
|
+
|
26
|
+
if ( ret ) {
|
27
|
+
if (( ret->ctx = calloc(sizeof(MMIOT), 1) ))
|
28
|
+
return ret;
|
29
|
+
free(ret);
|
30
|
+
}
|
31
|
+
return 0;
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
/* add a line to the markdown input chain
|
36
|
+
*/
|
37
|
+
static void
|
38
|
+
queue(Document* a, Cstring *line)
|
39
|
+
{
|
40
|
+
Line *p = calloc(sizeof *p, 1);
|
41
|
+
unsigned char c;
|
42
|
+
int xp = 0;
|
43
|
+
int size = S(*line);
|
44
|
+
unsigned char *str = (unsigned char*)T(*line);
|
45
|
+
|
46
|
+
CREATE(p->text);
|
47
|
+
ATTACH(a->content, p);
|
48
|
+
|
49
|
+
while ( size-- ) {
|
50
|
+
if ( (c = *str++) == '\t' ) {
|
51
|
+
/* expand tabs into ->tabstop spaces. We use ->tabstop
|
52
|
+
* because the ENTIRE FREAKING COMPUTER WORLD uses editors
|
53
|
+
* that don't do ^T/^D, but instead use tabs for indentation,
|
54
|
+
* and, of course, set their tabs down to 4 spaces
|
55
|
+
*/
|
56
|
+
do {
|
57
|
+
EXPAND(p->text) = ' ';
|
58
|
+
} while ( ++xp % a->tabstop );
|
59
|
+
}
|
60
|
+
else if ( c >= ' ' ) {
|
61
|
+
EXPAND(p->text) = c;
|
62
|
+
++xp;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
EXPAND(p->text) = 0;
|
66
|
+
S(p->text)--;
|
67
|
+
p->dle = mkd_firstnonblank(p);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
#ifdef PANDOC_HEADER
|
72
|
+
/* trim leading blanks from a header line
|
73
|
+
*/
|
74
|
+
static void
|
75
|
+
snip(Line *p)
|
76
|
+
{
|
77
|
+
CLIP(p->text, 0, 1);
|
78
|
+
p->dle = mkd_firstnonblank(p);
|
79
|
+
}
|
80
|
+
#endif
|
81
|
+
|
82
|
+
|
83
|
+
/* build a Document from any old input.
|
84
|
+
*/
|
85
|
+
typedef int (*getc_func)(void*);
|
86
|
+
|
87
|
+
Document *
|
88
|
+
populate(getc_func getc, void* ctx, int flags)
|
89
|
+
{
|
90
|
+
Cstring line;
|
91
|
+
Document *a = new_Document();
|
92
|
+
int c;
|
93
|
+
#ifdef PANDOC_HEADER
|
94
|
+
int pandoc = 0;
|
95
|
+
#endif
|
96
|
+
|
97
|
+
if ( !a ) return 0;
|
98
|
+
|
99
|
+
a->tabstop = (flags & STD_TABSTOP) ? 4 : TABSTOP;
|
100
|
+
|
101
|
+
CREATE(line);
|
102
|
+
|
103
|
+
while ( (c = (*getc)(ctx)) != EOF ) {
|
104
|
+
if ( c == '\n' ) {
|
105
|
+
#ifdef PANDOC_HEADER
|
106
|
+
if ( pandoc != EOF && pandoc < 3 ) {
|
107
|
+
if ( S(line) && (T(line)[0] == '%') )
|
108
|
+
pandoc++;
|
109
|
+
else
|
110
|
+
pandoc = EOF;
|
111
|
+
}
|
112
|
+
#endif
|
113
|
+
queue(a, &line);
|
114
|
+
S(line) = 0;
|
115
|
+
}
|
116
|
+
else if ( isprint(c) || isspace(c) || (c & 0x80) )
|
117
|
+
EXPAND(line) = c;
|
118
|
+
}
|
119
|
+
|
120
|
+
if ( S(line) )
|
121
|
+
queue(a, &line);
|
122
|
+
|
123
|
+
DELETE(line);
|
124
|
+
|
125
|
+
#ifdef PANDOC_HEADER
|
126
|
+
if ( (pandoc == 3) && !(flags & NO_HEADER) ) {
|
127
|
+
/* the first three lines started with %, so we have a header.
|
128
|
+
* clip the first three lines out of content and hang them
|
129
|
+
* off header.
|
130
|
+
*/
|
131
|
+
a->headers = T(a->content);
|
132
|
+
T(a->content) = a->headers->next->next->next;
|
133
|
+
a->headers->next->next->next = 0;
|
134
|
+
snip(a->headers);
|
135
|
+
snip(a->headers->next);
|
136
|
+
snip(a->headers->next->next);
|
137
|
+
}
|
138
|
+
#endif
|
139
|
+
|
140
|
+
return a;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
/* convert a file into a linked list
|
145
|
+
*/
|
146
|
+
Document *
|
147
|
+
mkd_in(FILE *f, int flags)
|
148
|
+
{
|
149
|
+
return populate((getc_func)fgetc, f, flags & INPUT_MASK);
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
/* return a single character out of a buffer
|
154
|
+
*/
|
155
|
+
struct string_ctx {
|
156
|
+
char *data; /* the unread data */
|
157
|
+
int size; /* and how much is there? */
|
158
|
+
} ;
|
159
|
+
|
160
|
+
|
161
|
+
static int
|
162
|
+
strget(struct string_ctx *in)
|
163
|
+
{
|
164
|
+
if ( !in->size ) return EOF;
|
165
|
+
|
166
|
+
--(in->size);
|
167
|
+
|
168
|
+
return *(in->data)++;
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
/* convert a block of text into a linked list
|
173
|
+
*/
|
174
|
+
Document *
|
175
|
+
mkd_string(char *buf, int len, int flags)
|
176
|
+
{
|
177
|
+
struct string_ctx about;
|
178
|
+
|
179
|
+
about.data = buf;
|
180
|
+
about.size = len;
|
181
|
+
|
182
|
+
return populate((getc_func)strget, &about, flags & INPUT_MASK);
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
/* write the html to a file (xmlified if necessary)
|
187
|
+
*/
|
188
|
+
int
|
189
|
+
mkd_generatehtml(Document *p, FILE *output)
|
190
|
+
{
|
191
|
+
char *doc;
|
192
|
+
int szdoc;
|
193
|
+
|
194
|
+
if ( (szdoc = mkd_document(p, &doc)) != EOF ) {
|
195
|
+
if ( p->ctx->flags & CDATA_OUTPUT )
|
196
|
+
mkd_generatexml(doc, szdoc, output);
|
197
|
+
else
|
198
|
+
fwrite(doc, szdoc, 1, output);
|
199
|
+
putc('\n', output);
|
200
|
+
return 0;
|
201
|
+
}
|
202
|
+
return -1;
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
/* convert some markdown text to html
|
207
|
+
*/
|
208
|
+
int
|
209
|
+
markdown(Document *document, FILE *out, int flags)
|
210
|
+
{
|
211
|
+
if ( mkd_compile(document, flags) ) {
|
212
|
+
mkd_generatehtml(document, out);
|
213
|
+
mkd_cleanup(document);
|
214
|
+
return 0;
|
215
|
+
}
|
216
|
+
return -1;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
void
|
221
|
+
mkd_basename(Document *document, char *base)
|
222
|
+
{
|
223
|
+
if ( document )
|
224
|
+
document->base = base;
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
/* write out a Cstring, mangled into a form suitable for `<a href=` or `<a id=`
|
229
|
+
*/
|
230
|
+
void
|
231
|
+
mkd_string_to_anchor(char *s, int len, void(*outchar)(int,void*), void *out)
|
232
|
+
{
|
233
|
+
unsigned char c;
|
234
|
+
|
235
|
+
for ( ; len-- > 0; ) {
|
236
|
+
c = *s++;
|
237
|
+
if ( c == ' ' || c == '&' || c == '<' || c == '"' )
|
238
|
+
(*outchar)('+', out);
|
239
|
+
else if ( isalnum(c) || ispunct(c) || (c & 0x80) )
|
240
|
+
(*outchar)(c, out);
|
241
|
+
else
|
242
|
+
(*outchar)('~',out);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
/* ___mkd_reparse() a line
|
248
|
+
*/
|
249
|
+
static void
|
250
|
+
mkd_parse_line(char *bfr, int size, MMIOT *f, int flags)
|
251
|
+
{
|
252
|
+
___mkd_initmmiot(f, 0);
|
253
|
+
f->flags = flags & USER_FLAGS;
|
254
|
+
___mkd_reparse(bfr, size, 0, f);
|
255
|
+
___mkd_emblock(f);
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
/* ___mkd_reparse() a line, returning it in malloc()ed memory
|
260
|
+
*/
|
261
|
+
int
|
262
|
+
mkd_line(char *bfr, int size, char **res, int flags)
|
263
|
+
{
|
264
|
+
MMIOT f;
|
265
|
+
int len;
|
266
|
+
|
267
|
+
mkd_parse_line(bfr, size, &f, flags);
|
268
|
+
|
269
|
+
if ( len = S(f.out) ) {
|
270
|
+
/* kludge alert; we know that T(f.out) is malloced memory,
|
271
|
+
* so we can just steal it away. This is awful -- there
|
272
|
+
* should be an opaque method that transparently moves
|
273
|
+
* the pointer out of the embedded Cstring.
|
274
|
+
*/
|
275
|
+
*res = T(f.out);
|
276
|
+
T(f.out) = 0;
|
277
|
+
S(f.out) = 0;
|
278
|
+
}
|
279
|
+
else {
|
280
|
+
*res = 0;
|
281
|
+
len = EOF;
|
282
|
+
}
|
283
|
+
___mkd_freemmiot(&f, 0);
|
284
|
+
return len;
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
/* ___mkd_reparse() a line, writing it to a FILE
|
289
|
+
*/
|
290
|
+
int
|
291
|
+
mkd_generateline(char *bfr, int size, FILE *output, int flags)
|
292
|
+
{
|
293
|
+
MMIOT f;
|
294
|
+
|
295
|
+
mkd_parse_line(bfr, size, &f, flags);
|
296
|
+
if ( flags & CDATA_OUTPUT )
|
297
|
+
mkd_generatexml(T(f.out), S(f.out), output);
|
298
|
+
else
|
299
|
+
fwrite(T(f.out), S(f.out), 1, output);
|
300
|
+
|
301
|
+
___mkd_freemmiot(&f, 0);
|
302
|
+
return 0;
|
303
|
+
}
|
data/ext/mkdio.h
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#ifndef _MKDIO_D
|
2
|
+
#define _MKDIO_D
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
typedef void MMIOT;
|
7
|
+
|
8
|
+
/* line builder for markdown()
|
9
|
+
*/
|
10
|
+
MMIOT *mkd_in(FILE*,int); /* assemble input from a file */
|
11
|
+
MMIOT *mkd_string(char*,int,int); /* assemble input from a buffer */
|
12
|
+
|
13
|
+
void mkd_basename(MMIOT*,char*);
|
14
|
+
|
15
|
+
/* compilation, debugging, cleanup
|
16
|
+
*/
|
17
|
+
int mkd_compile(MMIOT*, int);
|
18
|
+
int mkd_cleanup(MMIOT*);
|
19
|
+
|
20
|
+
/* markup functions
|
21
|
+
*/
|
22
|
+
int mkd_dump(MMIOT*, FILE*, int, char*);
|
23
|
+
int markdown(MMIOT*, FILE*, int);
|
24
|
+
int mkd_line(char *, int, char **, int);
|
25
|
+
void mkd_string_to_anchor(char *, int, int (*)(int,void*), void*);
|
26
|
+
int mkd_xhtmlpage(MMIOT*,int,FILE*);
|
27
|
+
|
28
|
+
/* header block access
|
29
|
+
*/
|
30
|
+
char* mkd_doc_title(MMIOT*);
|
31
|
+
char* mkd_doc_author(MMIOT*);
|
32
|
+
char* mkd_doc_date(MMIOT*);
|
33
|
+
|
34
|
+
/* compiled data access
|
35
|
+
*/
|
36
|
+
int mkd_document(MMIOT*, char**);
|
37
|
+
int mkd_toc(MMIOT*, char**);
|
38
|
+
int mkd_css(MMIOT*, char **);
|
39
|
+
int mkd_xml(char *, int, char **);
|
40
|
+
|
41
|
+
/* write-to-file functions
|
42
|
+
*/
|
43
|
+
int mkd_generatehtml(MMIOT*,FILE*);
|
44
|
+
int mkd_generatetoc(MMIOT*,FILE*);
|
45
|
+
int mkd_generatexml(char *, int,FILE*);
|
46
|
+
int mkd_generatecss(MMIOT*,FILE*);
|
47
|
+
#define mkd_style mkd_generatecss
|
48
|
+
int mkd_generateline(char *, int, FILE*, int);
|
49
|
+
#define mkd_text mkd_generateline
|
50
|
+
|
51
|
+
/* version#.
|
52
|
+
*/
|
53
|
+
extern char markdown_version[];
|
54
|
+
|
55
|
+
/* special flags for markdown() and mkd_text()
|
56
|
+
*/
|
57
|
+
#define MKD_NOLINKS 0x0001 /* don't do link processing, block <a> tags */
|
58
|
+
#define MKD_NOIMAGE 0x0002 /* don't do image processing, block <img> */
|
59
|
+
#define MKD_NOPANTS 0x0004 /* don't run smartypants() */
|
60
|
+
#define MKD_NOHTML 0x0008 /* don't allow raw html through AT ALL */
|
61
|
+
#define MKD_STRICT 0x0010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
|
62
|
+
#define MKD_TAGTEXT 0x0020 /* process text inside an html tag; no
|
63
|
+
* <em>, no <bold>, no html or [] expansion */
|
64
|
+
#define MKD_NO_EXT 0x0040 /* don't allow pseudo-protocols */
|
65
|
+
#define MKD_CDATA 0x0080 /* generate code for xml ![CDATA[...]] */
|
66
|
+
#define MKD_NOTABLES 0x0400 /* disallow tables */
|
67
|
+
#define MKD_TOC 0x1000 /* do table-of-contents processing */
|
68
|
+
#define MKD_1_COMPAT 0x2000 /* compatability with MarkdownTest_1.0 */
|
69
|
+
#define MKD_AUTOLINK 0x4000 /* make http://foo.com link even without <>s */
|
70
|
+
#define MKD_SAFELINK 0x8000 /* paranoid check for link protocol */
|
71
|
+
#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
|
72
|
+
|
73
|
+
/* special flags for mkd_in() and mkd_string()
|
74
|
+
*/
|
75
|
+
#define MKD_NOHEADER 0x0100 /* don't process header blocks */
|
76
|
+
#define MKD_TABSTOP 0x0200 /* expand tabs to 4 spaces */
|
77
|
+
|
78
|
+
|
79
|
+
#endif/*_MKDIO_D*/
|