mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
implemented simple parsing
This commit is contained in:
parent
9607657cc1
commit
6918ba27e8
3 changed files with 64 additions and 5 deletions
|
|
@ -4,7 +4,8 @@ The user can include page title, abstract or the whole content in a given page.
|
|||
|
||||
## Thoughts & Questions
|
||||
* Which include syntax should be used?
|
||||
* page include can be definde alongsite of image includes - sth. like `#[indent-level](relative or absolute url)`
|
||||
* page include can be definde alongsite of image includes - sth. like
|
||||
`&[:indent-heading s/Num :indent-list s/Num](relative or absolute url s/Str)`
|
||||
* Which kind of urls should we accept for page includes?
|
||||
* relative local urls (we will need some care to prohibit directory traversal ...)
|
||||
* absolute github / gitlab / gitblit urls without authentication.
|
||||
|
|
|
|||
|
|
@ -24,3 +24,19 @@
|
|||
new-includer
|
||||
[]
|
||||
(map->Includer {}))
|
||||
|
||||
(def IncludeLink
|
||||
{:uri s/Str
|
||||
:indent-heading s/Num
|
||||
:indent-list s/Num})
|
||||
|
||||
(s/defn
|
||||
parse-include-md :- [IncludeLink]
|
||||
[md-src :- s/Str]
|
||||
(vec
|
||||
(map
|
||||
(fn [parse-element]
|
||||
{:uri (nth parse-element 5)
|
||||
:indent-heading 0
|
||||
:indent-list 0})
|
||||
(re-seq #"&\[(:indent-heading (d*))?w*(:indent-list (d*))?\]\((.*)\)" md-src))))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,49 @@
|
|||
[smeagol.include.resolver :as resolver]
|
||||
[smeagol.include :as sut]))
|
||||
|
||||
(def include-simple
|
||||
"# Heading1
|
||||
&[](./simple.md)")
|
||||
|
||||
(def include-surounding-simple
|
||||
"# Heading1
|
||||
Some surounding &[](./simple.md) text")
|
||||
|
||||
(def include-heading-0
|
||||
"# Heading1
|
||||
&[:indent-heading 0](./with-heading.md)")
|
||||
|
||||
(def include-heading-list-1
|
||||
"# Heading1
|
||||
&[:indent-heading 1 :indent-list 1](./with-heading-and-list.md)")
|
||||
|
||||
(def include-heading-list-0
|
||||
"# Heading1
|
||||
&[:indent-heading 0 :indent-list 0](./with-heading-and-list.md)")
|
||||
|
||||
(def include-invalid-indent
|
||||
"# Heading1
|
||||
&[ invalid input should default to indent 0 ](./simple.md)")
|
||||
|
||||
(def include-spaced-indent
|
||||
"# Heading1
|
||||
&[ :indent-heading 0 :indent-list 0 ](./with-heading-and-list.md)")
|
||||
|
||||
|
||||
(deftest test-parse-include-md
|
||||
(testing "parse include links"
|
||||
(is
|
||||
(= []
|
||||
(sut/parse-include-md "# Heading")))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-simple)))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 1, :indent-list 1}]
|
||||
(sut/parse-include-md
|
||||
include-heading-list-1)))))
|
||||
|
||||
(s/defmethod resolver/do-resolve-md :test-mock
|
||||
[resolver
|
||||
uri :- s/Str]
|
||||
|
|
@ -19,14 +62,13 @@
|
|||
{:resolver :resolver})))
|
||||
|
||||
(deftest test-expand-include-md
|
||||
(testing "Rewriting of local links"
|
||||
(testing "The whole integration of include"
|
||||
(is
|
||||
(= "# Heading"
|
||||
(sut/expand-include-md (:includer system-under-test) "# Heading")))
|
||||
(is
|
||||
(= "# Heading 1
|
||||
Simple content."
|
||||
Simple content."
|
||||
(sut/expand-include-md
|
||||
(:includer system-under-test)
|
||||
"# Heading1
|
||||
#[](.simple.md)")))))
|
||||
include-simple)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue