Function: eglot--format-markup

eglot--format-markup is a byte-compiled function defined in eglot.el.gz.

Signature

(eglot--format-markup MARKUP &optional MODE)

Documentation

Format MARKUP according to LSP's spec.

MARKUP is either an LSP MarkedString or MarkupContent object.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot--format-markup (markup &optional mode)
  "Format MARKUP according to LSP's spec.
MARKUP is either an LSP MarkedString or MarkupContent object."
  (let (string render-mode language)
    (cond ((stringp markup)
           (setq string markup
                 render-mode (or mode 'gfm-view-mode)))
          ((setq language (plist-get markup :language))
           ;; Deprecated MarkedString
           (setq string (concat "```" language "\n"
                                (plist-get markup :value) "\n```")
                 render-mode (or mode 'gfm-view-mode)))
          (t
           ;; MarkupContent
           (setq string (plist-get markup :value)
                 render-mode
                 (or mode
                     (pcase (plist-get markup :kind)
                       ("markdown" 'gfm-view-mode)
                       ("plaintext" 'text-mode)
                       (_ major-mode))))))
    (with-temp-buffer
      (setq-local markdown-fontify-code-blocks-natively t)
      (insert string)
      (let ((inhibit-message t)
            (message-log-max nil)
            match)
        (ignore-errors (delay-mode-hooks (funcall render-mode)))
        (font-lock-ensure)
        (goto-char (point-min))
        (let ((inhibit-read-only t))
          (when (fboundp 'text-property-search-forward)
            ;; If `render-mode' is `gfm-view-mode', the `invisible'
            ;; regions are set to `markdown-markup'.  Set them to 't'
            ;; instead, since this has actual meaning in the "*eldoc*"
            ;; buffer where we're taking this string (#bug79552).
            (while (setq match (text-property-search-forward 'invisible))
              (put-text-property (prop-match-beginning match)
                                 (prop-match-end match)
                                 'invisible t))))
        (string-trim (buffer-string))))))