Function: markdown-syntax-propertize-fenced-block-constructs

markdown-syntax-propertize-fenced-block-constructs is a byte-compiled function defined in markdown-mode.el.

Signature

(markdown-syntax-propertize-fenced-block-constructs START END)

Documentation

Propertize according to markdown-fenced-block-pairs from START to END.

If unable to propertize an entire block (if the start of a block is within START and END, but the end of the block is not), propertize the start section of a block, then in a subsequent call propertize both middle and end by finding the start which was previously propertized.

Source Code

;; Defined in ~/.emacs.d/elpa/markdown-mode-20260321.143/markdown-mode.el
(defun markdown-syntax-propertize-fenced-block-constructs (start end)
  "Propertize according to `markdown-fenced-block-pairs' from START to END.
If unable to propertize an entire block (if the start of a block is within START
and END, but the end of the block is not), propertize the start section of a
block, then in a subsequent call propertize both middle and end by finding the
start which was previously propertized."
  (let ((start-reg (markdown-get-start-fence-regexp)))
    (save-excursion
      (goto-char start)
      ;; start from previous unclosed block, if exists
      (let ((prev-begin-block (markdown-find-previous-block)))
        (when prev-begin-block
          (let* ((correct-entry
                  (cl-find-if (lambda (entry)
                                (eq (cdr prev-begin-block) (cl-cadar entry)))
                              markdown-fenced-block-pairs))
                 (enclosed-text-start (1+ (car prev-begin-block)))
                 (start-length
                  (save-excursion
                    (goto-char (car prev-begin-block))
                    (string-match
                     (markdown-maybe-funcall-regexp
                      (caar correct-entry))
                     (buffer-substring
                      (line-beginning-position) (line-end-position)))
                    (- (match-end 1) (match-beginning 1))))
                 (end-reg (markdown-maybe-funcall-regexp
                           (cl-caadr correct-entry) start-length)))
            (markdown-propertize-end-match
             end-reg end correct-entry enclosed-text-start))))
      ;; find all new blocks within region
      (while (re-search-forward start-reg end t)
        ;; we assume the opening constructs take up (only) an entire line,
        ;; so we re-check the current line
        (let* ((block-start (match-beginning 0))
               (cur-line (buffer-substring (line-beginning-position) (line-end-position)))
               ;; find entry in `markdown-fenced-block-pairs' corresponding
               ;; to regex which was matched
               (correct-entry
                (cl-find-if
                 (lambda (fenced-pair)
                   (string-match-p
                    (markdown-maybe-funcall-regexp (caar fenced-pair))
                    cur-line))
                 markdown-fenced-block-pairs))
               (enclosed-text-start
                (save-excursion (1+ (line-end-position))))
               (end-reg
                (markdown-maybe-funcall-regexp
                 (cl-caadr correct-entry)
                 (if (and (match-beginning 1) (match-end 1))
                     (- (match-end 1) (match-beginning 1))
                   0)))
               (prop (cl-cadar correct-entry)))
          (when (or (not (eq prop 'markdown-gfm-block-begin))
                    (not (markdown--code-fence-single-line-p block-start)))
            ;; get correct match data
            (save-excursion
              (beginning-of-line)
              (re-search-forward
               (markdown-maybe-funcall-regexp (caar correct-entry))
               (line-end-position)))
            ;; mark starting, even if ending is outside of region
            (put-text-property (match-beginning 0) (match-end 0) prop (match-data t))
            (markdown-propertize-end-match
             end-reg end correct-entry enclosed-text-start)))))))