He hecho algo parecido . Está en francés, pero el código debería hablar por sí mismo. Lo uso ‰
para el marcador (uso un diseño bepo ), y cuando lo hago, el texto marcado como un estilo de botón presionado.
No hablo con fluidez, por lo que puede haber margen de mejora.
Lo que he hecho es que, cuando se usa ‰
para marcador, el texto marcado tiene un estilo de botón presionado, y cuando se exporta se traduce a<kbd>
Primero, tuve que definir una nueva cara:
(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)
Luego personaliza 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
Para la exportación, es posible que deba cargar ox.el
con (require 'ox)
.
Luego, cada vez bold
o code
aparece en una función (en ox-org.el
), he creado una función similar (o modifiqué las existentes):
;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))))))
A continuación, he definido un my-html
back-end para la exportación:
(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))
Entonces, cuando lo uso, C-c C-e h r
se exporta correctamente:
Según lo sugerido por OP en los comentarios, es posible que deba usar org-mode-restart
(o org-reload
) o matar / recargar su búfer.
Editar: Esto funciona para el modo org con versiones anteriores a la 8.3 (es decir, hasta la 8.2.10)
Con versiones ≥8.3.1, tengo que modificar
- elemento-org-todos-objetos
- posiblemente org-element-object-restrictions
- org-element - set-regexps
- elemento-org - objeto-lex
y por supuesto aún agrego las funciones
- org-element-my-object-keystroke-parser
- org-element-my-object-keystroke-interpreter
pero
- org-element-object-successor-alist
- org-element-text-markup-successor
ahora están eliminados
Gracias a Charles C. Berry por su ayuda.