19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
** using an external renderer.
*/
#include "config.h"
#include "markdown.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#define MKD_LI_END 8 /* internal list flag */
/********************
* TYPE DEFINITIONS *
********************/
#if INTERFACE
/* mkd_autolink -- type of autolink */
enum mkd_autolink {
MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
MKDA_NORMAL, /* normal http/http/ftp link */
MKDA_EXPLICIT_EMAIL, /* e-mail link with explicit mailto: */
MKDA_IMPLICIT_EMAIL /* e-mail link without mailto: */
};
/* mkd_renderer -- functions for rendering parsed data */
struct mkd_renderer {
/* document level callbacks */
void (*prolog)(struct Blob *ob, void *opaque);
void (*epilog)(struct Blob *ob, void *opaque);
|
>
>
>
>
>
>
>
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
** using an external renderer.
*/
#include "config.h"
#include "markdown.h"
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define MKD_LI_END 8 /* internal list flag */
/********************
* TYPE DEFINITIONS *
********************/
#if INTERFACE
/* mkd_autolink -- type of autolink */
enum mkd_autolink {
MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
MKDA_NORMAL, /* normal http/http/ftp link */
MKDA_EXPLICIT_EMAIL, /* e-mail link with explicit mailto: */
MKDA_IMPLICIT_EMAIL /* e-mail link without mailto: */
};
/* mkd_tagspan -- type of tagged <span> */
enum mkd_tagspan {
MKDT_ATREF, /* @name references, as in /chat attention targeting */
MKDT_HASH, /* #hash tags, message IDs, etc. */
};
/* mkd_renderer -- functions for rendering parsed data */
struct mkd_renderer {
/* document level callbacks */
void (*prolog)(struct Blob *ob, void *opaque);
void (*epilog)(struct Blob *ob, void *opaque);
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
int (*emphasis)(struct Blob *ob, struct Blob *text, char c,void*opaque);
int (*image)(struct Blob *ob, struct Blob *link, struct Blob *title,
struct Blob *alt, void *opaque);
int (*linebreak)(struct Blob *ob, void *opaque);
int (*link)(struct Blob *ob, struct Blob *link, struct Blob *title,
struct Blob *content, void *opaque);
int (*raw_html_tag)(struct Blob *ob, struct Blob *tag, void *opaque);
int (*triple_emphasis)(struct Blob *ob, struct Blob *text,
char c, void *opaque);
/* low level callbacks - NULL copies input directly into the output */
void (*entity)(struct Blob *ob, struct Blob *entity, void *opaque);
void (*normal_text)(struct Blob *ob, struct Blob *text, void *opaque);
|
>
>
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
int (*emphasis)(struct Blob *ob, struct Blob *text, char c,void*opaque);
int (*image)(struct Blob *ob, struct Blob *link, struct Blob *title,
struct Blob *alt, void *opaque);
int (*linebreak)(struct Blob *ob, void *opaque);
int (*link)(struct Blob *ob, struct Blob *link, struct Blob *title,
struct Blob *content, void *opaque);
int (*raw_html_tag)(struct Blob *ob, struct Blob *tag, void *opaque);
int (*tagspan)(struct Blob *ob, struct Blob *ref, enum mkd_tagspan type,
void *opaque);
int (*triple_emphasis)(struct Blob *ob, struct Blob *text,
char c, void *opaque);
/* low level callbacks - NULL copies input directly into the output */
void (*entity)(struct Blob *ob, struct Blob *entity, void *opaque);
void (*normal_text)(struct Blob *ob, struct Blob *text, void *opaque);
|
867
868
869
870
871
872
873
874
875
876
877
878
879
880
|
rndr->make.entity(ob, &work, rndr->make.opaque);
}else{
blob_append(ob, data, end);
}
return end;
}
/* char_langle_tag -- '<' when tags or autolinks are allowed */
static size_t char_langle_tag(
struct Blob *ob,
struct render *rndr,
char *data,
size_t offset,
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
|
rndr->make.entity(ob, &work, rndr->make.opaque);
}else{
blob_append(ob, data, end);
}
return end;
}
/* char_atref_tag -- '@' followed by "word" characters to tag
* at-references */
static size_t char_atref_tag(
struct Blob *ob,
struct render *rndr,
char *data,
size_t offset,
size_t size
){
size_t end;
struct Blob work = BLOB_INITIALIZER;
if (size < 2 || !isalpha(data[1])) return 0;
for (end = 2; (end < size) && isalnum(data[end]); ++end) /* */ ;
blob_init(&work, data + 1, end - 1);
rndr->make.tagspan(ob, &work, MKDT_ATREF, rndr->make.opaque);
return end;
}
/* char_hashref_tag -- '#' followed by "word" characters to tag
* post numbers, hashtags, etc. */
static size_t char_hashref_tag(
struct Blob *ob,
struct render *rndr,
char *data,
size_t offset,
size_t size
){
size_t end;
struct Blob work = BLOB_INITIALIZER;
if (size < 2 || !isalnum(data[1])) return 0;
for (end = 2; (end < size) && (isalnum(data[end] || data[end] == '.')); ++end) /* */ ;
blob_init(&work, data + 1, end - 1);
rndr->make.tagspan(ob, &work, MKDT_HASH, rndr->make.opaque);
return end;
}
/* char_langle_tag -- '<' when tags or autolinks are allowed */
static size_t char_langle_tag(
struct Blob *ob,
struct render *rndr,
char *data,
size_t offset,
|
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
|
for(i=0; rndr.make.emph_chars[i]; i++){
rndr.active_char[(unsigned char)rndr.make.emph_chars[i]] = char_emphasis;
}
}
if( rndr.make.codespan ) rndr.active_char['`'] = char_codespan;
if( rndr.make.linebreak ) rndr.active_char['\n'] = char_linebreak;
if( rndr.make.image || rndr.make.link ) rndr.active_char['['] = char_link;
rndr.active_char['<'] = char_langle_tag;
rndr.active_char['\\'] = char_escape;
rndr.active_char['&'] = char_entity;
/* first pass: looking for references, copying everything else */
beg = 0;
ib_data = blob_buffer(ib);
|
>
>
|
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
|
for(i=0; rndr.make.emph_chars[i]; i++){
rndr.active_char[(unsigned char)rndr.make.emph_chars[i]] = char_emphasis;
}
}
if( rndr.make.codespan ) rndr.active_char['`'] = char_codespan;
if( rndr.make.linebreak ) rndr.active_char['\n'] = char_linebreak;
if( rndr.make.image || rndr.make.link ) rndr.active_char['['] = char_link;
rndr.active_char['@'] = char_atref_tag;
rndr.active_char['#'] = char_hashref_tag;
rndr.active_char['<'] = char_langle_tag;
rndr.active_char['\\'] = char_escape;
rndr.active_char['&'] = char_entity;
/* first pass: looking for references, copying everything else */
beg = 0;
ib_data = blob_buffer(ib);
|