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