Function: org-element-item-parser

org-element-item-parser is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element-item-parser LIMIT STRUCT &optional RAW-SECONDARY-P)

Documentation

Parse an item up to LIMIT.

STRUCT is the structure of the plain list.

Return a new syntax node of item type containing :bullet,
:begin, :end, :contents-begin, :contents-end, :checkbox,
:counter, :tag, :structure, :pre-blank, :post-blank and
:post-affiliated properties.

When optional argument RAW-SECONDARY-P is non-nil, item's tag, if any, will not be parsed as a secondary string, but as a plain string instead.

Assume point is at the beginning of the item.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
;;;; Item

(defun org-element-item-parser (limit struct &optional raw-secondary-p)
  "Parse an item up to LIMIT.

STRUCT is the structure of the plain list.

Return a new syntax node of `item' type containing `:bullet',
`:begin', `:end', `:contents-begin', `:contents-end', `:checkbox',
`:counter', `:tag', `:structure', `:pre-blank', `:post-blank' and
`:post-affiliated' properties.

When optional argument RAW-SECONDARY-P is non-nil, item's tag, if
any, will not be parsed as a secondary string, but as a plain
string instead.

Assume point is at the beginning of the item."
  (save-excursion
    (forward-line 0)
    (looking-at org-list-full-item-re)
    (let* ((begin (point))
	   (bullet (org-element--get-cached-string (match-string-no-properties 1)))
           (tag-begin (match-beginning 4))
           (tag-end (match-end 4))
	   (checkbox (let ((box (match-string 3)))
		       (cond ((equal "[ ]" box) 'off)
			     ((equal "[X]" box) 'on)
			     ((equal "[-]" box) 'trans))))
	   (end (progn (goto-char (nth 6 (assq (point) struct)))
		       (min limit
                            (if (bolp) (point) (line-beginning-position 2)))))
	   (pre-blank 0)
	   (contents-begin
	    (progn
	      (goto-char
	       ;; Ignore tags in un-ordered lists: they are just
	       ;; a part of item's body.
	       (if (and (match-beginning 4)
			(string-match-p "[.)]" bullet))
		   (match-beginning 4)
		 (match-end 0)))
	      (skip-chars-forward " \r\t\n" end)
	      (cond ((= (point) end) nil)
		    ;; If first line isn't empty, contents really
		    ;; start at the text after item's meta-data.
		    ((= (line-beginning-position) begin) (point))
		    (t
		     (setq pre-blank
			   (count-lines (line-beginning-position) begin))
		     (line-beginning-position)))))
	   (contents-end (and contents-begin
			      (progn (goto-char end)
				     (skip-chars-backward " \r\t\n")
				     (line-beginning-position 2))))
           (counter (let ((c (match-string 2)))
		      (cond
		       ((not c) nil)
		       ((string-match "[A-Za-z]" c)
			(- (string-to-char (upcase (match-string-no-properties 0 c)))
			   64))
		       ((string-match "[0-9]+" c)
			(string-to-number (match-string-no-properties 0 c))))))
	   (item
	    (org-element-create
             'item
	     (list :bullet bullet
		   :begin begin
		   :end end
		   :contents-begin contents-begin
		   :contents-end contents-end
		   :checkbox checkbox
		   :counter counter
		   :structure struct
		   :pre-blank pre-blank
		   :post-blank (count-lines (or contents-end begin) end)
		   :post-affiliated begin
                   :secondary (alist-get
                               'item
                               org-element-secondary-value-alist)))))
      (org-element-put-property
       item :tag
       (let ((raw (org-list-get-tag begin struct)))
	 (when raw
	   (if raw-secondary-p raw
	     (org-element--parse-objects
	      tag-begin tag-end nil
	      (org-element-restriction 'item)
	      item))))))))