mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
improve the HTML creation in article-area
This commit is contained in:
parent
a1e3ae43a5
commit
72c56299ac
@ -251,28 +251,28 @@
|
||||
|
||||
(describe "Format article"
|
||||
(it "should escape HTML entities"
|
||||
(should= "<b>text</b>" (reformat-article "<b>text</b>")))
|
||||
(should= "<b>text</b>" (reformat-article-into-html "<b>text</b>")))
|
||||
|
||||
(it "should linkify url"
|
||||
(should= "<a href=\"https://nostr.com\">nostr.com</a>" (reformat-article "https://nostr.com")))
|
||||
(should= "<a href=\"https://nostr.com\">nostr.com</a>" (reformat-article-into-html "https://nostr.com")))
|
||||
|
||||
(it "should ms-link a namereference"
|
||||
(should= "<a href=\"ms-namereference://@name\">@name</a>"
|
||||
(reformat-article "@name")))
|
||||
(reformat-article-into-html "@name")))
|
||||
|
||||
(it "should ms-link an idreference"
|
||||
(should= "<a href=\"ms-idreference://@0000000000000000000000000000000000000000000000000000000000000000\">@0000000000000000000000000000000000000000000000000000000000000000</a>"
|
||||
(reformat-article "@0000000000000000000000000000000000000000000000000000000000000000")))
|
||||
(should= "<a href=\"ms-idreference://@0000000000000000000000000000000000000000000000000000000000000000\">@0000000000000000000000000000000000000000000000000000000000000000</a>"
|
||||
(reformat-article-into-html "@0000000000000000000000000000000000000000000000000000000000000000")))
|
||||
|
||||
(it "should escape HTML entities and linkify url"
|
||||
(should= "<b>Clojure</b>: <a href=\"https://clojure.org/\">clojure.org/</a>"
|
||||
(reformat-article "<b>Clojure</b>: https://clojure.org/")))
|
||||
(reformat-article-into-html "<b>Clojure</b>: https://clojure.org/")))
|
||||
|
||||
(it "should format replies and escape HTML entities properly"
|
||||
(should= ">this is<br>>a reply" (reformat-article ">this is >a reply")))
|
||||
(should= ">this is<br>>a reply" (reformat-article-into-html ">this is >a reply")))
|
||||
|
||||
(it "should replace multiple spaces with  "
|
||||
(should= "one two  three   ." (reformat-article "one two three .")))
|
||||
(should= "one two  three   ." (reformat-article-into-html "one two three .")))
|
||||
|
||||
|
||||
)
|
||||
|
@ -215,7 +215,7 @@
|
||||
:else
|
||||
(concat segments (list [:text content]))))))))
|
||||
|
||||
(defn reformat-article [article]
|
||||
(defn reformat-article-into-html [article]
|
||||
(let [segments (segment-article article)]
|
||||
(reduce
|
||||
(fn [formatted-content [seg-type seg]]
|
||||
|
@ -183,6 +183,16 @@
|
||||
name (formatters/format-user-id id 50)]
|
||||
(recur (rest reactions) (conj items (str content " " name)))))))
|
||||
|
||||
(defn make-html-document [style body]
|
||||
(str "<head>" style "</head>"
|
||||
"<body>" body "</body>"))
|
||||
|
||||
(defn make-article-html [event]
|
||||
(make-html-document
|
||||
editor-pane-stylesheet
|
||||
(formatters/reformat-article-into-html
|
||||
(formatters/replace-references event))))
|
||||
|
||||
(defn load-article-info [selected-id]
|
||||
(let [main-frame (get-mem :frame)
|
||||
event (gateway/get-event (get-db) selected-id)
|
||||
@ -215,8 +225,7 @@
|
||||
(swing-util/clear-popup reactions-popup)
|
||||
(config! relays-popup :items relay-names)
|
||||
(config! reactions-popup :items (reaction-items (:reactions event)))
|
||||
(text! article-area (formatters/reformat-article
|
||||
(formatters/replace-references event)))
|
||||
(text! article-area (make-article-html event))
|
||||
(text! author-name-label
|
||||
(formatters/format-user-id (:pubkey event) 50))
|
||||
(config! author-name-label :user-data (:pubkey event))
|
||||
|
Loading…
Reference in New Issue
Block a user