commit 1184807871e947148e2fcef3a8f248465f8490f9
parent 50fc055b2b4e505d6f65ea9b4c220a4bad66585b
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 16 Oct 2021 10:30:23 +0000
markdown: handle code blocks
Diffstat:
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/extra/Markdown.c b/extra/Markdown.c
@@ -13,6 +13,7 @@ enum {
TH0, TH1, TH2, TH3, TH4, TH5, TH6,
TWORD, TWBRK, TPBRK,
TLINK,
+ TCODEBLOCK,
TUNDEF = -1,
};
@@ -43,6 +44,8 @@ void llink(void);
void lladdr(void);
void lltitle(void);
+void lcodeblock(void);
+
char consume(void);
char peek(int);
void emit(void);
@@ -130,7 +133,10 @@ lnewline(void)
lex = llink;
consume();
emitwbrk();
- // emitpbrk();
+ break;
+ case '\t':
+ lex = lcodeblock;
+ consume();
break;
default:
lex = lword;
@@ -381,6 +387,26 @@ lltitle(void)
}
}
+void
+lcodeblock(void)
+{
+ switch (peek(0)){
+ case 0:
+ lex = nil;
+ break;
+ case '\n':
+ lex = lnewline;
+ s_putc(tok.s, consume());
+ s_terminate(tok.s);
+ tok.type = TCODEBLOCK;
+ emit();
+ tok.type = TUNDEF;
+ break;
+ default:
+ s_putc(tok.s, consume());
+ }
+}
+
char
consume(void)
{
@@ -494,6 +520,10 @@ printtoken(Token tok)
case TLINK:
link = s_to_c(tok.a);
break;
+ case TCODEBLOCK:
+ text = smprint("\t%s", s_to_c(tok.s));
+ font = "/lib/font/bit/terminus/unicode.16.font";
+ break;
default:
sysfatal("unknown token type %d for text \"%s\"", tok.type, text);
}