mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
add the replacement parameter
This commit is contained in:
parent
6714dc04bf
commit
78a534349b
2 changed files with 27 additions and 14 deletions
|
|
@ -3,7 +3,8 @@
|
|||
[schema.core :as s]))
|
||||
|
||||
(def IncludeLink
|
||||
{:uri s/Str
|
||||
{:replace s/Str
|
||||
:uri s/Str
|
||||
:indent-heading s/Num
|
||||
:indent-list s/Num})
|
||||
|
||||
|
|
@ -27,7 +28,7 @@
|
|||
(s/defn
|
||||
parse-include-link
|
||||
[md-src :- s/Str]
|
||||
(re-seq #".*&\[\w*(.*)\w*\]\((.*)\).*" md-src))
|
||||
(re-seq #".*(&\[\w*(.*)\w*\]\((.*)\)).*" md-src))
|
||||
|
||||
(s/defn
|
||||
parse-include-md :- [IncludeLink]
|
||||
|
|
@ -35,9 +36,11 @@
|
|||
(vec
|
||||
(map
|
||||
(fn [parse-element]
|
||||
(let [uri (nth parse-element 2)
|
||||
indents-text (nth parse-element 1)]
|
||||
{:uri uri
|
||||
(let [replace (nth parse-element 1)
|
||||
uri (nth parse-element 3)
|
||||
indents-text (nth parse-element 2)]
|
||||
{:replace replace
|
||||
: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))))
|
||||
|
|
|
|||
|
|
@ -45,37 +45,47 @@ more text.")
|
|||
(= []
|
||||
(sut/parse-include-md "# Heading")))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(= [{:replace "&[](./simple.md)" :uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-simple)))
|
||||
(is
|
||||
(= [{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(= [{:replace "&[](./simple.md)" :uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
include-surounding-simple)))
|
||||
(is
|
||||
(= [{:uri "./with-heading.md", :indent-heading 0, :indent-list 0}]
|
||||
(= [{:replace "&[:indent-heading 0](./with-heading.md)" :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}]
|
||||
(= [{:replace
|
||||
"&[:indent-heading 1 :indent-list 1](./with-heading-and-list.md)"
|
||||
: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}]
|
||||
(= [{:replace
|
||||
"&[:indent-list 0 :indent-heading 0](./with-heading-and-list.md)"
|
||||
: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}]
|
||||
(= [{:replace
|
||||
"&[ invalid input should default to indent 0 ](./simple.md)"
|
||||
: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 3}]
|
||||
(= [{:replace
|
||||
"&[ :indent-heading 2 :indent-list 33 ](./with-heading-and-list.md)"
|
||||
:uri "./with-heading-and-list.md", :indent-heading 2, :indent-list 3}]
|
||||
(sut/parse-include-md
|
||||
include-spaced-indent)))
|
||||
(is
|
||||
(= [{:uri "./with-heading-and-list.md",
|
||||
(= [{:replace
|
||||
"&[ :indent-heading 2 :indent-list 33 ](./with-heading-and-list.md)"
|
||||
:uri "./with-heading-and-list.md",
|
||||
:indent-heading 2,
|
||||
:indent-list 3}
|
||||
{:uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
{:replace "&[](./simple.md)" :uri "./simple.md", :indent-heading 0, :indent-list 0}]
|
||||
(sut/parse-include-md
|
||||
multi)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue