Function: htmlize-add-before-after-strings

htmlize-add-before-after-strings is a byte-compiled function defined in htmlize.el.

Signature

(htmlize-add-before-after-strings BEG END TEXT)

Source Code

;; Defined in ~/.emacs.d/elpa/htmlize-20250724.1703/htmlize.el
(defun htmlize-add-before-after-strings (beg end text)
  ;; Find overlays specifying before-string and after-string in [beg,
  ;; pos).  If any are found, splice them into TEXT and return the new
  ;; text.
  (let (additions)
    (dolist (overlay (overlays-in beg end))
      (let ((before (overlay-get overlay 'before-string))
            (after (overlay-get overlay 'after-string)))
        (when after
          (push (cons (- (overlay-end overlay) beg)
                      after)
                additions))
        (when before
          (push (cons (- (overlay-start overlay) beg)
                      before)
                additions))))
    (if additions
        (let ((textlist nil)
              (strpos 0))
          (dolist (add (cl-stable-sort additions #'< :key #'car))
            (let ((addpos (car add))
                  (addtext (cdr add)))
              (push (substring text strpos addpos) textlist)
              (push addtext textlist)
              (setq strpos addpos)))
          (push (substring text strpos) textlist)
          (apply #'concat (nreverse textlist)))
      text)))