Mercurial > core / lisp/lib/organ/section.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
609931bd65ba
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; lib/organ/section.lisp --- Org Sections 8 (defclass org-section () 9 ((contents :initform #() :initarg :contents :type (vector org-object) 10 :accessor org-contents))) 12 (defmethod org-create ((type (eql :section)) &rest initargs) 13 (apply #'make-instance (sym-to-org-class-name type) initargs)) 15 (defmethod org-parse ((type (eql :section)) (input string)) 16 (unless (sequence:emptyp input) 17 (org-create :section :contents input))) 19 (defclass org-meta-section (org-section) ((keywords :initform #() :initarg :keywords :type (vector org-keyword)))) 21 (defmethod org-create ((type (eql :meta)) &rest initargs) 22 (apply #'make-instance 'org-meta-section initargs)) 24 (defmethod org-parse ((type (eql :meta)) (input string)) 25 (unless (sequence:emptyp input) 26 (let ((contents (make-array 0 :element-type 'org-element :fill-pointer 0 :adjustable t))) 27 (log:debug! "meta section input:" input) 28 (with-input-from-string (s input) 29 (vector-push-extend (org-parse :keyword (read-line s)) contents)) 30 (org-create :meta :contents contents)))) 32 (defmethod org-parse ((type (eql :meta)) (input stream)) 33 (let ((keywords (make-array 0 :element-type 'org-keyword :adjustable t :fill-pointer 0)) 34 (content (make-array 0 :element-type 'character :fill-pointer 0))) 35 (with-output-to-string (content-stream content) 36 (loop for c = (peek-char nil input nil nil) ; check that this line isn't a headline 37 until (or (not c) (char= #\* c)) 38 do (let ((l (read-line input))) 39 (if-let ((kw (org-parse :keyword l))) 40 (vector-push-extend kw keywords) 41 (write-line l content-stream))))) 42 (org-create :meta :keywords keywords :contents (org-parse :paragraph content))))