@@ -149,7 +149,7 @@ pre.src-C:before { content: 'Org-mode Example!'; }
149
149
;; Copyright (c) 2021 Musa Al-hassy
150
150
151
151
;; Author: Musa Al-hassy <
[email protected] >
152
- ;; Version: 4.1.0
152
+ ;; Version: 4.1.1
153
153
;; Package-Requires: ((s "1.13.1") (dash "2.18.1") (emacs "27.1") (org "9.1") (lf "1.0") (dad-joke "1.4") (seq "2.0") (lolcat "0"))
154
154
;; Keywords: org, blocks, colors, convenience
155
155
;; URL: https://alhassy.github.io/org-special-block-extras
@@ -518,10 +518,7 @@ badge:Emacs|27|green|https://www.gnu.org/software/emacs|gnu-emacs
518
518
badge:Org|9.4|blue|https://orgmode.org|gnu
519
519
520
520
#+html: <span>
521
- badge:org-special-block-extras|3.0|informational|https://github.com/alhassy/org-special-block-extras|Gnu-Emacs
522
-
523
- #+html: <a href="https://melpa.org/#/org-special-block-extras"><img alt="MELPA" src="https://melpa.org/packages/org-special-block-extras-badge.svg"/></a>
524
- #+html: </span>
521
+ melpa:org-special-block-extras
525
522
526
523
[[badge:license|GNU_3|informational|https://www.gnu.org/licenses/gpl-3.0.en.html|read-the-docs][gnu 3 license badge]]
527
524
[[badge:docs|literate|success|https://github.com/alhassy/emacs.d#what-does-literate-programming-look-like|read-the-docs][read-the-docs badge]]
@@ -1808,7 +1805,7 @@ Three example uses:
1808
1805
,(org--create-defmethod-of-defblock name docstring (plist-get kwds :backend) kwds body)
1809
1806
;; ⇨ The link type support
1810
1807
(eval (backquote (org-deflink ,name
1811
- ,(vconcat `[:help-echo (format "%s:%s\n\n%s" (quote ,name) o-label ,docstring)] (cdr (assoc name org--block--link-display)))
1808
+ ,(vconcat `[:help-echo (format "%s:%s\n\n%s" (quote ,name) o-label ,docstring)] (or link-display ( cdr (assoc name org--block--link-display) )))
1812
1809
;; s-replace-all `((,(format "@@%s:" backend) . "") ("#+end_export" . "") (,(format "#+begin_export %s" backend) . ""))
1813
1810
(s-replace-regexp "@@" ""
1814
1811
(,(intern (format "org-block/%s" name)) o-backend (or o-description o-label) o-label :o-link? t)))))))))
@@ -3195,7 +3192,7 @@ then:
3195
3192
3196
3193
Bye!
3197
3194
#+end_box
3198
- * Basic defblock test :relocate:noexport:
3195
+ ** Basic defblock test :relocate:noexport:
3199
3196
:PROPERTIES:
3200
3197
:CUSTOM_ID: Basic-defblock-test
3201
3198
:END:
@@ -3257,6 +3254,70 @@ post")
3257
3254
"<p>\npost"))
3258
3255
#+end_src
3259
3256
3257
+ ** Dispatch on =backend= ---open for extensibility
3258
+ :PROPERTIES:
3259
+ :CUSTOM_ID: Dispatch-on-backend-open-for-extensibility
3260
+ :END:
3261
+
3262
+ Consider the source and how it exports ...
3263
+ #+begin_org-demo
3264
+ The link “ [[shout:me the author][hello to the world]] ” exports with bold in HTML and large in LaTeX.
3265
+ #+end_org-demo
3266
+ # C-c C-e h o ⇒ bold
3267
+ # C-c C-e l o ⇒ large
3268
+
3269
+ This could be declared via ...
3270
+ #+begin_src elisp :tangle no
3271
+ ;; Declare the new defblock, along with how it should be displayed as an org link
3272
+ (org-defblock shout0 (speaker)
3273
+ [:face '(:foreground "orange" :weight bold) :display 'full]
3274
+ "Capitalise the contents! Seen in orange bold in Emacs!"
3275
+ (pcase backend
3276
+ ('html (format "Yuck/%s: <strong>%s</strong>" speaker contents))
3277
+ ('latex (format "Yuck/%s: \\emph{\\LARGE %s}" speaker contents))
3278
+ (t (error "org-block/shout: Unsupported backend “%s”" backend))))
3279
+ #+end_src
3280
+
3281
+ Rather than defining it with a single defblock declaration and a condition on the backend, we can define it using three
3282
+ defblock declarations: One to declare the block along with top-level documentation and display link information; the
3283
+ second for the HTML export; the third for the LaTeX backend export. (Your favourite backend ℬ can easily be supported by
3284
+ declaring a new defblock in /your own code/!)
3285
+
3286
+ #+name: startup-code
3287
+ #+begin_src elisp :tangle no
3288
+ ;; Declare the new defblock, along with how it should be displayed as an org link
3289
+ (org-defblock shout (speaker)
3290
+ [:face '(:foreground "orange" :weight bold) :display 'full]
3291
+ "Capitalise the contents! Seen in orange bold in Emacs!")
3292
+
3293
+
3294
+ ;; Specialise its definition for when we export to the HTML backend
3295
+ (org-defblock shout (speaker nil :backend html)
3296
+ "To shout is to be bold; i.e., strong."
3297
+ (format "%s: <strong>%s</strong>" speaker contents))
3298
+
3299
+
3300
+ ;; Specialise its definition for when we export to the LaTeX backend
3301
+ (org-defblock shout (speaker nil :backend latex)
3302
+ "Shouting is a what LARGE brutes do"
3303
+ (format "%s: \\emph{\\LARGE %s}" speaker contents))
3304
+ #+end_src
3305
+
3306
+ Try kbd:C-h_o_org-defblock/shout and see two implementations.
3307
+ - This means that users can always re-define an org special block, or extend it to support a new backend. Neato!
3308
+ - Free user extensibility!
3309
+
3310
+ Such “open methods” are known as “multimethods”; e.g., see doc:cl-defgeneric and doc:cl-defmethod.
3311
+
3312
+ :Multimethod_invocation_examples_of_SHOUT:
3313
+ #+begin_src elisp :tangle no
3314
+ ;; Example uses of the multimethods approach
3315
+ (org-block/shout 'random-backend "hi") ;; should error!
3316
+ (org-block/shout 'html "hi")
3317
+ (org-block/shout 'latex "hi")
3318
+ #+end_src
3319
+ :End:
3320
+
3260
3321
* Folded Details ---As well as boxed text and subtle colours
3261
3322
:PROPERTIES:
3262
3323
:CUSTOM_ID: Folded-Details
@@ -3332,61 +3393,6 @@ it may be prudent to expose more aspects as arguments.
3332
3393
</details>" background-color title-color title contents))))
3333
3394
#+end_src
3334
3395
3335
- #+RESULTS:
3336
- | :export | (lambda (label description backend) (s-replace-all `((#+end_export . ) (,(format #+begin_export %s backend) . )) (org--details backend (or description label) label))) | :help-echo | (lambda (window object position) (save-excursion (goto-char position) (-let* (((&plist :path :format :raw-link :contents-begin :contents-end) (cadr (org-element-context))) (description (when (equal format 'bracket) (copy-region-as-kill contents-begin contents-end) (substring-no-properties (car kill-ring))))) (format %s |
3337
-
3338
- :HACK:Disabled:
3339
- Above is a lower-case ‘d’etails block, we now make a captial-case ‘D’etails
3340
- block, for the not-too-odd situation we want to have, right away, one details block
3341
- within another.
3342
- #+begin_src emacs-lisp :exports none
3343
- (org-defblock Details (title "Details"
3344
- background-color "#e5f5e5" title-color "green")
3345
- "Enclose contents in a folded up box, for HTML.
3346
-
3347
- For LaTeX, this is just a boring, but centered, box.
3348
-
3349
- By default, the TITLE of such blocks is “Details”
3350
- its TITLE-COLOR is green, and BACKGROUND-COLOR is “#e5f5e5”.
3351
-
3352
- In HTML, we show folded, details, regions with a nice greenish colour.
3353
-
3354
- In the future ---i.e., when I have time---
3355
- it may be prudent to expose more aspects as arguments.
3356
- "
3357
- (pcase backend
3358
- (`latex (concat (pcase (substring background-color 0 1)
3359
- ("#" (format "\\definecolor{osbe-bg}{HTML}{%s}" (substring background-color 1)))
3360
- (_ (format "\\colorlet{osbe-bg}{%s}" background-color)))
3361
- (pcase (substring title-color 0 1)
3362
- ("#" (format "\\definecolor{osbe-fg}{HTML}{%s}" (substring title-color 1)))
3363
- (_ (format "\\colorlet{osbe-fg}{%s}" title-color)))
3364
- (format "\\begin{quote}
3365
- \\begin{tcolorbox}[colback=osbe-bg,colframe=osbe-fg,title={%s},sharp corners,boxrule=0.4pt]
3366
- %s
3367
- \\end{tcolorbox}
3368
- \\end{quote}" title contents)))
3369
- (_ (format "<details class=\"code-details\"
3370
- style =\"padding: 1em;
3371
- background-color: %s;
3372
- border-radius: 15px;
3373
- color: hsl(157 75% 20%);
3374
- font-size: 0.9em;
3375
- box-shadow: 0.05em 0.1em 5px 0.01em #00000057;\">
3376
- <summary>
3377
- <strong>
3378
- <font face=\"Courier\" size=\"3\" color=\"%s\">
3379
- %s
3380
- </font>
3381
- </strong>
3382
- </summary>
3383
- %s
3384
- </details>" background-color title-color title contents))))
3385
- #+end_src
3386
- MA: TODO: The above should not be present, it should instead be factored out
3387
- into a defblock-alias function.
3388
- :End:
3389
-
3390
3396
:Posterity_Older_implementation:
3391
3397
#+BEGIN_SRC emacs-lisp -n -r :tangle no
3392
3398
(defun org--details (backend contents)
@@ -6088,7 +6094,7 @@ wish to use; e.g., badge:|1d8348|1d8348
6088
6094
the LaTeX backend. {{{newline}}} [[remark:Author][That is why no examples are shown in the PDF]] It
6089
6095
may be useful to colour the =|=-separated fields of a badge link.
6090
6096
# This would make the interface more welcoming to new users.
6091
- * COMMENT Tooltips for Glossaries, Dictionaries, and Documentation
6097
+ * Tooltips for Glossaries, Dictionaries, and Documentation
6092
6098
:PROPERTIES:
6093
6099
:CUSTOM_ID: Tooltips-for-Glossaries-Dictionaries-and-Documentation
6094
6100
:END:
@@ -7489,7 +7495,7 @@ block types; whereas they currently break the HTML export.
7489
7495
to its associated =#+begin_documentation= declaration block in the current
7490
7496
buffer, if possible.
7491
7497
7492
- * COMMENT Marginal, “one-off”, remarks
7498
+ * Marginal, “one-off”, remarks
7493
7499
:PROPERTIES:
7494
7500
:CUSTOM_ID: Marginal-one-off-remarks
7495
7501
:END:
0 commit comments