-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0649ecf
commit 03c63da
Showing
6 changed files
with
127 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns ^{:doc "Format Semagol's local links." | ||
:author "Simon Brooke"} | ||
smeagol.local-links | ||
(:require [clojure.data.json :as json] | ||
[clojure.string :as cs] | ||
[cemerick.url :refer (url url-encode url-decode)])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;;;; | ||
;;;; Smeagol: a very simple Wiki engine. | ||
;;;; | ||
;;;; This program is free software; you can redistribute it and/or | ||
;;;; modify it under the terms of the GNU General Public License | ||
;;;; as published by the Free Software Foundation; either version 2 | ||
;;;; of the License, or (at your option) any later version. | ||
;;;; | ||
;;;; This program is distributed in the hope that it will be useful, | ||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;;;; GNU General Public License for more details. | ||
;;;; | ||
;;;; You should have received a copy of the GNU General Public License | ||
;;;; along with this program; if not, write to the Free Software | ||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
;;;; USA. | ||
;;;; | ||
;;;; Copyright (C) 2017 Simon Brooke | ||
;;;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
;; Error to show if text to be rendered is nil. | ||
;; TODO: this should go through i18n | ||
(def no-text-error "No text: does the file exist?") | ||
|
||
|
||
(defn local-links | ||
"Rewrite text in `html-src` surrounded by double square brackets as a local link into this wiki." | ||
[^String html-src] | ||
(if html-src | ||
(cs/replace html-src #"\[\[[^\[\]]*\]\]" | ||
#(let [text (cs/replace %1 #"[\[\]]" "") | ||
encoded (url-encode text) | ||
;; I use '\_' to represent '_' in wiki markup, because | ||
;; '_' is meaningful in Markdown. However, this needs to | ||
;; be stripped out when interpreting local links. | ||
munged (cs/replace encoded #"%26%2395%3B" "_")] | ||
(format "<a href='wiki?page=%s'>%s</a>" munged text))) | ||
no-text-error)) | ||
|
||
|
Oops, something went wrong.