Browse Source

added ast preview option in parser, multi-line blockquote support

main
root 2 months ago
parent
commit
27fb24c886
  1. 20
      blog.janet

20
blog.janet

@ -45,7 +45,9 @@
(default alt link)
[:link link alt]))
:list-item (* "* " (cmt (<- :paragraph) ,string/trim))
:quote (cmt (* ">" (<- :paragraph)) ,|[:quote (string/trim $0)])
:quote (+
(cmt (* ">" (<- :paragraph)) ,|[:quote (string/trim $0)])
(cmt ">" ,|[:quote ""]))
## Custom HTML-mapped syntax
:hr (cmt "---" ,|[:hr])
@ -61,10 +63,15 @@
:list-item
(any (* "\n" :list-item)))
,|[:list $&])
:multiline-quote (cmt
(*
:quote
(any (* "\n" :quote)))
,|[:multiline-quote $&])
:block (+ :link
:blockquote
:heading
:quote
:multiline-quote
:list
:hr
:empty-lines
@ -92,7 +99,6 @@
(string/join [;base (if (= ext "gmi") "html" ext)] ".")
link))
# TODO: Add a toggle to disable empty divs and other features
(defn to-html
"Transforms the Gemini AST (as provided by (peg/match gemini-syntax)) into HTML"
[ast &opt sep]
@ -108,8 +114,10 @@
[:heading value slug level]
(string "<h" level " id='" slug
"'><a href='#" slug "' class='heading'>::</a> " (htmlspecialchars value) "</h" level ">")
[:quote value]
(string "<blockquote>" (htmlspecialchars value) "</blockquote>")
[:multiline-quote value]
(string "<blockquote>\n"
(string/join (map |(string "<p>" (htmlspecialchars (get $0 1)) "</p>") value) "\n")
"\n</blockquote>")
[:empty]
"<div class='empty'></div>"
[:hr]
@ -231,6 +239,7 @@
(let [value (slurp path)
ast (peg/match gemini-syntax value)]
(cond
(= mode :ast) (pp-ast ast)
(= mode :html) (print (to-html ast))
(= mode :meta) (dump-bash-eval (extract-meta ast))
(= mode :gmi) (print (to-gmi ast))
@ -248,6 +257,7 @@
(defn main [bin & args]
(match args
["--ast" file] (parse-doc :ast file)
["--html" file] (parse-doc :html file)
["--meta" file] (parse-doc :meta file)
["--rss" file] (parse-doc :rss file)

Loading…
Cancel
Save