1
0
Fork 0

Switch to marxdown as default post and comment format

This commit is contained in:
Andy Wingo 2022-10-20 22:37:55 +02:00
parent 1236e8a996
commit 4374fbf1dc
4 changed files with 27 additions and 17 deletions

View file

@ -1,5 +1,5 @@
;; Tekuti
;; Copyright (C) 2008, 2010, 2012 Andy Wingo <wingo at pobox dot com>
;; Copyright (C) 2008, 2010, 2012, 2022 Andy Wingo <wingo at pobox dot com>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@ -56,11 +56,11 @@
(author ,(assq-ref comment 'author))
(email ,(assq-ref comment 'author_email))
(url ,(assq-ref comment 'author_url))
,(let ((format (or (assq-ref comment 'format) 'wordpress))
,(let ((format (or (assq-ref comment 'format) 'marxdown))
(raw (assq-ref comment 'raw-content)))
(or (case format
((wordpress) (false-if-exception (wordpress->sxml raw)))
((marxdown) (false-if-exception (marxdown->sxml raw)))
(else `(pre ,raw)))
`(pre ,raw))))))

View file

@ -1,5 +1,5 @@
;; Tekuti
;; Copyright (C) 2008, 2010, 2012 Andy Wingo <wingo at pobox dot com>
;; Copyright (C) 2008, 2010, 2012, 2022 Andy Wingo <wingo at pobox dot com>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@ -88,9 +88,10 @@
(a (@ (href ,(string-append "#" (assq-ref comment 'key))))
,(comment-readable-date comment)))
,(neutralize-links
(let ((format (or (assq-ref comment 'format) 'wordpress)))
(let ((format (or (assq-ref comment 'format) 'marxdown)))
((case format
((wordpress) wordpress->sxml)
((marxdown) marxdown->sxml)
(else (lambda (text) `(pre ,text))))
(comment-raw-content comment))))))
@ -119,7 +120,7 @@
`(("author" ,(lambda (x) #f))
("email" ,bad-email?)
("url" ,bad-url?)
("comment" ,bad-user-submitted-xhtml?)
("comment" ,bad-user-submitted-marxdown?)
("x" ,bad-number?)
("submit" ,(lambda (x) #f))))

View file

@ -1,5 +1,5 @@
;; Tekuti
;; Copyright (C) 2008, 2010, 2011, 2012 Andy Wingo <wingo at pobox dot com>
;; Copyright (C) 2008, 2010, 2011, 2012, 2022 Andy Wingo <wingo at pobox dot com>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@ -27,10 +27,11 @@
(define-module (tekuti filters)
#:use-module (sxml simple)
#:use-module (sxml transform)
#:use-module (tekuti marxdown)
#:use-module (tekuti match-bind)
#:use-module (tekuti util)
#:export (wordpress->sxml
*allowed-tags* bad-user-submitted-xhtml?))
#:export (wordpress->sxml marxdown->sxml
*allowed-tags* bad-user-submitted-marxdown?))
(define blocks '(table thead tfoot caption colgroup tbody tr td th div
dl dd dt ul ol li pre select form map area blockquote
@ -90,6 +91,9 @@
(*text* . ,(lambda (tag text)
text))))))
(define (marxdown->sxml text)
(smarxdown->shtml (call-with-input-string text marxdown->smarxdown)))
(define *allowed-tags*
`((a (href . ,urlish?) title)
(abbr title)
@ -140,13 +144,18 @@
`((div ,(compile-sxslt-rules *allowed-tags*)
. ,(lambda body body))))
(define (bad-user-submitted-xhtml? x)
(define (bad-user-submitted-marxdown? x)
(catch #t
(lambda ()
(pre-post-order (wordpress->sxml x) *valid-xhtml-rules*)
(pre-post-order (marxdown->sxml x) *valid-xhtml-rules*)
#f)
(lambda (key . args)
`(div (p (b "Invalid XHTML"))
`(div (p (b "Invalid Marxdown"))
(p "The input grammar is essentially Markdown. However "
"there are some differences, notably that e.g. *emph* "
"blocks need to be properly closed and that any "
"embedded HTML needs to be well-formed XHTML.")
(p "Further information:")
,(case key
((parser-error)
`(div
@ -168,6 +177,5 @@
((bad-attr-value)
`(p "XHTML attribute has bad value: " ,(car args)))
(else
(pk key args)
`(p "Jesus knows why, and so do you")))))))
`(p "Hey not real knows why, and so do you")))))))

View file

@ -1,5 +1,5 @@
;; Tekuti
;; Copyright (C) 2008, 2010, 2011, 2012, 2014, 2021 Andy Wingo <wingo at pobox dot com>
;; Copyright (C) 2008, 2010, 2011, 2012, 2014, 2021, 2022 Andy Wingo <wingo at pobox dot com>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@ -133,15 +133,16 @@
(git "show" (string-append (assq-ref post 'sha1) ":content")))
(define (post-sxml-content post)
(let ((format (or (assq-ref post 'format) 'wordpress))
(let ((format (or (assq-ref post 'format) 'marxdown))
(raw (post-raw-content post)))
(catch #t
(lambda ()
(case format
((wordpress) (wordpress->sxml raw))
((marxdown) (marxdown->sxml raw))
(else `(pre ,raw))))
(lambda args
`(pre ,(bad-user-submitted-xhtml? raw))))))
`(pre ,(bad-user-submitted-marxdown? raw))))))
(define (post-readable-date post)
(let ((date (time-utc->date