Skip to content

Enable different header scaling in markdown-mode and markdown-view-mode #858

@mattiasb

Description

@mattiasb

Expected Behavior

I would like to have header scaling enabled in markdown-view-mode but
not in markdown-mode.

I have a local hack in my personal config that looks like this:

;;;###autoload
(define-minor-mode +markdown-scale-headers-mode
  "Scale `markdown-mode' headers."
  :lighter "M↑"
  (+markdown-update-header-faces +markdown-scale-headers-mode))

(defun +markdown-update-header-faces (&optional scaling scaling-values)
  "Update header faces, depending on if header SCALING is desired.
If so, use given list of SCALING-VALUES relative to the baseline
size of `markdown-header-face'.
Like `markdown-update-header-faces' but buffer local."
  (dotimes (num 6)
    (let* ((face-name (intern (format "markdown-header-face-%s" (1+ num))))
           (scale (cond ((not scaling) 1.0)
                        (scaling-values (float (nth num scaling-values)))
                        (t (float (nth num markdown-header-scaling-values))))))
      (unless (get face-name 'saved-face) ; Don't update customized faces
        (face-remap-add-relative face-name :height scale)))))

The important points in the code snippet above are:

  1. I add a buffer local minor mode for enabling or disabling header scaling
  2. I change markdown-update-header-faces like this:
    - (set-face-attribute face-name nil :height scale)
    + (face-remap-add-relative face-name :height scale)

Posting this hack in the issue itself is mostly to show that it can be done
but I realize there are several ways to do this and there might be downsides
I haven't considered.

Actual Behavior

Enabling markdown-header-scaling will toggle header scaling in all modes.

Steps to Reproduce

  1. Enable header scaling

Software Versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions