In HN, there's no syntax-supported way to quote someone. You can put two spaces in front of a quote, but that doesn't line-wrap. You can put ">" in front, but that isn't as obvious at a glance as one would like. I've created a patch which adds quote support from the markdown spec; if you put > at the beginning of a line, it'll wrap <blockquote> tags around all text until there's a blank line. The necessary functions are in app.arc . 'markdown needs to be changed. I've annotated the diffs: (def markdown (s (o maxurl) (o nolinks))
(let ital nil
(tostring
(forlen i s
(iflet (newi spaces) (indented-code s i (if (is i 0) 2 0))
(do (pr "<p><pre><code>")
(let cb (code-block s (- newi spaces 1))
(pr cb)
(= i (+ (- newi spaces 1) (len cb))))
(pr "</code></pre>"))
(if (quote-begins-at s i) ;;quote code begins here
(let end (quote-end s i)
(pr "<blockquote>"
(get-quote s (+ i 1))
"</blockquote>")
(= i (+ 1 (or end len.s)))) ;;quote code ends here
(iflet newi (parabreak s i (if (is i 0) 1 0))
(do (unless (is i 0) (pr "<p>"))
(= i (- newi 1)))
(and (is (s i) #\*)
(or ital
(atend i s)
(and (~whitec (s (+ i 1)))
(pos #\* s (+ i 1)))))
(do (pr (if ital "</i>" "<i>"))
(= ital (no ital)))
(and (no nolinks)
(or (litmatch "http://" s i)
(litmatch "https://" s i)))
(withs (n (urlend s i)
url (clean-url (cut s i n)))
(tag (a href url rel 'nofollow)
(pr (if (no maxurl)
url
(ellipsize url maxurl))))
(= i (- n 1)))
(writec (s i)))))))))
And three functions need to be added: (def quote-begins-at (str i)
"true if a quote begins at str.i"
(and (or (is i 0)
(is (str (- i 1)) #\newline))
(begins str ">" i)))
(def quote-end (str i)
"Returns the end of a quote beginning at i"
(posmatch "\n\n" str i))
(def get-quote (str i)
"Returns the substring beginning at i and ending the next time there are two #\newline s in a row; failing that, the end of the string"
(cut str (+ i 4) ;;get past > which is the beginning of the quote
(quote-end str i)))
It doesn't support nested quotes, or any markdown syntax inside the quote.I'll license this code under the same license as Arc (Perl Artistic 2.0), in case anyone actually wants to use it. Please let me know if you do. |