[writan/format] add support for inlined code blocks
This commit is contained in:
parent
1d11c03fc1
commit
9768a37f20
12
format.c
12
format.c
|
@ -218,9 +218,14 @@ emit_link(FILE *input, FILE *output)
|
|||
|
||||
/* code blocks */
|
||||
void
|
||||
emit_code_block(FILE *input, FILE *output)
|
||||
emit_code_block(char lastc, FILE *input, FILE *output)
|
||||
{
|
||||
/* if this code block is on a separate line, create a <pre>. otherwise, it
|
||||
* is inlined in a paragraph and we want a <code>. */
|
||||
if (lastc == '\n')
|
||||
fprintf(output, "<pre>");
|
||||
else
|
||||
fprintf(output, "<code>");
|
||||
|
||||
char c;
|
||||
while ((c = fgetc(input)) != ']') {
|
||||
|
@ -229,7 +234,10 @@ emit_code_block(FILE *input, FILE *output)
|
|||
emit_sanitized_char(c, output);
|
||||
}
|
||||
|
||||
if (lastc == '\n')
|
||||
fprintf(output, "</pre>");
|
||||
else
|
||||
fprintf(output, "</code>");
|
||||
}
|
||||
|
||||
/* blockquotes */
|
||||
|
@ -275,7 +283,7 @@ format(FILE *input, FILE *output)
|
|||
emit_link(input, output);
|
||||
}
|
||||
else if (c == '[') { /* code block */
|
||||
emit_code_block(input, output);
|
||||
emit_code_block(lastc, input, output);
|
||||
}
|
||||
else if (c == '>' && lastc == '\n') { /* quote */
|
||||
emit_blockquote(input, output);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
:root {
|
||||
--fg: #ddd;
|
||||
--bg: #111;
|
||||
--pre-bg: #1a1a1a;
|
||||
--code-bg: #1a1a1a;
|
||||
/* --bg: #eee; */
|
||||
/* --fg: #111; */
|
||||
/* --pre-bg: #dedede */
|
||||
/* --code-bg: #dedede */
|
||||
}
|
||||
|
||||
body {
|
||||
|
@ -27,11 +27,16 @@ a:hover {
|
|||
background: var(--fg);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--pre-bg);
|
||||
code {
|
||||
background: var(--code-bg);
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
code {
|
||||
background: var(--code-bg);
|
||||
padding: 0.2em;
|
||||
}
|
||||
|
||||
hr {
|
||||
width: 50%;
|
||||
border-top: 0px;
|
||||
|
|
|
@ -23,5 +23,12 @@ Underneath is a code block.
|
|||
(frobnicate x))
|
||||
]
|
||||
|
||||
This can also be written as
|
||||
|
||||
[(define (frob x)
|
||||
(forbnicate x))]
|
||||
|
||||
You can inline [code] blocks.
|
||||
|
||||
> Some profound text someone said once. This is a blockquote. It can occupy
|
||||
> multiple lines.
|
||||
|
|
Loading…
Reference in New Issue
Block a user