[writan] change code block syntax [format] conform to writan change
This commit is contained in:
parent
e99b22b9fb
commit
c413c2de86
25
format.c
25
format.c
|
@ -218,23 +218,31 @@ emit_link(FILE *input, FILE *output)
|
|||
|
||||
/* code blocks */
|
||||
void
|
||||
emit_code_block(char lastc, FILE *input, FILE *output)
|
||||
emit_code_block(char firstc, 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')
|
||||
if (firstc == '\n')
|
||||
fprintf(output, "<pre>");
|
||||
else
|
||||
fprintf(output, "<code>");
|
||||
|
||||
char c;
|
||||
while ((c = fgetc(input)) != ']') {
|
||||
for (;;) {
|
||||
char c = fgetc(input);
|
||||
|
||||
if (c == '`') {
|
||||
if (fgetc(input) == '`')
|
||||
break;
|
||||
else
|
||||
fseek(input, -1L, SEEK_CUR);
|
||||
}
|
||||
|
||||
if (c == EOF)
|
||||
die("Unexpected EOF while converting code block.");
|
||||
emit_sanitized_char(c, output);
|
||||
}
|
||||
|
||||
if (lastc == '\n')
|
||||
if (firstc == '\n')
|
||||
fprintf(output, "</pre>");
|
||||
else
|
||||
fprintf(output, "</code>");
|
||||
|
@ -282,8 +290,11 @@ format(FILE *input, FILE *output)
|
|||
fprintf(output, "<p>");
|
||||
emit_link(input, output);
|
||||
}
|
||||
else if (c == '[') { /* code block */
|
||||
emit_code_block(lastc, input, output);
|
||||
else if (c == '`') { /* code block */
|
||||
if (fgetc(input) == '`')
|
||||
emit_code_block(lastc, input, output);
|
||||
else
|
||||
fseek(input, -1L, SEEK_CUR);
|
||||
}
|
||||
else if (c == '>' && lastc == '\n') { /* quote */
|
||||
emit_blockquote(input, output);
|
||||
|
|
|
@ -18,17 +18,17 @@ newlines without affecting the output.}
|
|||
|
||||
Underneath is a code block.
|
||||
|
||||
[
|
||||
``
|
||||
(define (frob x)
|
||||
(frobnicate x))
|
||||
]
|
||||
``
|
||||
|
||||
This can also be written as
|
||||
|
||||
[(define (frob x)
|
||||
(forbnicate x))]
|
||||
``(define (frob x)
|
||||
(forbnicate x))``
|
||||
|
||||
You can inline [code] blocks.
|
||||
You can inline ``code`` blocks.
|
||||
|
||||
> Some profound text someone said once. This is a blockquote. It can occupy
|
||||
> multiple lines.
|
||||
|
|
|
@ -15,7 +15,7 @@ Some dialects of Lisp include Common Lisp, Scheme and Clojure.
|
|||
|
||||
A Lisp form consists of an operator followed by zero or more operands.
|
||||
|
||||
[(operator operand1 operand2 ...)]
|
||||
``(operator operand1 operand2 ...)``
|
||||
|
||||
The operator will be evaluated first, then the operands. Finally, the form will
|
||||
evaluate to the result of applying the operands to the operator. This is the
|
||||
|
@ -38,7 +38,8 @@ another Lisp form.
|
|||
|
||||
An example in Common Lisp:
|
||||
|
||||
[;; Example definition of let using a lambda for creating a local context
|
||||
``
|
||||
;; Example definition of let using a lambda for creating a local context
|
||||
|
||||
(defmacro my-let (bindings &body body)
|
||||
(let ((vars (mapcar #'car bindings))
|
||||
|
@ -56,7 +57,7 @@ An example in Common Lisp:
|
|||
((lambda (a b)
|
||||
(+ a b))
|
||||
1 2)
|
||||
]
|
||||
``
|
||||
|
||||
{https://tildegit.org/opfez/lisp-hacks Various Common Lisp hacks}
|
||||
{http://www.phyast.pitt.edu/~micheles/syntax-rules.pdf JRM's syntax-rules primer
|
||||
|
|
Loading…
Reference in New Issue