summaryrefslogtreecommitdiff
path: root/markdown.c
diff options
context:
space:
mode:
Diffstat (limited to 'markdown.c')
-rw-r--r--markdown.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/markdown.c b/markdown.c
index 27a4a1b..3b812aa 100644
--- a/markdown.c
+++ b/markdown.c
@@ -19,7 +19,12 @@ static void output_md_text(FILE *out, int *flags, int line_number, const char *t
for (p = text; *p; ++p) {
if ((*flags & FLAG_CODE) && *p != '`') {
- putc(*p, out);
+ switch (*p) {
+ case '<': fprintf(out, "&lt;"); break;
+ case '>': fprintf(out, "&gt;"); break;
+ case '&': fprintf(out, "&amp;"); break;
+ default: putc(*p, out); break;
+ }
continue;
}
switch (*p) {
@@ -198,10 +203,18 @@ int main(int argc, char **argv) {
fprintf(out, "<pre><code>\n");
while (fgets(line, sizeof line, in)) {
+ char *p;
++line_number;
if (strncmp(line, "```", 3) == 0)
break;
- fprintf(out, "%s", line);
+ for (p = line; *p; ++p) {
+ switch (*p) {
+ case '<': fprintf(out, "&lt;"); break;
+ case '>': fprintf(out, "&gt;"); break;
+ case '&': fprintf(out, "&amp;"); break;
+ default: fputc(*p, out); break;
+ }
+ }
}
fprintf(out, "</code></pre>\n");