-
Notifications
You must be signed in to change notification settings - Fork 59
/
critic.c
111 lines (95 loc) · 2.71 KB
/
critic.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
/*
critic.c -- CriticMarkup preprocessor
<http://criticmarkup.com>
(c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License or the MIT
license. See LICENSE for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include "critic.h"
void print_critic_accept_node_tree(GString *out, node *list, scratch_pad *scratch) {
while (list != NULL) {
print_critic_accept_node(out, list, scratch);
list = list->next;
}
}
void print_critic_reject_node_tree(GString *out, node *list, scratch_pad *scratch) {
while (list != NULL) {
print_critic_reject_node(out, list, scratch);
list = list->next;
}
}
void print_critic_html_highlight_node_tree(GString *out, node *list, scratch_pad *scratch) {
while (list != NULL) {
print_critic_html_highlight_node(out, list, scratch);
list = list->next;
}
}
void print_critic_accept_node(GString *out, node *n, scratch_pad *scratch) {
if (n == NULL)
return;
switch (n->key) {
case LIST:
case CRITICSUBSTITUTION:
print_critic_accept_node_tree(out, n->children, scratch);
break;
case CRITICDELETION:
case CRITICCOMMENT:
break;
case CRITICHIGHLIGHT:
case CRITICADDITION:
default:
g_string_append_printf(out,"%s",n->str);
break;
}
}
void print_critic_reject_node(GString *out, node *n, scratch_pad *scratch) {
if (n == NULL)
return;
switch (n->key) {
case LIST:
case CRITICSUBSTITUTION:
print_critic_reject_node_tree(out, n->children, scratch);
break;
case CRITICADDITION:
case CRITICCOMMENT:
break;
case CRITICHIGHLIGHT:
case CRITICDELETION:
default:
g_string_append_printf(out,"%s",n->str);
break;
}
}
void print_critic_html_highlight_node(GString *out, node *n, scratch_pad *scratch) {
if (n == NULL)
return;
switch (n->key) {
case LIST:
print_critic_html_highlight_node_tree(out, n->children, scratch);
break;
case CRITICSUBSTITUTION:
print_critic_html_highlight_node_tree(out, n->children, scratch);
break;
case CRITICADDITION:
g_string_append_printf(out,"<ins>%s</ins>",n->str);
break;
case CRITICCOMMENT:
/* Hide comments for now */
/* g_string_append_printf(out, "<span class=\"critic comment\">%s</span>", n->str); */
break;
case CRITICHIGHLIGHT:
g_string_append_printf(out,"<mark>%s</mark>",n->str);
break;
case CRITICDELETION:
g_string_append_printf(out,"<del>%s</del>",n->str);
break;
default:
g_string_append_printf(out,"%s",n->str);
break;
}
}