diff --git a/markdown-printer.lisp b/markdown-printer.lisp index fcfba18..2a22faa 100644 --- a/markdown-printer.lisp +++ b/markdown-printer.lisp @@ -223,11 +223,27 @@ (foo parse-tree)) n)) +(defun starts-with-backtick-p (parse-tree) + (let ((a (first parse-tree))) + (and (stringp a) + (plusp (length a)) + (char= (aref a 0) #\`)))) + +(defun ends-with-backtick-p (parse-tree) + (let ((a (first (last parse-tree)))) + (and (stringp a) + (plusp (length a)) + (char= (aref a (1- (length a))) #\`)))) + (defmethod print-md-tagged-element ((tag (eql :code)) stream rest) (let ((n (max-n-consecutive-backticks rest))) (loop repeat (1+ n) do (write-char #\` stream)) (let ((*in-code* t)) - (dolist (a rest) (print-md-element a stream))) + (when (starts-with-backtick-p rest) + (write-char #\Space stream)) + (dolist (a rest) (print-md-element a stream)) + (when (ends-with-backtick-p rest) + (write-char #\Space stream))) (loop repeat (1+ n) do (write-char #\` stream)))) (defmacro define-smart-quote-md-translation (name replacement) diff --git a/tables.lisp b/tables.lisp index 9c676c2..fe205be 100644 --- a/tables.lisp +++ b/tables.lisp @@ -159,13 +159,13 @@ :body (((td (:plain "col" " " (:code "3") " " "is") left) (td (:plain "some" " " "wordy" " " "text") center) - (td (:plain "$1600") right)) + (td (:plain "$" "1600") right)) ((td (:plain "col" " " "2" " " "is") left) (td (:plain "centered") center) - (td (:plain "$12") right)) + (td (:plain "$" "12") right)) ((td (:plain "zebra" " " "stripes") left) (td (:plain "are" " " "neat") center) - (td (:plain "$1") right))))) + (td (:plain "$" "1") right))))) (parse-doc " | Left-Aligned | Center Aligned | Right Aligned | | :------------ |:---------------:| -----:| diff --git a/tests/extensions/tables.lisp b/tests/extensions/tables.lisp index 87a655d..011e024 100644 --- a/tests/extensions/tables.lisp +++ b/tests/extensions/tables.lisp @@ -62,13 +62,13 @@ :BODY (((TD (:PLAIN "col" " " (:CODE "3") " " "is") LEFT) (TD (:PLAIN "some" " " "wordy" " " "text") CENTER) - (TD (:PLAIN "$1600") RIGHT)) + (TD (:PLAIN "$" "1600") RIGHT)) ((TD (:PLAIN "col" " " "2" " " "is") LEFT) (TD (:PLAIN "centered") CENTER) - (TD (:PLAIN "$12") RIGHT)) + (TD (:PLAIN "$" "12") RIGHT)) ((TD (:PLAIN "zebra" " " "stripes") LEFT) (TD (:PLAIN "are" " " "neat") CENTER) - (TD (:PLAIN "$1") RIGHT))))) + (TD (:PLAIN "$" "1") RIGHT))))) (3bmd-tests::def-grammar-test tables-4 diff --git a/tests/printing/inline.lisp b/tests/printing/inline.lisp index 5bd2a6e..6065d68 100644 --- a/tests/printing/inline.lisp +++ b/tests/printing/inline.lisp @@ -163,3 +163,18 @@ :format :markdown :text "" :expected "") + +(def-print-test print-code-with-backticks-1 + :format :markdown + :text "``a`b``" + :expected "``a`b``") + +(def-print-test print-code-with-backticks-2 + :format :markdown + :text "``a` ``" + :expected "``a` ``") + +(def-print-test print-code-with-backticks-3 + :format :markdown + :text "`` `b``" + :expected "`` `b``")