Skip to content

Commit

Permalink
Move blog specific sections to AlBasmala.el in my blog repo
Browse files Browse the repository at this point in the history
  • Loading branch information
alhassy committed Mar 22, 2024
1 parent b8849e4 commit 49df883
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 98 deletions.
7 changes: 6 additions & 1 deletion .aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 346
personal_ws-1.1 en 351
ACSII
AST
ASTs
Expand Down Expand Up @@ -66,13 +66,15 @@ Musa's
Nasriyah
Neato
Netmask
Occultation
Orchestrator
PackageFormer
PackageFormer's
Parametricity
Prepend
Procedurally
Prolog
Protobuf
Protobufs
Pseudocode
Pushout
Expand Down Expand Up @@ -141,6 +143,7 @@ combinators
compositional
computability
computable
concat
connectedness
continous
contrapositive
Expand Down Expand Up @@ -169,6 +172,7 @@ disjunction
disjunctions
distributivity
dualised
emacs
endofunctors
equalities
equational
Expand Down Expand Up @@ -284,6 +288,7 @@ reachability
rebased
redistributable
reduct
repl
representable
requireds
reusability
Expand Down
98 changes: 1 addition & 97 deletions init.org
Original file line number Diff line number Diff line change
Expand Up @@ -8916,103 +8916,7 @@ anchors.
;; Can be used to export a file into a coloured html.
#+END_SRC

*** Ensuring Useful HTML Anchors
:PROPERTIES:
:CUSTOM_ID: Ensuring-Useful-HTML-Anchors
:END:

Upon HTML export, each tree heading is assigned an ID to be used for hyperlinks.
Default IDs are something like ~org1957a9d~, which does not endure the test of time:
Re-export will produce a different id. Here's a rough snippet to generate
IDs from headings, by replacing spaces with hyphens, for headings without IDs.

#+BEGIN_SRC emacs-lisp
(defun my/ensure-headline-ids (&rest _)
"Org trees without a

All non-alphanumeric characters are cleverly replaced with ‘-’.

If multiple trees end-up with the same id property, issue a
message and undo any property insertion thus far.

E.g., ↯ We'll go on a ∀∃⇅ adventure
↦ We'll-go-on-a-adventure
"
(interactive)
(let ((ids))
(org-map-entries
(lambda ()
(org-with-point-at (point)
(let ((id (org-entry-get nil "CUSTOM_ID")))
(unless id
(thread-last (nth 4 (org-heading-components))
(s-replace-regexp "[^[:alnum:]']" "-")
(s-replace-regexp "-+" "-")
(s-chop-prefix "-")
(s-chop-suffix "-")
(setq id))
(if (not (member id ids))
(push id ids)
(message-box "Oh no, a repeated id!\n\n\t%s" id)
(undo)
(setq quit-flag t))
(org-entry-put nil "CUSTOM_ID" id))))))))

;; Whenever html & md export happens, ensure we have headline ids.
(advice-add 'org-html-export-to-html :before 'my/ensure-headline-ids)
(advice-add 'org-md-export-to-markdown :before 'my/ensure-headline-ids)
#+END_SRC

One may then use ~[[#my-custom-id]]~ to link to the entry with ~CUSTOM_ID~
property ~my-custom-id~.

Interestingly, ~org-set-property~, ~C-c C-x p~, lets us insert a property
from a selection of available ones, then we'll be prompted for a value
for it from a list of values you've used elsewhere. This is useful for
remaining consistent for when trees share similar properties.

*** Clickable Headlines
:PROPERTIES:
:CUSTOM_ID: Clickable-Headlines
:END:

By default, HTML export generates ID's to headlines so they may be referenced
to, but there is no convenient way to get at them to refer to a particular
heading. The following spell fixes this issue: Headlines are now clickable,
resulting in a link to the headline itself.

#+begin_src emacs-lisp
;; Src: https://writepermission.com/org-blogging-clickable-headlines.html
(setq org-html-format-headline-function
(lambda (todo todo-type priority text tags info)
"Format a headline with a link to itself."
(let* ((headline (get-text-property 0 :parent text))
(id (or (org-element-property :CUSTOM_ID headline)
(ignore-errors (org-export-get-reference headline info))
(org-element-property :ID headline)))
(link (if id
(format "<a href=\"#%s\">%s</a>" id text)
text)))
(org-html-format-headline-default-function todo todo-type priority link tags info))))
#+end_src

*Warning:* The header cannot already be a link! Otherwise you get cyrptic and
unhelpful error =(wrong-type-argument plistp :section-number)=; which then
pollutes the current Emacs session resulting in stange =nil= errors after =C-x C-s=,
thereby forcing a full Emacs restart. Instead, you need at least one portion of
each heading to be not a link.

1. Need to have a custom id declared.
#+BEGIN_SRC org :tangle no
:PROPERTIES:
:CUSTOM_ID: my-header
:END:
#+END_SRC
2. Failing headers: =* [[link]]= nor =* ~code~= nor =* $math$=.
- Any non-link text /before/ it will work: =ok [[link]]=.
* Using Unicode non-breaking space ‘ ’ is ok.
- Text /only after/ the link is insufficient.
*** HTML “Folded Drawers”
*** HTML “Folded Drawers” :Move_to_org_special_block_extras:
:PROPERTIES:
:CUSTOM_ID: HTML-Folded-Drawers
:END:
Expand Down

0 comments on commit 49df883

Please sign in to comment.