diff --git a/extra/farkup/farkup-tests.factor b/extra/farkup/farkup-tests.factor
index bdb08bd29a..af4ddd8839 100755
--- a/extra/farkup/farkup-tests.factor
+++ b/extra/farkup/farkup-tests.factor
@@ -52,7 +52,12 @@ IN: farkup.tests
[ "
foo
" ] [ "==foo==" convert-farkup ] unit-test
[ "foo
" ] [ "==foo==" convert-farkup ] unit-test
[ "=
foo
" ] [ "===foo==" convert-farkup ] unit-test
-
-
[ "foo
=
" ] [ "=foo==" convert-farkup ] unit-test
+[ "int main()
" ]
+[ "[c{int main()}]" convert-farkup ] unit-test
+
+[ "
" ] [ "[[image:lol.jpg]]" convert-farkup ] unit-test
+[ "
" ] [ "[[image:lol.jpg|teh lol]]" convert-farkup ] unit-test
+[ "
" ] [ "[[lol.com]]" convert-farkup ] unit-test
+[ "haha
" ] [ "[[lol.com|haha]]" convert-farkup ] unit-test
diff --git a/extra/farkup/farkup.factor b/extra/farkup/farkup.factor
index ac91a77685..142fc5de6c 100755
--- a/extra/farkup/farkup.factor
+++ b/extra/farkup/farkup.factor
@@ -55,10 +55,31 @@ MEMO: eq ( -- parser )
>r string-lines r>
[ [ htmlize-lines ] with-html-stream ] with-string-writer ;
+: escape-link ( href text -- href-esc text-esc )
+ >r escape-quoted-string r> escape-string ;
+
: make-link ( href text -- seq )
- >r escape-quoted-string r> escape-string
+ escape-link
[ "r , r> "\">" , [ , ] when* "" , ] { } make ;
+: make-image-link ( href alt -- seq )
+ escape-link
+ [
+ "
" , ]
+ { } make ;
+
+MEMO: image-link ( -- parser )
+ [
+ "[[image:" token hide ,
+ [ "|]" member? not ] satisfy repeat1 [ >string ] action ,
+ "|" token hide
+ [ CHAR: ] = not ] satisfy repeat0 2seq
+ [ first >string ] action optional ,
+ "]]" token hide ,
+ ] seq* [ first2 make-image-link ] action ;
+
MEMO: simple-link ( -- parser )
[
"[[" token hide ,
@@ -75,7 +96,7 @@ MEMO: labelled-link ( -- parser )
"]]" token hide ,
] seq* [ first2 make-link ] action ;
-MEMO: link ( -- parser ) [ simple-link , labelled-link , ] choice* ;
+MEMO: link ( -- parser ) [ image-link , simple-link , labelled-link , ] choice* ;
DEFER: line
MEMO: list-item ( -- parser )
@@ -101,13 +122,10 @@ MEMO: table ( -- parser )
MEMO: code ( -- parser )
[
"[" token hide ,
- [ "{" member? not ] satisfy repeat1 optional [ >string ] action ,
+ [ CHAR: { = not ] satisfy repeat1 optional [ >string ] action ,
"{" token hide ,
- [
- [ any-char , "}]" token ensure-not , ] seq*
- repeat1 [ concat >string ] action ,
- [ any-char , "}]" token hide , ] seq* optional [ >string ] action ,
- ] seq* [ concat ] action ,
+ "}]" token ensure-not any-char 2seq repeat0 [ concat >string ] action ,
+ "}]" token hide ,
] seq* [ first2 swap render-code ] action ;
MEMO: line ( -- parser )