Saya telah melakukan hal serupa . Itu dalam bahasa Prancis, tetapi kodenya harus berbicara sendiri. Saya menggunakan ‰
untuk penanda (saya menggunakan tata letak bepo ), dan ketika saya melakukannya, teks yang ditandai sebagai gaya tombol-ditekan.
Saya tidak lancar berbahasa Inggris, jadi mungkin ada ruang untuk perbaikan.
Apa yang telah saya lakukan adalah bahwa, ketika menggunakan ‰
untuk marker, teks yang ditandai memiliki gaya tombol-ditekan, dan ketika diekspor itu diterjemahkan ke<kbd>
Pertama, saya harus mendefinisikan wajah baru:
(defface my-face-org-keystroke
'((t (:inherit shadow
:box (:line-width -2 ;neg. in order to keep the same size of lines
:color "grey75"
:style pressed-button)))) "Face for keystrokes"
:group 'org-faces)
Kemudian sesuaikan org-emphasis-alist
:
(("*" bold)
("/" italic)
("_" underline)
("=" org-code verbatim)
("~" org-verbatim verbatim)
("+"
(:strike-through t))
("‰" my-face-org-keystroke verbatim));This line is what you want to add
Untuk ekspor, Anda mungkin perlu memuat ox.el
dengan (require 'ox)
.
Kemudian setiap kali bold
atau code
muncul dalam suatu fungsi (dalam ox-org.el
), saya telah membuat fungsi serupa (atau memodifikasi yang sudah ada):
;creation
(defun org-html-keystroke (keystroke contents info)
"Transcode KEYSTROKE from Org to HTML.
CONTENTS is nil. INFO is a plist holding contextual
information."
(format (or (cdr (assq 'my-object-keystroke org-html-text-markup-alist)) "%s")
(org-html-encode-plain-text (org-element-property :value keystroke))))
;creation
(defun org-element-my-object-keystroke-parser ()
"Parse code object at point.
Return a list whose CAR is `my-object-keystroke' and CDR is a plist with
`:value', `:begin', `:end' and `:post-blank' keywords.
Assume point is at the first tilde marker."
(interactive)
(save-excursion
(unless (bolp) (backward-char 1))
(looking-at org-emph-re)
(let ((begin (match-beginning 2))
(value (org-match-string-no-properties 4))
(post-blank (progn (goto-char (match-end 2))
(skip-chars-forward " \t")))
(end (point)))
(list 'my-object-keystroke
(list :value value
:begin begin
:end end
:post-blank post-blank)))))
;creation
(defun org-element-my-object-keystroke-interpreter (keystroke contents)
"Interpret KEYSTROKE object as Org syntax.
CONTENTS is nil."
(format "‰%s‰" (org-element-property :value keystroke)))
;modification
(defconst org-element-object-successor-alist
'((subscript . sub/superscript) (superscript . sub/superscript)
(bold . text-markup) (code . text-markup) (italic . text-markup)
(strike-through . text-markup) (underline . text-markup)
(verbatim . text-markup) (entity . latex-or-entity)
(latex-fragment . latex-or-entity) (my-object-keystroke . text-markup))
"Alist of translations between object type and successor name.
Sharing the same successor comes handy when, for example, the
regexp matching one object can also match the other object.")
;modification
(defconst org-element-all-objects
'(bold code entity export-snippet footnote-reference inline-babel-call
inline-src-block italic line-break latex-fragment link macro
radio-target statistics-cookie strike-through subscript superscript
table-cell target timestamp underline verbatim my-object-keystroke)
"Complete list of object types.")
;modification
(defun org-element-text-markup-successor ()
"Search for the next text-markup object.
Return value is a cons cell whose CAR is a symbol among `bold',
`italic', `underline', `strike-through', `code' and `verbatim'
and CDR is beginning position."
(save-excursion
(unless (bolp) (backward-char))
(when (re-search-forward org-emph-re nil t)
(let ((marker (match-string 3)))
(cons (cond
((equal marker "*") 'bold)
((equal marker "/") 'italic)
((equal marker "_") 'underline)
((equal marker "+") 'strike-through)
((equal marker "~") 'code)
((equal marker "=") 'verbatim)
((equal marker "‰") 'my-object-keystroke)
(t (error "Unknown marker at %d" (match-beginning 3))))
(match-beginning 2))))))
Selanjutnya, saya telah menetapkan my-html
backend untuk ekspor:
(org-export-define-derived-backend 'my-html 'html
:translate-alist '((my-object-keystroke . org-html-keystroke))
:menu-entry ' (?h 1
((?r "my-html" org-html-export-to-my-html))))
(defun org-html-export-to-my-html
(&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to a HTML file.
Return output file's name."
(interactive)
(let* ((extension (concat "." org-html-extension))
(file (org-export-output-file-name extension subtreep))
(org-export-coding-system org-html-coding-system))
(org-export-to-file 'my-html file
async subtreep visible-only body-only ext-plist)))
(defun org-html-publish-to-my-html (plist filename pub-dir)
"Publish an org file to my-html.
Return output file name."
(org-publish-org-to 'my-html filename
(concat "." (or (plist-get plist :html-extension)
org-html-extension "html"))
plist pub-dir))
(defun org-html-convert-region-to-my-html ()
"Assume the current region has org-mode syntax, and convert it to HTML.
This can be used in any buffer. For example, you can write an
itemized list in org-mode syntax in an HTML buffer and use this
command to convert it."
(interactive)
(org-export-replace-region-by 'my-html))
Jadi ketika saya menggunakannya C-c C-e h r
diekspor dengan benar:
Seperti yang disarankan oleh OP dalam komentar, Anda mungkin perlu menggunakan org-mode-restart
(atau org-reload
) atau membunuh / memuat ulang buffer Anda.
Sunting: Ini berfungsi untuk mode-org dengan versi sebelumnya 8.3 (yaitu sampai 8.2.10)
Dengan versi ≥8.3.1, saya harus memodifikasi
- org-elemen-semua-objek
- mungkin org-elemen-objek-pembatasan
- org-element - set-regexps
- org-element - object-lex
dan tentu saja masih menambahkan fungsi
- org-element-my-object-keystroke-parser
- org-element-my-object-keystroke-interpreter
tapi
- org-element-object-successor-alist
- org-element-text-markup-successor
sekarang dihapus.
Terima kasih kepada Charles C. Berry untuk bantuannya.