ruricolist/spinneret

Wrong order of Markdown arguments in a link when both text and link are provided

svetlyak40wt opened this issue · 2 comments

A short demo

Set up the environment:

CL-USER> (defparameter *text* "The Text")
*TEXT*
CL-USER> (defparameter *url* "https://40ants.com")
*URL*

When I'm trying an example from the README, everything works like expected:

CL-USER> (spinneret:with-html
           ("Here is some copy, with [a link](~a)"
            *url*))

Here is some copy, with <a href="https://40ants.com">a link</a> 

But when I provide both, text and URL, the result is broken:

CL-USER> (spinneret:with-html
           ("Here is some copy, with [~a](~a)"
            *text*
            *url*))

Here is some copy, with <a href="The Text">https://40ants.com</a> 

The expected result is:

Here is some copy, with <a href="https://40ants.com">The Text</a> 

With manual calls to format and cl-markdown:markdown I'm getting the desired result:

CL-USER> (format nil "Here is some copy, with [~a](~a)"
                 *text*
                 *url*)
"Here is some copy, with [The Text](https://40ants.com)"
CL-USER> (with-output-to-string (s)
           (cl-markdown:markdown * :stream s))
"<p>Here is some copy, with <a href=\"https://40ants.com\">The Text</a> </p>"

Probably, it will be good idea along with a fix add a check which will fail if link argument is not starting from http or /, because such fix will make wrong result appear in all places where this markdown feature is used and it might be better to break everything, than to have many broken links on the whole site.

I am aware of this behavior, but I had not (previously) considered it a bug, simply a consequence of the unfortunate fact that Markdown and HTML take links and descriptions in the opposite order.

I will think however about whether there is some way to make the behavior less surprising without having to introduce a full HTML parser.

The problem with checking the link argument for / is that it would prevent relative links.