Commits

Dominic Kexel committed 38c4169

allow titles in images
allow single quote attributes in links

Comments (0)

Files changed (3)

src/mdclj/html.clj

 (defmethod format-span :mdclj.spans/link [{inner :content url :url title :title}]
   (output-element "a" {"href" url "title" title} (content-parser inner)))
 
-(defmethod format-span :mdclj.spans/image [{inner :content url :url}]
-  (output-element "img" {"src" url "alt" inner}))
+(defmethod format-span :mdclj.spans/image [{inner :content url :url title :title}]
+  (output-element "img" {"src" url "alt" inner "title" title}))
 
 (defmethod format-span :mdclj.spans/hard-break [span]
   (output-element "br"))

src/mdclj/spans.clj

           (concat-spans acc span remaining)))))
 
 (defn- extract-link-title [text]
-  (-> text  
-      (to-string)
-      (clojure.string/replace #"\"$" "")
-      (clojure.string/replace #"^\"" "")))
+  (reduce #(clojure.string/replace % %2 "") (to-string text) [#"\"$" #"'$" #"^\"" #"^'"]))  
 
 (defn- parse-link-text [linktext]
   (let [[link title] (clojure.string/split (to-string linktext) #" " 2)]

test/mdclj/test/html.clj

 (deftest parse-urls
   (is (= (format-blocks (parse-text "[Example](http://example.com Click Me!)")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
   (is (= (format-blocks (parse-text "[Example](http://example.com \"Click Me!\")")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
+  (is (= (format-blocks (parse-text "[Example](http://example.com 'Click Me!')")) "<p><a href=\"http://example.com\" title=\"Click Me!\">Example</a></p>"))
   (is (= (format-blocks (parse-text "[Example](http://example.com)")) "<p><a href=\"http://example.com\">Example</a></p>"))
-  (is (= (format-blocks (parse-text "![](http://example.com)")) "<p><img src=\"http://example.com\" /></p>"))
-  (is (= (format-blocks (parse-text "![Example](http://example.com Click Me!)")) "<p><img src=\"http://example.com\" alt=\"Example\" /></p>")))
+  (is (= (format-blocks (parse-text "![](http://example.com)"))                      "<p><img src=\"http://example.com\" /></p>"))
+  (is (= (format-blocks (parse-text "![Example](http://example.com \"Click Me!\")")) "<p><img src=\"http://example.com\" alt=\"Example\" title=\"Click Me!\" /></p>"))
+  (is (= (format-blocks (parse-text "![Example](http://example.com 'Click Me!')"))   "<p><img src=\"http://example.com\" alt=\"Example\" title=\"Click Me!\" /></p>")))
 
 (deftest parse-urls1
   (let [[http-text  http-result]  ["<http://stuff>"  "<p><a href=\"http://stuff\">http://stuff</a></p>"]]