~technomancy/fennel-lang.org

57b6ad8c94f9c67b1b6a6ea4ff0f1027584d71a0 — Phil Hagelberg 6 months ago 944c9ad
Improve unescape in html.fnl.

Previously you could just fake it out with a string, but now you need
a proper unescape function which can't be faked.
M Makefile => Makefile +2 -2
@@ 20,7 20,7 @@ PANDOC ?= pandoc --syntax-definition fennel-syntax.xml -f gfm \
fennel/fennel: ; make -C fennel fennel
fennel/fennel.lua: ; make -C fennel fennel.lua

index.html: main.fnl sample.html fennel/fennel
index.html: main.fnl html.fnl sample.html fennel/fennel
	fennel/fennel main.fnl $(TAGDIRS) > index.html

events.html: events.fnl fennel/fennel


@@ 34,7 34,7 @@ fennelview.lua: fennel/fennel fennel/src/fennel/view.fnl
# would be better to use a submodule for this too, but it changes much less
# antifennel.lua: ../antifennel/antifennel ; cp $< $@

fennel-syntax.xml: syntax.fnl fennel/fennel.lua
fennel-syntax.xml: syntax.fnl fennel/fennel
	fennel/fennel $< > $@

coc.html: fennel/CODE-OF-CONDUCT.md; $(PANDOC) -o $@ $<

M conf/2018.fnl => conf/2018.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))
(local foot (require :conf.foot))


M conf/2019.fnl => conf/2019.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))
(local foot (require :conf.foot))


M conf/2020.fnl => conf/2020.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))
(local foot (require :conf.foot))


M conf/2021.fnl => conf/2021.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))
(local foot (require :conf.foot))


M conf/2022.fnl => conf/2022.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))
(local foot (require :conf.foot))


M conf/thanks.fnl => conf/thanks.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local style (require :conf.style))

(print (html [:html {:lang "en"}

M events.fnl => events.fnl +1 -1
@@ 1,6 1,6 @@
;; static HTML generator for the events page

(local html (require "html"))
(local {: html} (require :html))

(print "<!DOCTYPE html>")
(print (html [:html {:lang "en"}

M html.fnl => html.fnl +7 -3
@@ 40,15 40,19 @@
                                     (.. k "=\"" v"\""))) " ")]
    (.. "<" tag-name " " attr-str">")))

(fn html [document allow-no-escape?]
(fn unescaped [element] [unescaped element])

(fn html [document allow-unescaped?]
  (if (= (type document) :string)
      (escape document)
      (and allow-no-escape? (= (. document 1) :NO-ESCAPE))
      (and allow-unescaped? (= (. document 1) unescaped))
      (. document 2)
      (let [[tag-name attrs & body] document]
        (if (void-tag? tag-name)
            (tag tag-name attrs)
            (.. (tag tag-name attrs)
                (table.concat (icollect [_ element (ipairs body)]
                                (html element allow-no-escape?)) " ")
                                (html element allow-unescaped?)) " ")
                "</" tag-name ">")))))

{: html : unescaped}

M main.fnl => main.fnl +5 -5
@@ 1,5 1,5 @@
;; static HTML generator for the page
(local html (require "html"))
(local {: html : unescaped} (require :html))

(print "<!DOCTYPE html>")
(print (html [:html {:lang "en"}


@@ 51,10 51,10 @@
               ;; TODO: add multiple selection of snippets like python.org
               ;; maybe we can show lua output for each; see "modal" on
               ;; http://youmightnotneedjs.com/
               [:NO-ESCAPE (let [f (io.open "sample.html" "r")
                                 sample (: f :read "*all")]
                             (: f :close)
                             sample)]
               (unescaped (let [f (io.open "sample.html" "r")
                                sample (: f :read "*all")]
                            (: f :close)
                            sample))

               [:p {} "See the "
                [:a {:href (.. "https://fennel-lang.org/setup#downloading-fennel")}

M survey/summary.fnl => survey/summary.fnl +1 -1
@@ 1,7 1,7 @@
;; this file spits out the HTML file summarizing the results using a
;; combination of SVG bar graphs and commentary text. it reads the results
;; written by the save.fnl file in raw HTTP form encoded format.
(local html (require :html))
(local {: html} (require :html))
(local foot (require :foot))
(local chart (require :chart))


M survey/survey.fnl => survey/survey.fnl +1 -1
@@ 1,4 1,4 @@
(local html (require :html))
(local {: html} (require :html))
(local foot (require :foot))
(local questions (require :questions))
(local year 2022)