From 3d2d277c3c3ad9538fa79b36f8b92305a2d19775 Mon Sep 17 00:00:00 2001 From: Artyom Bologov Date: Tue, 27 May 2025 21:04:30 +0400 Subject: [PATCH] Add Plump back-end. --- plump/cl-html5-parser-plump.asd | 25 +++++++++++++++++ plump/plump-dom.lisp | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 plump/cl-html5-parser-plump.asd create mode 100644 plump/plump-dom.lisp diff --git a/plump/cl-html5-parser-plump.asd b/plump/cl-html5-parser-plump.asd new file mode 100644 index 0000000..04c6287 --- /dev/null +++ b/plump/cl-html5-parser-plump.asd @@ -0,0 +1,25 @@ +;;;; HTML5 parser for Common Lisp +;;;; +;;;; Copyright (C) 2025 Artyom Bologov +;;;; +;;;; This library is free software: you can redistribute it and/or modify +;;;; it under the terms of the GNU Lesser General Public License as published +;;;; by the Free Software Foundation, either version 3 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; This library is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this library. If not, see . + +(defsystem #:cl-html5-parser-plump + :name "cl-html5-parser" + :description "Plump integration for cl-html5-parser" + :licence "GNU Lesser General Public License" + :author "Artyom Bologov " + :depends-on ("cl-html5-parser" "plump") + :serial t + :components ((:file "plump-dom"))) diff --git a/plump/plump-dom.lisp b/plump/plump-dom.lisp new file mode 100644 index 0000000..c714f71 --- /dev/null +++ b/plump/plump-dom.lisp @@ -0,0 +1,48 @@ +;;;; HTML5 parser for Common Lisp +;;;; +;;;; Copyright (C) 2025 Artyom Bologov +;;;; +;;;; This library is free software: you can redistribute it and/or modify +;;;; it under the terms of the GNU Lesser General Public License as published +;;;; by the Free Software Foundation, either version 3 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; This library is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this library. If not, see . + +(in-package #:html5-parser) + + +(defmethod transform-html5-dom ((to-type (eql :plump)) node &key parent &allow-other-keys) + (ecase (node-type node) + (:document-type + (plump:make-doctype parent (node-system-id node))) + ((:document :document-fragment) + (let ((root (plump:make-root))) + (element-map-children + (lambda (child &optional parent xlink-defined) + (declare (ignorable parent xlink-defined)) + (transform-html5-dom to-type child :parent root)) + node) + root)) + (:element + (let ((elem (plump:make-element parent (node-name node)))) + (element-map-attributes + (lambda (name namespace value) + (declare (ignorable namespace)) + (plump:set-attribute elem name value)) + node) + (element-map-children + (lambda (child) + (transform-html5-dom to-type child :parent elem)) + node) + elem)) + (:text + (plump:make-text-node parent (node-value node))) + (:comment + (plump:make-comment parent (node-value node)))))