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]))
|
[schema.core :as s]))
|
||||||
|
|
||||||
(def IncludeLink
|
(def IncludeLink
|
||||||
{:uri s/Str
|
{:replace s/Str
|
||||||
|
:uri s/Str
|
||||||
:indent-heading s/Num
|
:indent-heading s/Num
|
||||||
:indent-list s/Num})
|
:indent-list s/Num})
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@
|
||||||
(s/defn
|
(s/defn
|
||||||
parse-include-link
|
parse-include-link
|
||||||
[md-src :- s/Str]
|
[md-src :- s/Str]
|
||||||
(re-seq #".*&\[\w*(.*)\w*\]\((.*)\).*" md-src))
|
(re-seq #".*(&\[\w*(.*)\w*\]\((.*)\)).*" md-src))
|
||||||
|
|
||||||
(s/defn
|
(s/defn
|
||||||
parse-include-md :- [IncludeLink]
|
parse-include-md :- [IncludeLink]
|
||||||
|
|
@ -35,9 +36,11 @@
|
||||||
(vec
|
(vec
|
||||||
(map
|
(map
|
||||||
(fn [parse-element]
|
(fn [parse-element]
|
||||||
(let [uri (nth parse-element 2)
|
(let [replace (nth parse-element 1)
|
||||||
indents-text (nth parse-element 1)]
|
uri (nth parse-element 3)
|
||||||
{:uri uri
|
indents-text (nth parse-element 2)]
|
||||||
|
{:replace replace
|
||||||
|
:uri uri
|
||||||
:indent-heading (convert-indent-to-int (parse-indent-heading indents-text))
|
:indent-heading (convert-indent-to-int (parse-indent-heading indents-text))
|
||||||
:indent-list (convert-indent-to-int (parse-indent-list indents-text))}))
|
:indent-list (convert-indent-to-int (parse-indent-list indents-text))}))
|
||||||
(parse-include-link md-src))))
|
(parse-include-link md-src))))
|
||||||
|
|
|
||||||
|
|
@ -45,37 +45,47 @@ more text.")
|
||||||
(= []
|
(= []
|
||||||
(sut/parse-include-md "# Heading")))
|
(sut/parse-include-md "# Heading")))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-simple)))
|
include-simple)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-surounding-simple)))
|
include-surounding-simple)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-heading-0)))
|
include-heading-0)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-heading-list-1)))
|
include-heading-list-1)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-heading-list-0)))
|
include-heading-list-0)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-invalid-indent)))
|
include-invalid-indent)))
|
||||||
(is
|
(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
|
(sut/parse-include-md
|
||||||
include-spaced-indent)))
|
include-spaced-indent)))
|
||||||
(is
|
(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-heading 2,
|
||||||
:indent-list 3}
|
: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
|
(sut/parse-include-md
|
||||||
multi)))))
|
multi)))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue