您的位置:首页 > 其它

使用Emacs中的org-mode写cnblogs之图片插入

2017-01-15 17:27 295 查看
.title { text-align: center }
.todo { font-family: monospace; color: red }
.done { color: green }
.tag { background-color: #eee; font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal }
.timestamp { color: #bebebe }
.timestamp-kwd { color: #5f9ea0 }
.right { margin-left: auto; margin-right: 0px; text-align: right }
.left { margin-left: 0px; margin-right: auto; text-align: left }
.center { margin-left: auto; margin-right: auto; text-align: center }
.underline { text-decoration: underline }
#postamble p,#preamble p { font-size: 90%; margin: .2em }
p.verse { margin-left: 3% }
pre { border: 1px solid #ccc; padding: 8pt; font-family: monospace; overflow: auto; margin: 1.2em }
pre.src { position: relative; overflow: visible; padding-top: 1.2em }
pre.src::before { display: none; position: absolute; background-color: white; top: -10px; right: 10px; padding: 3px; border: 1px solid black }
pre.src:hover::before { display: inline }
pre.src-sh::before { content: "sh" }
pre.src-bash::before { content: "sh" }
pre.src-emacs-lisp::before { content: "Emacs Lisp" }
pre.src-R::before { content: "R" }
pre.src-perl::before { content: "Perl" }
pre.src-java::before { content: "Java" }
pre.src-sql::before { content: "SQL" }
table { border-collapse: collapse }
caption.t-above { caption-side: top }
caption.t-bottom { caption-side: bottom }
td,th { vertical-align: top }
th.right { text-align: center }
th.left { text-align: center }
th.center { text-align: center }
td.right { text-align: right }
td.left { text-align: left }
td.center { text-align: center }
dt { font-weight: bold }
.footpara:nth-child(0n+2) { display: inline }
.footpara { display: block }
.footdef { margin-bottom: 1em }
.figure { padding: 1em }
.figure p { text-align: center }
.inlinetask { padding: 10px; border: 2px solid gray; margin: 10px; background: #ffffcc }
#org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap }
textarea { }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00 }
.org-info-js_info-navigation { border-style: none }
#org-info-js_console-label { font-size: 10px; font-weight: bold; white-space: nowrap }
.org-info-js_search-highlight { background-color: #ffff00; color: #000000; font-weight: bold }
code { color: #FF0000 }
pre.src { background-color: #002b36; color: #839496 }

使用Emacs中的org-mode写cnblogs之图片插入

Table of Contents

1. 效果

2. 原生org-mode的图片插入

3. 使用org-download进行图片插入

4. 截图软件

用Emacs的org-mode来做记录和写博客,真的是太方便了。而其中,原生的org-mode有所欠缺的是图片的插入。

1 效果



2 原生org-mode的图片插入

org-mode中插入图片或者其他的资源,是通过
C-c C-l
把图片的文件路径粘贴进行进行插入。需要在org中显示图片,首先需要Emacs支持图片的显示。这个可以下载一个支持图片的版本(主要是图片显示的lib_png之类的.dll)。

但是这种方式比较麻烦,每次都要创建一个图片,然后,把图片的文件路径粘贴进行进行插入。

3 使用org-download进行图片插入

使用package插件安装org-download,然后配置:

(use-package org-download
:bind ("C-S-y" . org-download-clipboard)
:config
(defun org-download-clipboard ()
"Save the captured image from clipboard to file, and insert into buffer. Or org-download-yank."
(interactive)
(let ((link "http://images2015.cnblogs.com/blog/717724/201703/717724-20170318145647104-177813066.jpg"))
(if (eq 0 (shell-command (format "\"c:/Program\sFiles/ImageMagick-6.9.3-Q16/convert.exe\" clipboard:myimage %s" link) "*screenshot2file*" "*screenshot2file*"))
(org-download-image link)
(org-download-yank)))))


org-download本身会自动在org文档当前目录下创建一个与文档同名的文件夹来保存图片,然后支持多种途径的图片插入,插入之后会复制或者下载一张图片到图片文件夹下面:

用url把图片插入,然后自动下载;

复制图片文件路径,然后插入;

拖拽图片插入。

但是,org-download不会把剪切板中的图片自动保存一个图片文件,然后插入。所以,必须要借助于外部程序。可以使用任意一个带命令行参数的图片保存器将剪切板中的图片进行保存。有人写了一个csharp的程序,很小很小就可以做到了。我这里直接使用ImageMagick ,因为这个软件实在是太强大了,而且是免费的。路径我们可以根据自己的安装路径来进行配置,然后,先调用里面的convert.exe把剪切板里面的图片保存到一个临时目录下面。我这里是
d:/temp/
,这个可以根据自己的需要来设置。然后,定义了一个快捷键
C-S-Y
,比原来的粘贴键多了一个shift,就可以粘贴图片了。

4 截图软件

剪切板中的图片可以是从另外一个地方复制来的,但更多的场景是使用截图软件进行截图,然后粘贴的。我使用的截图软件是faststone,程序很小,但是功能很强大,既可以截图也可以录视频,还可以编辑视频,对于简单的插入便条,字幕之类的处理,特别方便。还可以设置快捷键,截选择框、窗口、滚动条内窗口内容等等,非常方便。下面截个图粘贴一下做个示例:



Date: 2017-01-13 21:41

Created: 2017-03-18 周六 14:56

Emacs 26.0.50 (Org mode 8.2.10)

Validate
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: