Skip to content

Add Plump back-end. #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions plump/cl-html5-parser-plump.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;;;; HTML5 parser for Common Lisp
;;;;
;;;; Copyright (C) 2025 Artyom Bologov <mail@aartaka.me>
;;;;
;;;; 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 <http://www.gnu.org/licenses/>.

(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 <mail@aartaka.me>"
:depends-on ("cl-html5-parser" "plump")
:serial t
:components ((:file "plump-dom")))
48 changes: 48 additions & 0 deletions plump/plump-dom.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
;;;; HTML5 parser for Common Lisp
;;;;
;;;; Copyright (C) 2025 Artyom Bologov <mail@aartaka.me>
;;;;
;;;; 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 <http://www.gnu.org/licenses/>.

(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)))))