mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
include link parsing now works
This commit is contained in:
parent
6918ba27e8
commit
4025b1e29c
2 changed files with 52 additions and 8 deletions
|
|
@ -30,13 +30,37 @@
|
|||
:indent-heading s/Num
|
||||
:indent-list s/Num})
|
||||
|
||||
(s/defn
|
||||
convert-indent-to-int :- s/Num
|
||||
[indents :- [s/Str]]
|
||||
(if (some? indents)
|
||||
(Integer/valueOf (nth indents 2))
|
||||
0))
|
||||
|
||||
(s/defn
|
||||
parse-indent-list
|
||||
[md-src :- s/Str]
|
||||
(re-matches #".*(:indent-list (\d)).*" md-src))
|
||||
|
||||
(s/defn
|
||||
parse-indent-heading
|
||||
[md-src :- s/Str]
|
||||
(re-matches #".*(:indent-heading (\d)).*" md-src))
|
||||
|
||||
(s/defn
|
||||
parse-include-link
|
||||
[md-src :- s/Str]
|
||||
(re-seq #".*&\[\w*(.*)\w*\]\((.*)\).*" md-src))
|
||||
|
||||
(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))))
|
||||
(let [uri (nth parse-element 2)
|
||||
indents-text (nth parse-element 1)]
|
||||
{:uri uri
|
||||
:indent-heading (convert-indent-to-int (parse-indent-heading indents-text))
|
||||
:indent-list (convert-indent-to-int (parse-indent-list indents-text))}))
|
||||
(parse-include-link md-src))))
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ Some surounding &[](./simple.md) text")
|
|||
|
||||
(def include-heading-list-0
|
||||
"# Heading1
|
||||
&[:indent-heading 0 :indent-list 0](./with-heading-and-list.md)")
|
||||
&[:indent-list 0 :indent-heading 0](./with-heading-and-list.md)")
|
||||
|
||||
(def include-invalid-indent
|
||||
"# Heading1
|
||||
|
|
@ -31,7 +31,7 @@ Some surounding &[](./simple.md) text")
|
|||
|
||||
(def include-spaced-indent
|
||||
"# Heading1
|
||||
&[ :indent-heading 0 :indent-list 0 ](./with-heading-and-list.md)")
|
||||
&[ :indent-heading 2 :indent-list 33 ](./with-heading-and-list.md)")
|
||||
|
||||
|
||||
(deftest test-parse-include-md
|
||||
|
|
@ -44,9 +44,29 @@ Some surounding &[](./simple.md) text")
|
|||
(sut/parse-include-md
|
||||
include-simple)))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 1, :indent-list 1}]
|
||||
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-heading-list-1)))))
|
||||
include-surounding-simple)))
|
||||
(is
|
||||
(= [{:uri "./with-heading.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-heading-0)))
|
||||
(is
|
||||
(= [{:uri "./with-heading-and-list.md", :indent-heading 1, :indent-list 1}]
|
||||
(sut/parse-include-md
|
||||
include-heading-list-1)))
|
||||
(is
|
||||
(= [{:uri "./with-heading-and-list.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-heading-list-0)))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-invalid-indent)))
|
||||
(is
|
||||
(= [{:uri "./with-heading-and-list.md", :indent-heading 2, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-spaced-indent)))))
|
||||
|
||||
(s/defmethod resolver/do-resolve-md :test-mock
|
||||
[resolver
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue