Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

`mkd_text()` is now `mkd_generateline()`; the new

function `mkd_line()` formats a line into a string,
similarly to `mkd_toc()`, `mkd_xml()`, and so on.

There are a whole bunch of new public functions now,
so I'm pushing the version up to 1.4.0
  • Loading branch information...
commit 8ca7a50e707c62f217ce53dd0ef36d0c94853db7 1 parent 7059476
David Parsons authored
2  VERSION
... ... @@ -1 +1 @@
1   -1.3.7
  1 +1.4.0
8 main.c
@@ -102,7 +102,7 @@ main(int argc, char **argv)
102 102 int flags = 0;
103 103 int debug = 0;
104 104 int toc = 0;
105   - int use_mkd_text = 0;
  105 + int use_mkd_line = 0;
106 106 char *text = 0;
107 107 char *ofile = 0;
108 108 char *urlbase = 0;
@@ -127,7 +127,7 @@ main(int argc, char **argv)
127 127 case 'f': set(&flags, optarg);
128 128 break;
129 129 case 't': text = optarg;
130   - use_mkd_text = 1;
  130 + use_mkd_line = 1;
131 131 break;
132 132 case 'T': toc = 1;
133 133 break;
@@ -151,8 +151,8 @@ main(int argc, char **argv)
151 151 argc -= optind;
152 152 argv += optind;
153 153
154   - if ( use_mkd_text )
155   - rc = mkd_text( text, strlen(text), stdout, flags);
  154 + if ( use_mkd_line )
  155 + rc = mkd_generateline( text, strlen(text), stdout, flags);
156 156 else {
157 157 if ( text ) {
158 158 if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
2  mkd2html.c
@@ -162,7 +162,7 @@ char **argv;
162 162
163 163 if ( h ) {
164 164 fprintf(output," <title>");
165   - mkd_text(h, strlen(h), output, 0);
  165 + mkd_generateline(h, strlen(h), output, 0);
166 166 fprintf(output, "</title>\n");
167 167 }
168 168 for ( i=0; i < S(headers); i++ )
51 mkdio.c
@@ -244,18 +244,55 @@ mkd_string_to_anchor(char *s, int len, void(*outchar)(int,void*), void *out)
244 244 }
245 245
246 246
247   -/* public interface for ___mkd_reparse()
  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
248 260 */
249 261 int
250   -mkd_text(char *bfr, int size, FILE *output, int flags)
  262 +mkd_line(char *bfr, int size, char **res, int flags)
251 263 {
252 264 MMIOT f;
253   -
254   - ___mkd_initmmiot(&f, 0);
255   - f.flags = flags & USER_FLAGS;
  265 + int len;
256 266
257   - ___mkd_reparse(bfr, size, 0, &f);
258   - ___mkd_emblock(&f);
  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);
259 296 if ( flags & CDATA_OUTPUT )
260 297 mkd_generatexml(T(f.out), S(f.out), output);
261 298 else
18 mkdio.h
@@ -15,20 +15,15 @@ void mkd_basename(MMIOT*,char*);
15 15 /* compilation, debugging, cleanup
16 16 */
17 17 int mkd_compile(MMIOT*, int);
18   -int mkd_generatehtml(MMIOT*,FILE*);
19   -int mkd_generatetoc(MMIOT*,FILE*);
20   -int mkd_generatecss(MMIOT*,FILE*);
21   -#define mkd_style mkd_generatecss
22   -int mkd_xhtmlpage(MMIOT*,int,FILE*);
23 18 int mkd_cleanup(MMIOT*);
24 19
25 20 /* markup functions
26 21 */
27   -int mkd_text(char *, int, FILE*, int);
28 22 int mkd_dump(MMIOT*, FILE*, int, char*);
29 23 int markdown(MMIOT*, FILE*, int);
30   -void mkd_basename(MMIOT*,char*);
  24 +int mkd_line(char *, int, char **, int);
31 25 void mkd_string_to_anchor(char *, int, int (*)(int,void*), void*);
  26 +int mkd_xhtmlpage(MMIOT*,int,FILE*);
32 27
33 28 /* header block access
34 29 */
@@ -42,6 +37,15 @@ int mkd_document(MMIOT*, char**);
42 37 int mkd_toc(MMIOT*, char**);
43 38 int mkd_css(MMIOT*, char **);
44 39
  40 +/* write-to-file functions
  41 + */
  42 +int mkd_generatehtml(MMIOT*,FILE*);
  43 +int mkd_generatetoc(MMIOT*,FILE*);
  44 +int mkd_generatecss(MMIOT*,FILE*);
  45 +#define mkd_style mkd_generatecss
  46 +int mkd_generateline(char *, int, FILE*, int);
  47 +#define mkd_text mkd_generateline
  48 +
45 49 /* version#.
46 50 */
47 51 extern char markdown_version[];
6 theme.c
@@ -310,7 +310,7 @@ ftitle(MMIOT *doc, FILE* output, int flags)
310 310 h = pagename;
311 311
312 312 if ( h )
313   - mkd_text(h, strlen(h), output, flags);
  313 + mkd_generateline(h, strlen(h), output, flags);
314 314 }
315 315
316 316
@@ -322,7 +322,7 @@ fdate(MMIOT *doc, FILE *output, int flags)
322 322 char *h = infop ? ctime(&infop->st_mtime) : mkd_doc_date(doc);
323 323
324 324 if ( h )
325   - mkd_text(h, strlen(h), output, flags|MKD_TAGTEXT);
  325 + mkd_generateline(h, strlen(h), output, flags|MKD_TAGTEXT);
326 326 }
327 327
328 328
@@ -339,7 +339,7 @@ fauthor(MMIOT *doc, FILE *output, int flags)
339 339 #endif
340 340
341 341 if ( h )
342   - mkd_text(h, strlen(h), output, flags);
  342 + mkd_generateline(h, strlen(h), output, flags);
343 343 }
344 344
345 345

0 comments on commit 8ca7a50

Please sign in to comment.
Something went wrong with that request. Please try again.