UP | HOME

Markdown

like markdown to use a variable-pitch font, with different font sizes for h1-h6, it’s almost wsywig.

emacs-lisp :comments both :mkdirp yes :tangle ~/.emacs.d/chee/setup-markdown.el

(use-package markdown-mode
  :straight t
  :mode "\\.md\\'"
  :bind (:map markdown-mode-map
              ("s-b" . markdown-insert-bold)
              ("s-i" . markdown-insert-italic)
              ("s-C" . markdown-insert-code)
              ("C-c C-'" . markdown-edit-code-block)
              ("C-c i" . markdown-insert-image)
              ("C-c TAB" . chee/interupt-code-block))
  :config
  (use-package markdown-edit-indirect :straight t)

  (defun chee/open-in-marked nil
    "Open currrent buffer in marked."
    (interactive)
    (async-shell-command
     (concat "open -a 'Marked 2' '" (buffer-file-name) "'")))

  (defun chee/interupt-code-block nil
    "Inject an end and a new beginning at this point in a markdown
                                                        code block."
    (interactive)
    (when (point-at-bol-or-indentation)
      (forward-line -1))
    (end-of-line)
    (let
        ((header
          (save-excursion
            (re-search-backward "^```")
            ;; get everything on the header line after "```"
            (buffer-substring (+ (point) 3) (progn (end-of-line) (point))))))
      (insert "\n```\n\n```" header)
      (forward-line -1)))

  (add-hook 'markdown-mode-hook #'auto-fill-mode)  :custom
  (markdown-fontify-code-blocks-natively t)
  (markdown-header-scaling t)
  :custom
  (markdown-hr-strings '("***" "---"))
  (markdown-italic-underscore t))

(provide 'setup-markdown)