Ho fatto qualcosa di simile . È in francese, ma il codice dovrebbe parlare da solo. Uso ‰
il marcatore (utilizzo un layout bepo ) e, quando lo faccio, il testo contrassegnato come stile pulsante premuto.
Non sono fluente in lisp, quindi potrebbe esserci spazio per miglioramenti.
Quello che ho fatto è che, quando si usa ‰
per marker, il testo contrassegnato ha uno stile pulsante e, quando viene esportato, viene tradotto in<kbd>
Innanzitutto, ho dovuto definire un nuovo volto:
(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)
Quindi personalizza 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
Per l'esportazione, potrebbe essere necessario caricare ox.el
con (require 'ox)
.
Quindi ogni volta bold
o code
appare in una funzione (in ox-org.el
), ho creato una funzione simile (o modificata quelle esistenti):
;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))))))
Successivamente, ho definito un my-html
backend per l'esportazione:
(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))
Quindi quando lo uso C-c C-e h r
viene esportato correttamente:
Come suggerito dall'OP nei commenti, potrebbe essere necessario utilizzare org-mode-restart
(o org-reload
) o eliminare / ricaricare il buffer.
Modifica: funziona con la modalità org con versioni precedenti alla 8.3 (cioè fino alla 8.2.10)
Con le versioni ≥8.3.1, devo modificare
- org-elemento-tutti-oggetti
- possibilmente org-element-object-restrizioni
- org-elementi - set-espressioni regolari
- org-elementi - oggetto-lex
e ovviamente aggiungo ancora le funzioni
- org-elemento-my-oggetto-battitura-parser
- org-elemento-my-oggetto-battitura-interprete
ma
- org-elemento oggetto-successore-alist
- org-elemento-text-markup-successore
sono ora eliminati.
Grazie a Charles C. Berry per il suo aiuto.