Compare commits
2 commits
682f37e49c
...
38806c4d03
Author | SHA1 | Date | |
---|---|---|---|
38806c4d03 | |||
00db423384 |
|
@ -72,7 +72,10 @@
|
||||||
(table.insert lexed {:type "raw-text"
|
(table.insert lexed {:type "raw-text"
|
||||||
:text (string.sub contents current (length contents))})
|
:text (string.sub contents current (length contents))})
|
||||||
(set current (length contents)))))) ; No decoration at all
|
(set current (length contents)))))) ; No decoration at all
|
||||||
lexed))
|
(if (> (length lexed) 0) ; If lexed is nil, the only case is we had a single \n paragraph?
|
||||||
|
lexed
|
||||||
|
[{:type "raw-text"
|
||||||
|
:text "\n"}])))
|
||||||
; ">" (let [(block new-end) ((. grammar :Spoiler) contents current)]
|
; ">" (let [(block new-end) ((. grammar :Spoiler) contents current)]
|
||||||
; (table.insert lexed block)
|
; (table.insert lexed block)
|
||||||
; (set current new-end))))
|
; (set current new-end))))
|
||||||
|
|
1
main.fnl
1
main.fnl
|
@ -10,4 +10,3 @@
|
||||||
(blocks.lexer blocks.grammar)
|
(blocks.lexer blocks.grammar)
|
||||||
(inline.inline-lexer inline.inline-grammar)
|
(inline.inline-lexer inline.inline-grammar)
|
||||||
(_G.pp))
|
(_G.pp))
|
||||||
; (inline.contents-lexer inline.contents-grammar))
|
|
||||||
|
|
54
render.fnl
Normal file
54
render.fnl
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
(local fennel (require :fennel))
|
||||||
|
(fn _G.pp [x] (print (fennel.view x)))
|
||||||
|
|
||||||
|
(fn render-contents [contents])
|
||||||
|
|
||||||
|
(local renderer
|
||||||
|
{:Header (fn render-header [{: contents : size}]
|
||||||
|
(let [header-type (tostring size)
|
||||||
|
header (.. "h" header-type)
|
||||||
|
contents-render (render-contents contents)]
|
||||||
|
(.. "<" header ">\n" contents-render "</" header ">\n")))
|
||||||
|
:List (fn render-list [{: elements}]
|
||||||
|
(var list-str "<ul>\n")
|
||||||
|
(var depth 1)
|
||||||
|
(each [_ element (ipairs elements)]
|
||||||
|
(let [contents-render (render-contents (. element :contents))
|
||||||
|
indent-level (. element :indent-level)]
|
||||||
|
(if (= indent-level depth) ; If we're at the right indent level
|
||||||
|
(set list-str (.. list-str "<li>" contents-render "</li>\n")) ; Just add the string as a list element
|
||||||
|
(do ; Otherwise
|
||||||
|
(while (not (= depth indent-level)) ; While our depth level is different from the indent level
|
||||||
|
(if (< indent-level depth) ; If we need to increase depth
|
||||||
|
(do
|
||||||
|
(set list-str (.. list-str "<ul>\n")) ; Add another layer in the render
|
||||||
|
(set depth (+ depth 1))) ; Increase our depth level
|
||||||
|
(do ; We need to decrease depth
|
||||||
|
(set list-str (.. list-str "</ul>\n")) ; Close a layer
|
||||||
|
(set depth (- depth 1))))) ; Reduce depth level
|
||||||
|
(set list-str (.. list-str "<li>" contents-render "</li>\n"))))))
|
||||||
|
(while (not (= depth 1))
|
||||||
|
(set list-str (.. list-str "</ul>\n"))
|
||||||
|
(set depth (- depth 1)))
|
||||||
|
list-str)
|
||||||
|
:Quote (fn render-quote [{: contents}]
|
||||||
|
(let [contents-render (render-contents contents)]
|
||||||
|
(.. "<blockquote>\n" contents-render "</blockquote>\n")))
|
||||||
|
:Paragraph (fn render-paragraph [{: contents}]
|
||||||
|
(let [contents-render (render-contents contents)]
|
||||||
|
(.. "<p>\n" contents-render "</p>\n")))
|
||||||
|
:Image (fn render-image [{: link : contents}]
|
||||||
|
(.. "<img\n src=" link "\n alt=" contents " />"))
|
||||||
|
; Tags are a type of metadata
|
||||||
|
; Not really sure how to render metadata
|
||||||
|
; I think it actually shouldn't be rendered, and passed back up as... metadata
|
||||||
|
; The SSG should handle how to render them
|
||||||
|
:Tag (fn metadata-tag [{: tags}]
|
||||||
|
(var metadata {}))
|
||||||
|
:Metadata ""
|
||||||
|
; Not sure what to do about code either
|
||||||
|
; Need to look into pygments or whatever see how that works
|
||||||
|
; Or find some sort of minimal js solution?
|
||||||
|
; Not really sure
|
||||||
|
:Code ""})
|
||||||
|
|
Loading…
Reference in a new issue