Function: markdown-insert-header
markdown-insert-header is an interactive and byte-compiled function
defined in markdown-mode.el.
Signature
(markdown-insert-header &optional LEVEL TEXT SETEXT)
Documentation
Insert or replace header markup.
The level of the header is specified by LEVEL and header text is given by TEXT. LEVEL must be an integer from 1 and 6, and the default value is 1. When TEXT is nil, the header text is obtained as follows. If there is an active region, it is used as the header text. Otherwise, the current line will be used as the header text. If there is not an active region and the point is at a header, remove the header markup and replace with level N header. Otherwise, insert empty header markup and place the point in between. The style of the header will be atx (hash marks) unless SETEXT is non-nil, in which case a setext-style (underlined) header will be inserted.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/markdown-mode-20260321.143/markdown-mode.el
(defun markdown-insert-header (&optional level text setext)
"Insert or replace header markup.
The level of the header is specified by LEVEL and header text is
given by TEXT. LEVEL must be an integer from 1 and 6, and the
default value is 1.
When TEXT is nil, the header text is obtained as follows.
If there is an active region, it is used as the header text.
Otherwise, the current line will be used as the header text.
If there is not an active region and the point is at a header,
remove the header markup and replace with level N header.
Otherwise, insert empty header markup and place the point in
between.
The style of the header will be atx (hash marks) unless
SETEXT is non-nil, in which case a setext-style (underlined)
header will be inserted."
(interactive "p\nsHeader text: ")
(setq level (min (max (or level 1) 1) (if setext 2 6)))
;; Determine header text if not given
(when (null text)
(if (use-region-p)
;; Active region
(setq text (delete-and-extract-region (region-beginning) (region-end)))
;; No active region
(markdown-remove-header)
(setq text (delete-and-extract-region
(line-beginning-position) (line-end-position)))
(when (and setext (string-match-p "^[ \t]*$" text))
(setq text (read-string "Header text: "))))
(setq text (markdown-compress-whitespace-string text)))
;; Insertion with given text
(markdown-ensure-blank-line-before)
(let (hdr)
(cond (setext
(setq hdr (make-string (string-width text) (if (= level 2) ?- ?=)))
(insert text "\n" hdr))
(t
(setq hdr (make-string level ?#))
(insert hdr " " text)
(when (null markdown-asymmetric-header) (insert " " hdr)))))
(markdown-ensure-blank-line-after)
;; Leave point at end of text
(cond (setext
(backward-char (1+ (string-width text))))
((null markdown-asymmetric-header)
(backward-char (1+ level)))))