ext/mkdio.c in rdiscount-2.0.7.3 vs ext/mkdio.c in rdiscount-2.1.6
- old
+ new
@@ -16,30 +16,31 @@
typedef ANCHOR(Line) LineAnchor;
/* create a new blank Document
*/
-static Document*
-new_Document()
+Document*
+__mkd_new_Document()
{
Document *ret = calloc(sizeof(Document), 1);
if ( ret ) {
- if (( ret->ctx = calloc(sizeof(MMIOT), 1) )) {
+ if ( ret->ctx = calloc(sizeof(MMIOT), 1) ) {
ret->magic = VALID_DOCUMENT;
return ret;
}
free(ret);
}
return 0;
}
-/* add a line to the markdown input chain
+/* add a line to the markdown input chain, expanding tabs and
+ * noting the presence of special characters as we go.
*/
-static void
-queue(Document* a, Cstring *line)
+void
+__mkd_enqueue(Document* a, Cstring *line)
{
Line *p = calloc(sizeof *p, 1);
unsigned char c;
int xp = 0;
int size = S(*line);
@@ -58,10 +59,12 @@
do {
EXPAND(p->text) = ' ';
} while ( ++xp % a->tabstop );
}
else if ( c >= ' ' ) {
+ if ( c == '|' )
+ p->flags |= PIPECHAR;
EXPAND(p->text) = c;
++xp;
}
}
EXPAND(p->text) = 0;
@@ -70,12 +73,12 @@
}
/* trim leading blanks from a header line
*/
-static void
-header_dle(Line *p)
+void
+__mkd_header_dle(Line *p)
{
CLIP(p->text, 0, 1);
p->dle = mkd_firstnonblank(p);
}
@@ -86,11 +89,11 @@
Document *
populate(getc_func getc, void* ctx, int flags)
{
Cstring line;
- Document *a = new_Document();
+ Document *a = __mkd_new_Document();
int c;
int pandoc = 0;
if ( !a ) return 0;
@@ -104,32 +107,32 @@
if ( S(line) && (T(line)[0] == '%') )
pandoc++;
else
pandoc = EOF;
}
- queue(a, &line);
+ __mkd_enqueue(a, &line);
S(line) = 0;
}
else if ( isprint(c) || isspace(c) || (c & 0x80) )
EXPAND(line) = c;
}
if ( S(line) )
- queue(a, &line);
+ __mkd_enqueue(a, &line);
DELETE(line);
if ( (pandoc == 3) && !(flags & (MKD_NOHEADER|MKD_STRICT)) ) {
/* the first three lines started with %, so we have a header.
* clip the first three lines out of content and hang them
* off header.
*/
Line *headers = T(a->content);
- a->title = headers; header_dle(a->title);
- a->author= headers->next; header_dle(a->author);
- a->date = headers->next->next; header_dle(a->date);
+ a->title = headers; __mkd_header_dle(a->title);
+ a->author= headers->next; __mkd_header_dle(a->author);
+ a->date = headers->next->next; __mkd_header_dle(a->date);
T(a->content) = headers->next->next->next;
}
return a;
@@ -145,18 +148,12 @@
}
/* return a single character out of a buffer
*/
-struct string_ctx {
- char *data; /* the unread data */
- int size; /* and how much is there? */
-} ;
-
-
-static int
-strget(struct string_ctx *in)
+int
+__mkd_io_strget(struct string_stream *in)
{
if ( !in->size ) return EOF;
--(in->size);
@@ -165,18 +162,18 @@
/* convert a block of text into a linked list
*/
Document *
-mkd_string(char *buf, int len, DWORD flags)
+mkd_string(const char *buf, int len, DWORD flags)
{
- struct string_ctx about;
+ struct string_stream about;
about.data = buf;
about.size = len;
- return populate((getc_func)strget, &about, flags & INPUT_MASK);
+ return populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK);
}
/* write the html to a file (xmlified if necessary)
*/
@@ -223,19 +220,19 @@
int i, size;
char *line;
size = mkd_line(s, len, &line, IS_LABEL);
- if ( labelformat && size && !isalpha(line[0]) )
+ if ( labelformat && (size>0) && !isalpha(line[0]) )
(*outchar)('L',out);
for ( i=0; i < size ; i++ ) {
c = line[i];
if ( labelformat ) {
if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
(*outchar)(c, out);
else
- (*outchar)('.',out);
+ (*outchar)('.', out);
}
else
(*outchar)(c,out);
}
@@ -249,10 +246,10 @@
static void
mkd_parse_line(char *bfr, int size, MMIOT *f, int flags)
{
___mkd_initmmiot(f, 0);
f->flags = flags & USER_FLAGS;
- ___mkd_reparse(bfr, size, 0, f);
+ ___mkd_reparse(bfr, size, 0, f, 0);
___mkd_emblock(f);
}
/* ___mkd_reparse() a line, returning it in malloc()ed memory