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-heading s/Num
|
||||||
:indent-list 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
|
(s/defn
|
||||||
parse-include-md :- [IncludeLink]
|
parse-include-md :- [IncludeLink]
|
||||||
[md-src :- s/Str]
|
[md-src :- s/Str]
|
||||||
(vec
|
(vec
|
||||||
(map
|
(map
|
||||||
(fn [parse-element]
|
(fn [parse-element]
|
||||||
{:uri (nth parse-element 5)
|
(let [uri (nth parse-element 2)
|
||||||
:indent-heading 0
|
indents-text (nth parse-element 1)]
|
||||||
:indent-list 0})
|
{:uri uri
|
||||||
(re-seq #"&\[(:indent-heading (d*))?w*(:indent-list (d*))?\]\((.*)\)" md-src))))
|
: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
|
(def include-heading-list-0
|
||||||
"# Heading1
|
"# 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
|
(def include-invalid-indent
|
||||||
"# Heading1
|
"# Heading1
|
||||||
|
|
@ -31,7 +31,7 @@ Some surounding &[](./simple.md) text")
|
||||||
|
|
||||||
(def include-spaced-indent
|
(def include-spaced-indent
|
||||||
"# Heading1
|
"# 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
|
(deftest test-parse-include-md
|
||||||
|
|
@ -44,9 +44,29 @@ Some surounding &[](./simple.md) text")
|
||||||
(sut/parse-include-md
|
(sut/parse-include-md
|
||||||
include-simple)))
|
include-simple)))
|
||||||
(is
|
(is
|
||||||
(= [{:uri "./simple.md", :indent-heading 1, :indent-list 1}]
|
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||||
(sut/parse-include-md
|
(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
|
(s/defmethod resolver/do-resolve-md :test-mock
|
||||||
[resolver
|
[resolver
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue