如何在org-mode中使内嵌图片具有响应式布局?

9

当我使用org-toggle-inline-images切换内联图像时,会显示出图像。然而,当图像过大时,它将溢出编辑器的框架(见下面的截图)。

enter image description here

如何使图像具有响应性,即图像的最大尺寸不应超过窗口大小的宽度。

当然,我可以使用下面的代码来固定图像的大小。但是我真正想要的是一种响应式的图像显示方式。

(setq org-mode-actual-width 600)

在此输入图片描述

感谢您花时间查看这个问题。

2个回答

6

org-image-actual-width 的文档中可以了解到:

Documentation:
Should we use the actual width of images when inlining them?

When set to t, always use the image width.

When set to a number, use imagemagick (when available) to set
the image's width to this value.

When set to a number in a list, try to get the width from any
#+ATTR.* keyword if it matches a width specification like

  #+ATTR_HTML: :width 300px

and fall back on that number if none is found.

When set to nil, try to get the width from an #+ATTR.* keyword
and fall back on the original width if none is found.

因此,您可以使用属性# + ATTR_HTML来指定宽度。 不过,必须手动指定。 这样响应性好吗?


请查看此答案 https://dev59.com/A2gt5IYBdhLWcg3w-ST1#69339844 以获取“org-image-actual-width”设置为“列表中的数字”时的示例用法。 - zkytony

6
以下函数使用钩子在窗口大小改变时重新渲染org-mode内联图像。仅当窗口显示少于80个列(通常为屏幕的1/3)时,它才会缩小图像。我认为这比始终按窗口宽度呈现更好。
(defun org-image-resize (frame)
  (when (derived-mode-p 'org-mode)
      (if (< (window-total-width) 80)
      (setq org-image-actual-width (window-pixel-width))
    (setq org-image-actual-width (* 80 (window-font-width))))
      (org-redisplay-inline-images)))

(add-hook 'window-size-change-functions 'org-image-resize)

上面代码的 GIF 演示

如果您想让图像与窗口宽度匹配:

(defun org-image-resize (frame)
  (when (derived-mode-p 'org-mode)
      (setq org-image-actual-width (window-pixel-width))
      (org-redisplay-inline-images)))

(add-hook 'window-size-change-functions 'org-image-resize)

如果您想在右侧添加一些边距,则可将 (window-pixel-width) 更改为 (- (window-pixel-width) 20)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接