Verified Commit f356069e authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Improved PARSE-CLIKI-MARKUP, implemented \) escapes in internal links

parent a280953b
* figure out how () in page names should work with _()
https://github.com/archimag/cliki2/issues/24
* grab title for index page from wiki object
https://github.com/archimag/cliki2/issues/18
* edit summary maxlength should be 128
......
......@@ -92,7 +92,7 @@
(ppcre:regex-replace-all
"\\n\\n"
(sanitize:clean
(cl-ppcre:regex-replace-all
(ppcre:regex-replace-all
"< "
(parse-cliki-markup
(escape-parens-in-href-links markup start end))
......@@ -123,24 +123,28 @@
:simple-calls t :start start :end end))
(defun parse-cliki-markup (markup)
(loop for prefix in '("_" "_H" "\\*" "\\/" "_P")
for formatter in '(pprint-article-underscore-link format-hyperspec-link pprint-topic-link format-topic-list format-package-link)
do (setf markup (process-cliki-rule markup prefix formatter)))
markup)
(ppcre:regex-replace-all
"(_|\\*|/|_H|_P)\\(((?:\\\\\\)|[^\\)])*)\\)"
markup
(lambda (match prefix title)
(declare (ignore match))
(with-output-to-string (*html-stream*)
(funcall (cdr
(assoc prefix
'(("_" . pprint-article-underscore-link)
("*" . pprint-topic-link)
("/" . format-topic-list)
("_H" . format-hyperspec-link)
("_P" . format-package-link))
:test #'string=))
(ppcre:regex-replace-all "\\\\\\)" title ")"))))
:simple-calls t))
(defun pprint-article-underscore-link (title)
(destructuring-bind (real-title &optional link-title)
(cl-ppcre:split "\\|" title)
(%print-article-link real-title "internal" (or link-title real-title))))
(defun process-cliki-rule (markup prefix formatter)
(ppcre:regex-replace-all #?/${prefix}\((.*?)\)/
markup
(lambda (match r1)
(declare (ignore match))
(with-output-to-string (*html-stream*)
(funcall formatter r1)))
:simple-calls t))
(destructuring-bind (&optional (real-title "") link-title)
(ppcre:split "\\|" title)
(%print-article-link real-title "internal"
(or link-title real-title))))
(defun article-description (article-title)
(let ((c (cached-content article-title)))
......
......@@ -45,6 +45,24 @@
"<a href=\"/Something%20else\" class=\"new\">Shortname</a>"
(cliki2::parse-cliki-markup "_(Something else|Shortname)"))))
(test parse-empty-internal-link ()
(is
(string=
"<a href=\"/\" class=\"new\"></a>"
(cliki2::parse-cliki-markup "_()"))))
(test parse-empty-internal-link1 ()
(is
(string=
"<a href=\"/\" class=\"new\"></a>"
(cliki2::parse-cliki-markup "_(|)"))))
(test parse-empty-internal-link2 ()
(is
(string=
"<a href=\"/\" class=\"new\">x</a>"
(cliki2::parse-cliki-markup "_(|x)"))))
(test parse-hyperspec-link ()
(is
(string=
......@@ -68,3 +86,81 @@
(string=
"*(baz) <a href=\"foo %28bar%29\">foo (bar)</a> _(not bar)"
(cliki2::escape-parens-in-href-links "*(baz) <a href=\"foo (bar)\">foo (bar)</a> _(not bar)" 0 51))))
(test parse-article-link-with-escaped-parentheses ()
(is
(string=
"<a href=\"/Foo%20%28bar%29\" class=\"new\">Foo (bar)</a>"
(cliki2::parse-cliki-markup "_(Foo (bar\\))"))))
(test parse-article-link-with-escaped-parentheses1 ()
(is
(string=
"<a href=\"/Foo%20%28bar%29%20baz\" class=\"new\">Foo (bar) baz</a>"
(cliki2::parse-cliki-markup "_(Foo (bar\\) baz)"))))
(test parse-empty-article ()
(is
(string=
""
(cliki2::parse-cliki-markup ""))))
(test parse-short-article ()
(is
(string=
"a"
(cliki2::parse-cliki-markup "a"))))
(test parse-short-article1 ()
(is
(string=
"ab"
(cliki2::parse-cliki-markup "ab"))))
(test parse-short-article2 ()
(is
(string=
"abc"
(cliki2::parse-cliki-markup "abc"))))
(test parse-short-article3 ()
(is
(string=
"("
(cliki2::parse-cliki-markup "("))))
(test parse-short-article4 ()
(is
(string=
"_("
(cliki2::parse-cliki-markup "_("))))
(test parse-short-article5 ()
(is
(string=
")"
(cliki2::parse-cliki-markup ")"))))
(test parse-short-article6 ()
(is
(string=
"()"
(cliki2::parse-cliki-markup "()"))))
(test parse-some-article ()
(is
(string=
"something <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> baz"
(cliki2::parse-cliki-markup "something _(Foo bar) baz"))))
(test parse-some-article1 ()
(is
(string=
"(abc <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> xyz)"
(cliki2::parse-cliki-markup "(abc _(Foo bar) xyz)"))))
(test parse-some-article2 ()
(is
(string=
"abc <a href=\"/Foo%20bar\" class=\"new\">Foo bar</a> (xyz"
(cliki2::parse-cliki-markup "abc _(Foo bar) (xyz"))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment