-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod_hoedown.c
918 lines (819 loc) · 29.3 KB
/
mod_hoedown.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
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
/*
** mod_hoedown.c -- Apache hoedown module
**
** Then activate it in Apache's httpd.conf file:
**
** # httpd.conf
** LoadModule hoedown_module modules/mod_hoedown.so
**
** HoedownDefaultPage /var/www/html/README.md
** HoedownDirectoryIndex index.md
** # Style file
** HoedownStylePath /var/www/html/style
** HoedownStyleDefault default
** HoedownStyleExtension .html
** # Class attribute
** HoedownClassUl ul-list
** HoedownClassOl ol-list
** HoedownClassTask task-list
** # Toc options
** HoedownTocHeader '<div class="toc">'
** HoedownTocFooter '</div>'
** HoedownTocBegin 2
** HoedownTocEnd 6
** HoedownTocUnescape Off
** # Raw options
** HoedownRaw On
** # Extension options
** HoedownExtSpaceHeaders Off
** HoedownExtTables Off
** HoedownExtFencedCode Off
** HoedownExtFootnotes Off
** HoedownExtAutolink Off
** HoedownExtStrikethrough Off
** HoedownExtUnderline Off
** HoedownExtHighlight Off
** HoedownExtQuote Off
** HoedownExtSuperscript Off
** HoedownExtLaxSpacing Off
** HoedownExtNoIntraEmphasis Off
** HoedownExtDisableIndentedCode Off
** HoedownExtSpecialAttribute Off
** # Html Render options
** HoedownRenderSkipHtml Off
** HoedownRenderSkipStyle Off
** HoedownRenderSkipImages Off
** HoedownRenderSkipLinks Off
** HoedownRenderExpandTabs Off
** HoedownRenderSafelink Off
** HoedownRenderToc Off
** HoedownRenderHardWrap Off
** HoedownRenderUseXhtml Off
** HoedownRenderEscape Off
** HoedownRenderUseTaskList Off
** HoedownRenderLineContinue Off
**
** <Location /hoedown>
** # AddHandler hoedown .md
** SetHandler hoedown
** </Location>
*/
/* httpd */
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_log.h"
#include "util_script.h"
#include "ap_config.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_hash.h"
/* apreq2 */
#include "apreq2/apreq_module_apache2.h"
#ifdef HAVE_CONFIG_H
# undef PACKAGE_NAME
# undef PACKAGE_STRING
# undef PACKAGE_TARNAME
# undef PACKAGE_VERSION
# include "config.h"
#endif
#ifdef HOEDOWN_URL_SUPPORT
/* libcurl */
#include "curl/curl.h"
#endif
/* hoedown */
#include "hoedown/src/version.h"
#include "hoedown/src/document.h"
#include "hoedown/src/html.h"
#include "hoedown/src/buffer.h"
#ifdef __GNUC__
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#else
# define UNUSED(x) UNUSED_ ## x
#endif
#define HOEDOWN_READ_UNIT 1024
#define HOEDOWN_OUTPUT_UNIT 64
#define HOEDOWN_CURL_TIMEOUT 30
#define HOEDOWN_TITLE_DEFAULT "Markdown"
#define HOEDOWN_TITLE_MARKER "$title"
#define HOEDOWN_CONTENT_TYPE "text/html"
#define HOEDOWN_TAG "<body*>"
#define HOEDOWN_STYLE_EXT ".html"
#define HOEDOWN_DIRECTORY_INDEX "index.md"
#define HOEDOWN_TOC_BEGIN 2
#define HOEDOWN_TOC_END 6
typedef struct {
char *default_page;
char *directory_index;
struct {
char *path;
char *name;
char *ext;
} style;
struct {
char *ul;
char *ol;
char *task;
} class;
struct {
int begin;
int end;
int unescape;
char *header;
char *footer;
} toc;
int raw;
unsigned int extensions;
unsigned int html;
} hoedown_config_rec;
module AP_MODULE_DECLARE_DATA hoedown_module;
static int
output_style_header(request_rec *r, apr_file_t *fp, char const *markdown_title)
{
char buf[HUGE_STRING_LEN];
char *lower = NULL;
while (apr_file_gets(buf, HUGE_STRING_LEN, fp) == APR_SUCCESS) {
char *p = strstr(buf, HOEDOWN_TITLE_MARKER);
if (!p) {
ap_rputs(buf, r);
} else {
ap_rwrite(buf, p - buf, r);
ap_rputs(markdown_title, r);
ap_rputs(p + strlen(HOEDOWN_TITLE_MARKER), r);
}
lower = apr_pstrdup(r->pool, buf);
ap_str_tolower(lower);
if (apr_fnmatch("*"HOEDOWN_TAG"*", lower, APR_FNM_CASE_BLIND) == 0) {
return 1;
}
}
return 0;
}
static apr_file_t *
style_header(request_rec *r, hoedown_config_rec *cfg,
char const *style_filename, char const *markdown_filename)
{
apr_status_t rc = -1;
apr_file_t *fp = NULL;
char *style_filepath = NULL;
char *markdown_title;
if (markdown_filename) {
char const *p, *pp, *ps;
p = pp = ps = rawmemchr(markdown_filename, '\0');
while (ps >= markdown_filename && *ps != '/') {
ps--;
}
if (ps <= markdown_filename) {
ps = markdown_filename;
} else {
ps++;
}
while (p >= ps && *p != '.') {
p--;
}
if (p < ps) {
p = pp;
}
markdown_title = apr_pstrndup(r->pool, ps, p - ps);
} else {
markdown_title = HOEDOWN_TITLE_DEFAULT;
}
if (style_filename == NULL && cfg->style.name != NULL) {
style_filename = cfg->style.name;
}
if (style_filename != NULL) {
if (cfg->style.path == NULL) {
ap_add_common_vars(r);
cfg->style.path = (char *)apr_table_get(r->subprocess_env,
"DOCUMENT_ROOT");
}
style_filepath = apr_psprintf(r->pool, "%s/%s%s",
cfg->style.path, style_filename,
cfg->style.ext);
rc = apr_file_open(&fp, style_filepath,
APR_READ | APR_BINARY | APR_XTHREAD,
APR_OS_DEFAULT, r->pool);
if (rc == APR_SUCCESS) {
if (output_style_header(r, fp, markdown_title) != 1) {
apr_file_close(fp);
fp = NULL;
}
} else {
style_filepath = apr_psprintf(r->pool, "%s/%s%s",
cfg->style.path,
cfg->style.name,
cfg->style.ext);
rc = apr_file_open(&fp, style_filepath,
APR_READ | APR_BINARY | APR_XTHREAD,
APR_OS_DEFAULT, r->pool);
if (rc == APR_SUCCESS) {
if (output_style_header(r, fp, markdown_title) != 1) {
apr_file_close(fp);
fp = NULL;
}
}
}
}
if (rc != APR_SUCCESS) {
ap_rputs("<!DOCTYPE html>\n<html>\n", r);
ap_rprintf(r, "<head><title>%s</title></head>\n", markdown_title);
ap_rputs("<body>\n", r);
}
return fp;
}
static int
style_footer(request_rec *r, apr_file_t *fp) {
char buf[HUGE_STRING_LEN];
if (fp != NULL) {
while (apr_file_gets(buf, HUGE_STRING_LEN, fp) == APR_SUCCESS) {
ap_rputs(buf, r);
}
apr_file_close(fp);
} else {
ap_rputs("</body>\n</html>\n", r);
}
return 0;
}
static void
append_data(hoedown_buffer *ib, void *buffer, size_t size)
{
size_t offset = 0;
if (!ib || !buffer || size == 0) {
return;
}
while (offset < size) {
size_t bufsize = ib->asize - ib->size;
if (size >= (bufsize + offset)) {
memcpy(ib->data + ib->size, buffer + offset, bufsize);
ib->size += bufsize;
hoedown_buffer_grow(ib, ib->size + HOEDOWN_READ_UNIT);
offset += bufsize;
} else {
bufsize = size - offset;
if (bufsize > 0) {
memcpy(ib->data + ib->size, buffer + offset, bufsize);
ib->size += bufsize;
}
break;
}
}
}
#ifdef HOEDOWN_URL_SUPPORT
static size_t
append_url_data(void *buffer, size_t size, size_t nmemb, void *user)
{
size_t segsize = size * nmemb;
append_data((hoedown_buffer *)user, buffer, segsize);
return segsize;
}
#endif
static int
append_page_data(request_rec *r, hoedown_config_rec *cfg,
hoedown_buffer *ib, char *name, int directory)
{
apr_status_t rc = -1;
apr_file_t *fp = NULL;
apr_size_t read;
char *filename = NULL;
if (name == NULL) {
if (!cfg->default_page) {
return HTTP_NOT_FOUND;
}
filename = cfg->default_page;
} else if (strlen(name) <= 0 ||
memcmp(name + strlen(name) - 1, "/", 1) == 0) {
if (!cfg->directory_index || !directory) {
return HTTP_FORBIDDEN;
}
filename = apr_psprintf(r->pool, "%s%s", name, cfg->directory_index);
} else {
filename = name;
}
rc = apr_file_open(&fp, filename,
APR_READ | APR_BINARY | APR_XTHREAD, APR_OS_DEFAULT,
r->pool);
if (rc != APR_SUCCESS || !fp) {
switch (errno) {
case ENOENT:
return HTTP_NOT_FOUND;
case EACCES:
return HTTP_FORBIDDEN;
default:
break;
}
return HTTP_INTERNAL_SERVER_ERROR;
}
do {
rc = apr_file_read_full(fp, ib->data + ib->size, ib->asize - ib->size,
&read);
if (read > 0) {
ib->size += read;
hoedown_buffer_grow(ib, ib->size + HOEDOWN_READ_UNIT);
}
} while (rc != APR_EOF);
apr_file_close(fp);
return APR_SUCCESS;
}
/* content handler */
static int
hoedown_handler(request_rec *r)
{
int ret = -1;
int directory = 1;
apr_file_t *fp = NULL;
char *style = NULL;
char *url = NULL;
char *text = NULL;
char *raw = NULL;
char *toc = NULL;
int toc_begin = HOEDOWN_TOC_BEGIN, toc_end = HOEDOWN_TOC_END;
apreq_handle_t *apreq;
apr_table_t *params;
hoedown_config_rec *cfg;
/* hoedown: markdown */
hoedown_buffer *ib, *ob;
hoedown_document *markdown;
hoedown_renderer *renderer;
hoedown_html_renderer_state *state;
if (strcmp(r->handler, "hoedown")) {
return DECLINED;
}
if (r->header_only) {
return OK;
}
/* config */
cfg = ap_get_module_config(r->per_dir_config, &hoedown_module);
/* set contest type */
r->content_type = HOEDOWN_CONTENT_TYPE;
/* get parameter */
apreq = apreq_handle_apache2(r);
params = apreq_params(apreq, r->pool);
if (params) {
style = (char *)apreq_params_as_string(r->pool, params,
"style", APREQ_JOIN_AS_IS);
#ifdef HOEDOWN_URL_SUPPORT
url = (char *)apreq_params_as_string(r->pool, params,
"url", APREQ_JOIN_AS_IS);
#endif
if (cfg->raw != 0) {
raw = (char *)apr_table_get(params, "raw");
}
if (cfg->html & HOEDOWN_HTML_TOC) {
toc = (char *)apr_table_get(params, "toc");
}
if (r->method_number == M_POST) {
text = (char *)apreq_params_as_string(r->pool, params,
"markdown", APREQ_JOIN_AS_IS);
}
}
/* reading everything */
ib = hoedown_buffer_new(HOEDOWN_READ_UNIT);
hoedown_buffer_grow(ib, HOEDOWN_READ_UNIT);
/* page */
if (url || text) {
directory = 0;
}
append_page_data(r, cfg, ib, r->filename, directory);
/* text */
if (text && strlen(text) > 0) {
append_data(ib, text, strlen(text));
}
#ifdef HOEDOWN_URL_SUPPORT
/* url */
if (url && strlen(url) > 0) {
CURL *curl;
curl = curl_easy_init();
if (!curl) {
return HTTP_INTERNAL_SERVER_ERROR;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
/* curl */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)ib);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append_url_data);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HOEDOWN_CURL_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
/*
if (ret != 0) {
hoedown_buffer_free(ib);
return HTTP_INTERNAL_SERVER_ERROR;
}
*/
}
#endif
/* default page */
if (ib->size == 0) {
ret = append_page_data(r, cfg, ib, NULL, 0);
if (ret != APR_SUCCESS) {
hoedown_buffer_free(ib);
return ret;
}
}
/* default toc level */
toc_begin = cfg->toc.begin;
toc_end = cfg->toc.end;
if (ib->size > 0) {
if (cfg->raw != 0 && raw != NULL) {
r->content_type = "text/plain";
ap_rwrite(ib->data, ib->size, r);
hoedown_buffer_free(ib);
return OK;
}
/* output style header */
fp = style_header(r, cfg, style, r->filename);
/* performing markdown parsing */
ob = hoedown_buffer_new(HOEDOWN_OUTPUT_UNIT);
/* toc */
if (cfg->html & HOEDOWN_HTML_TOC) {
if (toc) {
size_t len = strlen(toc);
int n;
if (len > 0) {
char *delim, *toc_b = NULL, *toc_e = NULL;
delim = strstr(toc, ":");
if (delim) {
int i = delim - toc;
toc_b = apr_pstrndup(r->pool, toc, i++);
n = atoi(toc_b);
if (n) {
toc_begin = n;
}
toc_e = apr_pstrndup(r->pool, toc + i, len - i);
n = atoi(toc_e);
if (n) {
toc_end = n;
}
} else {
n = atoi(toc);
if (n) {
toc_begin = n;
}
}
}
}
renderer = hoedown_html_toc_renderer_new(0);
state = (hoedown_html_renderer_state *)renderer->opaque;
state->flags = cfg->html;
state->toc_data.level_offset = toc_begin;
state->toc_data.nesting_level = toc_end;
#ifdef HOEDOWN_VERSION_EXTRAS
state->toc_data.header = cfg->toc.header;
state->toc_data.footer = cfg->toc.footer;
state->toc_data.unescape = cfg->toc.unescape;
#endif
markdown = hoedown_document_new(renderer, cfg->extensions, 16);
hoedown_document_render(markdown, ob, ib->data, ib->size);
hoedown_document_free(markdown);
hoedown_html_renderer_free(renderer);
ap_rwrite(ob->data, ob->size, r);
hoedown_buffer_reset(ob);
}
/* markdown render */
renderer = hoedown_html_renderer_new(cfg->html, toc_end);
#ifdef HOEDOWN_VERSION_EXTRAS
state = (hoedown_html_renderer_state *)renderer->opaque;
if ((state->flags & HOEDOWN_HTML_USE_TASK_LIST) && cfg->class.task) {
state->class_data.task = cfg->class.task;
}
if (cfg->class.ol) {
state->class_data.ol = cfg->class.ol;
}
if (cfg->class.ul) {
state->class_data.ul = cfg->class.ul;
}
#endif
markdown = hoedown_document_new(renderer, cfg->extensions, 16);
hoedown_document_render(markdown, ob, ib->data, ib->size);
hoedown_document_free(markdown);
hoedown_html_renderer_free(renderer);
/* writing the result */
ap_rwrite(ob->data, ob->size, r);
/* cleanup */
hoedown_buffer_free(ob);
} else {
/* output style header */
fp = style_header(r, cfg, style, r->filename);
}
/* cleanup */
hoedown_buffer_free(ib);
/* output style footer */
style_footer(r, fp);
return OK;
}
static void *
hoedown_create_dir_config(apr_pool_t *p, char * UNUSED(dir))
{
hoedown_config_rec *cfg;
cfg = apr_pcalloc(p, sizeof(hoedown_config_rec));
memset(cfg, 0, sizeof(hoedown_config_rec));
cfg->default_page = NULL;
cfg->directory_index = HOEDOWN_DIRECTORY_INDEX;
cfg->style.path = NULL;
cfg->style.name = NULL;
cfg->style.ext = HOEDOWN_STYLE_EXT;
cfg->class.ul = NULL;
cfg->class.ol = NULL;
cfg->class.task = NULL;
cfg->toc.begin = HOEDOWN_TOC_BEGIN;
cfg->toc.end = HOEDOWN_TOC_END;
cfg->toc.header = NULL;
cfg->toc.footer = NULL;
cfg->toc.unescape = 0;
cfg->raw = 0;
cfg->html = 0;
cfg->extensions =
HOEDOWN_EXT_TABLES | HOEDOWN_EXT_FENCED_CODE |
HOEDOWN_EXT_AUTOLINK | HOEDOWN_EXT_STRIKETHROUGH |
HOEDOWN_EXT_NO_INTRA_EMPHASIS;
return (void *)cfg;
}
static void *
hoedown_merge_dir_config(apr_pool_t *p, void *base_conf, void *override_conf)
{
hoedown_config_rec *cfg = apr_pcalloc(p, sizeof(hoedown_config_rec));
hoedown_config_rec *base = (hoedown_config_rec *)base_conf;
hoedown_config_rec *override = (hoedown_config_rec *)override_conf;
if (override->default_page && strlen(override->default_page) > 0) {
cfg->default_page = override->default_page;
} else {
cfg->default_page = base->default_page;
}
if (strcmp(override->directory_index, HOEDOWN_DIRECTORY_INDEX) != 0) {
cfg->directory_index = override->directory_index;
} else {
cfg->directory_index = base->directory_index;
}
if (override->style.path && strlen(override->style.path) > 0) {
cfg->style.path = override->style.path;
} else {
cfg->style.path = base->style.path;
}
if (override->style.name && strlen(override->style.name) > 0) {
cfg->style.name = override->style.name;
} else {
cfg->style.name = base->style.name;
}
if (strcmp(override->style.ext, HOEDOWN_STYLE_EXT) != 0) {
cfg->style.ext = override->style.ext;
} else {
cfg->style.ext = base->style.ext;
}
#ifdef HOEDOWN_VERSION_EXTRAS
if (override->class.ul && strlen(override->class.ul) > 0) {
cfg->class.ul = override->class.ul;
} else {
cfg->class.ul = base->class.ul;
}
if (override->class.ol && strlen(override->class.ol) > 0) {
cfg->class.ol = override->class.ol;
} else {
cfg->class.ol = base->class.ol;
}
if (override->class.task && strlen(override->class.task) > 0) {
cfg->class.task = override->class.task;
} else {
cfg->class.task = base->class.task;
}
#endif
if (override->toc.begin != HOEDOWN_TOC_BEGIN) {
cfg->toc.begin = override->toc.begin;
} else {
cfg->toc.begin = base->toc.begin;
}
if (override->toc.end != HOEDOWN_TOC_END) {
cfg->toc.end = override->toc.end;
} else {
cfg->toc.end = base->toc.end;
}
#ifdef HOEDOWN_VERSION_EXTRAS
if (override->toc.header && strlen(override->toc.header) > 0) {
cfg->toc.header = override->toc.header;
} else {
cfg->toc.header = base->toc.header;
}
if (override->toc.footer && strlen(override->toc.footer) > 0) {
cfg->toc.footer = override->toc.footer;
} else {
cfg->toc.footer = base->toc.footer;
}
if (override->toc.unescape) {
cfg->toc.unescape = override->toc.unescape;
} else {
cfg->toc.unescape = base->toc.unescape;
}
#endif
if (override->raw != 0) {
cfg->raw = 1;
} else {
cfg->raw = base->raw;
}
if (override->extensions > 0) {
cfg->extensions = override->extensions;
} else {
cfg->extensions = base->extensions;
}
if (override->html > 0) {
cfg->html = override->html;
} else {
cfg->html = base->html;
}
return (void *)cfg;
}
#define HOEDOWN_SET_EXTENSIONS(_name, _ext) \
static const char * \
hoedown_set_extensions_ ## _name( \
cmd_parms * UNUSED(parms), void *mconfig, int bool) { \
hoedown_config_rec *cfg = (hoedown_config_rec *)mconfig; \
if (bool != 0) { \
cfg->extensions |= _ext; \
} else { \
cfg->extensions ^= _ext; \
} \
return NULL; \
}
HOEDOWN_SET_EXTENSIONS(spaceheaders, HOEDOWN_EXT_SPACE_HEADERS);
HOEDOWN_SET_EXTENSIONS(tables, HOEDOWN_EXT_TABLES);
HOEDOWN_SET_EXTENSIONS(fencedcode, HOEDOWN_EXT_FENCED_CODE);
HOEDOWN_SET_EXTENSIONS(footnotes, HOEDOWN_EXT_FOOTNOTES);
HOEDOWN_SET_EXTENSIONS(autolink, HOEDOWN_EXT_AUTOLINK);
HOEDOWN_SET_EXTENSIONS(strikethrough, HOEDOWN_EXT_STRIKETHROUGH);
HOEDOWN_SET_EXTENSIONS(underline, HOEDOWN_EXT_UNDERLINE);
HOEDOWN_SET_EXTENSIONS(highlight, HOEDOWN_EXT_HIGHLIGHT);
HOEDOWN_SET_EXTENSIONS(quote, HOEDOWN_EXT_QUOTE);
HOEDOWN_SET_EXTENSIONS(superscript, HOEDOWN_EXT_SUPERSCRIPT);
HOEDOWN_SET_EXTENSIONS(laxspacing, HOEDOWN_EXT_LAX_SPACING);
HOEDOWN_SET_EXTENSIONS(nointraemphasis, HOEDOWN_EXT_NO_INTRA_EMPHASIS);
HOEDOWN_SET_EXTENSIONS(disableindentedcode, HOEDOWN_EXT_DISABLE_INDENTED_CODE);
#ifdef HOEDOWN_VERSION_EXTRAS
HOEDOWN_SET_EXTENSIONS(specialattribute, HOEDOWN_EXT_SPECIAL_ATTRIBUTE);
#endif
#define HOEDOWN_SET_RENDER(_name, _ext) \
static const char * \
hoedown_set_render_ ## _name( \
cmd_parms * UNUSED(parms), void *mconfig, int bool) { \
hoedown_config_rec *cfg = (hoedown_config_rec *)mconfig; \
if (bool != 0) { \
cfg->html |= _ext; \
} else { \
cfg->html ^= _ext; \
} \
return NULL; \
}
HOEDOWN_SET_RENDER(skiphtml, HOEDOWN_HTML_SKIP_HTML);
HOEDOWN_SET_RENDER(skipstyle, HOEDOWN_HTML_SKIP_STYLE);
HOEDOWN_SET_RENDER(skipimages, HOEDOWN_HTML_SKIP_IMAGES);
HOEDOWN_SET_RENDER(skiplinks, HOEDOWN_HTML_SKIP_LINKS);
HOEDOWN_SET_RENDER(expandtabs, HOEDOWN_HTML_EXPAND_TABS);
HOEDOWN_SET_RENDER(safelink, HOEDOWN_HTML_SAFELINK);
HOEDOWN_SET_RENDER(toc, HOEDOWN_HTML_TOC);
HOEDOWN_SET_RENDER(hardwrap, HOEDOWN_HTML_HARD_WRAP);
HOEDOWN_SET_RENDER(usexhtml, HOEDOWN_HTML_USE_XHTML);
HOEDOWN_SET_RENDER(escape, HOEDOWN_HTML_ESCAPE);
#ifdef HOEDOWN_VERSION_EXTRAS
HOEDOWN_SET_RENDER(usetasklist, HOEDOWN_HTML_USE_TASK_LIST);
HOEDOWN_SET_RENDER(linecontinue, HOEDOWN_HTML_LINE_CONTINUE);
#endif
static const command_rec
hoedown_cmds[] = {
AP_INIT_TAKE1("HoedownDefaultPage", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, default_page),
OR_ALL, "hoedown default page file"),
AP_INIT_TAKE1("HoedownDirectoryIndex", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, directory_index),
OR_ALL, "hoedown directory index page"),
/* Style file */
AP_INIT_TAKE1("HoedownStylePath", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, style.path),
OR_ALL, "hoedown style path"),
AP_INIT_TAKE1("HoedownStyleDefault", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, style.name),
OR_ALL, "hoedown default style file name"),
AP_INIT_TAKE1("HoedownStyleExtension", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, style.ext),
OR_ALL, "hoedown default style file extension"),
#ifdef HOEDOWN_VERSION_EXTRAS
/* Class name */
AP_INIT_TAKE1("HoedownClassUl", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, class.ul),
OR_ALL, "hoedown ul class attributes"),
AP_INIT_TAKE1("HoedownClassOl", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, class.ol),
OR_ALL, "hoedown ol class attributes"),
AP_INIT_TAKE1("HoedownClassTask", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, class.task),
OR_ALL, "hoedown task list class attributes"),
#endif
/* Toc options */
AP_INIT_TAKE1("HoedownTocBegin", ap_set_int_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, toc.begin),
OR_ALL, "hoedown toc begin level"),
AP_INIT_TAKE1("HoedownTocEnd", ap_set_int_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, toc.end),
OR_ALL, "hoedown toc end level"),
#ifdef HOEDOWN_VERSION_EXTRAS
AP_INIT_TAKE1("HoedownTocHeader", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, toc.header),
OR_ALL, "hoedown toc header"),
AP_INIT_TAKE1("HoedownTocFooter", ap_set_string_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, toc.footer),
OR_ALL, "hoedown toc footer"),
AP_INIT_FLAG("HoedownTocUnescape", ap_set_flag_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, toc.unescape),
OR_ALL, "hoedown toc unescape"),
#endif
/* Raw options */
AP_INIT_FLAG("HoedownRaw", ap_set_flag_slot,
(void *)APR_OFFSETOF(hoedown_config_rec, raw),
OR_ALL, "Enable hoedown raw support"),
/* Markdown extension options */
AP_INIT_FLAG("HoedownExtSpaceHeaders",
hoedown_set_extensions_spaceheaders,
NULL, OR_ALL, "Enable hoedown extension Space Headers"),
AP_INIT_FLAG("HoedownExtTables",
hoedown_set_extensions_tables,
NULL, OR_ALL, "Enable hoedown extension Tables"),
AP_INIT_FLAG("HoedownExtFencedCode",
hoedown_set_extensions_fencedcode,
NULL, OR_ALL, "Enable hoedown extension Fenced Code"),
AP_INIT_FLAG("HoedownExtFootnotes",
hoedown_set_extensions_footnotes,
NULL, OR_ALL, "Enable hoedown extension Footnotes"),
AP_INIT_FLAG("HoedownExtAutolink",
hoedown_set_extensions_autolink,
NULL, OR_ALL, "Enable hoedown extension Autolink"),
AP_INIT_FLAG("HoedownExtStrikethrough",
hoedown_set_extensions_strikethrough,
NULL, OR_ALL, "Enable hoedown extension Strikethrough"),
AP_INIT_FLAG("HoedownExtUnderline",
hoedown_set_extensions_underline,
NULL, OR_ALL, "Enable hoedown extension Underline"),
AP_INIT_FLAG("HoedownExtHighlight",
hoedown_set_extensions_highlight,
NULL, OR_ALL, "Enable hoedown extension Highlight"),
AP_INIT_FLAG("HoedownExtQuote",
hoedown_set_extensions_quote,
NULL, OR_ALL, "Enable hoedown extension Quote"),
AP_INIT_FLAG("HoedownExtSuperscript",
hoedown_set_extensions_superscript,
NULL, OR_ALL, "Enable hoedown extension Superscript"),
AP_INIT_FLAG("HoedownExtLaxSpacing",
hoedown_set_extensions_laxspacing,
NULL, OR_ALL, "Enable hoedown extension Lax Spacing"),
AP_INIT_FLAG("HoedownExtNoIntraEmphasis",
hoedown_set_extensions_nointraemphasis,
NULL, OR_ALL, "Enable hoedown extension NoIntraEmphasis"),
AP_INIT_FLAG("HoedownExtDisableIndentedCode",
hoedown_set_extensions_disableindentedcode,
NULL, OR_ALL, "Disable hoedown extension Indented Code"),
#ifdef HOEDOWN_VERSION_EXTRAS
AP_INIT_FLAG("HoedownExtSpecialAttribute",
hoedown_set_extensions_specialattribute,
NULL, OR_ALL, "Enable hoedown extension Special Attribute"),
#endif
/* Html Render mode options */
AP_INIT_FLAG("HoedownRenderSkipHtml", hoedown_set_render_skiphtml,
NULL, OR_ALL, "Enable hoedown render Skip HTML"),
AP_INIT_FLAG("HoedownRenderSkipStyle", hoedown_set_render_skipstyle,
NULL, OR_ALL, "Enable hoedown render Skip Style"),
AP_INIT_FLAG("HoedownRenderSkipImages", hoedown_set_render_skipimages,
NULL, OR_ALL, "Enable hoedown render Skip Images"),
AP_INIT_FLAG("HoedownRenderSkipLinks", hoedown_set_render_skiplinks,
NULL, OR_ALL, "Enable hoedown render Skip Links"),
AP_INIT_FLAG("HoedownRenderExpandTabs", hoedown_set_render_expandtabs,
NULL, OR_ALL, "Enable hoedown render Expand Tabs"),
AP_INIT_FLAG("HoedownRenderSafelink", hoedown_set_render_safelink,
NULL, OR_ALL, "Enable hoedown render Safelink"),
AP_INIT_FLAG("HoedownRenderToc", hoedown_set_render_toc,
NULL, OR_ALL, "Enable hoedown render Toc"),
AP_INIT_FLAG("HoedownRenderHardWrap", hoedown_set_render_hardwrap,
NULL, OR_ALL, "Enable hoedown render Hard Wrap"),
AP_INIT_FLAG("HoedownRenderUseXhtml", hoedown_set_render_usexhtml,
NULL, OR_ALL, "Enable hoedown render Use XHTML"),
AP_INIT_FLAG("HoedownRenderEscape", hoedown_set_render_escape,
NULL, OR_ALL, "Enable hoedown render Escape"),
#ifdef HOEDOWN_VERSION_EXTRAS
AP_INIT_FLAG("HoedownRenderUseTaskList", hoedown_set_render_usetasklist,
NULL, OR_ALL, "Enable hoedown render Use Task List"),
AP_INIT_FLAG("HoedownRenderLineContinue", hoedown_set_render_linecontinue,
NULL, OR_ALL, "Enable hoedown render Line Continue"),
#endif
{NULL}
};
static void
hoedown_register_hooks(apr_pool_t * UNUSED(p))
{
ap_hook_handler(hoedown_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA hoedown_module =
{
STANDARD20_MODULE_STUFF,
hoedown_create_dir_config, /* create per-dir config structures */
hoedown_merge_dir_config, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
hoedown_cmds, /* table of config file commands */
hoedown_register_hooks /* register hooks */
};