I am exporting from org mode format to LaTeX and HTML formats. To tweak a little plain text in those formats, I am using filter functions.
If I try to use such a form of a filter function:
(defun filter-function-html (text backend info)
"Docstring."
(when (org-export-derived-backend-p 'latex)
(regexp-function-1)
(regexp-function-2)
(regexp-function-3)
etc ...
))
the same for HTML format, then simply:
(add-to-list 'org-export-plain-text-functions
'my-latex-filter-function
'my-html-filter-function)
However, this is not working. Only way I could make it work is to define each regexp as separate function and added it separately each time with add-to-list
.
How can I improve readablity of these functions?
Specific example (lengthy):
(defun my-latex-filter-nobreaks (text backend info)
"Ensure \" \" are properly handled in LaTeX export."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string " \\([zuioaskvZUIOASKV]\\) " " \\1~" text)))
(defun my-latex-filter-highlightNotes-1 (text backend info)
"Highligh custom notes markup. Notes are surounded by \"%%\" or \"!!\" delimiters."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string "!!\\(.*\\)!!" "\\\\highLight[yellow]{\\1}" text)))
(defun my-latex-filter-highlightNotes-2 (text backend info)
"Highligh custom notes markup. Notes are surounded by \"%%\" or \"!!\" delimiters."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string "\\\\%\\\\%\\(.*\\)\\\\%\\\\%" "\\\\highLight[red]{\\1}" text)))
(defun my-html-filter-nobreaks (text backend info)
"Ensure \" \" are properly handled in LaTeX export."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string " \\([zuioaskvZUIOASKV]\\) " " \\1 " text)))
(defun my-html-filter-highlightNotes-1 (text backend info)
"Highligh custom notes markup. Notes are surounded by \"%%\" or \"!!\" delimiters."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "!!\\(.*\\)!!" "<span style=\"background-color:yellow\">\\1</span>" text)))
(defun my-html-filter-highlightNotes-2 (text backend info)
"Highligh custom notes markup. Notes are surounded by \"%%\" or \"!!\" delimiters."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string "%%\\(.*\\)%%" "<span style=\"background-color:red\">\\1</span>" text)))
(add-to-list 'org-export-filter-plain-text-functions
'my-latex-filter-nobreaks)
(add-to-list 'org-export-filter-plain-text-functions
'my-latex-filter-highlightNotes-1)
(add-to-list 'org-export-filter-plain-text-functions
'my-latex-filter-highlightNotes-2)
(add-to-list 'org-export-filter-plain-text-functions
'my-html-filter-nobreaks)
(add-to-list 'org-export-filter-plain-text-functions
'my-html-filter-highlightNotes-1)
(add-to-list 'org-export-filter-plain-text-functions
'my-html-filter-highlightNotes-2)
which I would like to shrink to:
(defun my-latex-filter-nobreaks (text backend info)
"Ensure \" \" are properly handled in LaTeX export."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string " \\([zuioaskvZUIOASKV]\\) " " \\1~" text)
(replace-regexp-in-string "!!\\(.*\\)!!" "\\\\highLight[yellow]{\\1}" text)
(replace-regexp-in-string "\\\\%\\\\%\\(.*\\)\\\\%\\\\%" "\\\\highLight[red]{\\1}" text)))
(defun my-html-filter-nobreaks (text backend info)
"Ensure \" \" are properly handled in LaTeX export."
(when (org-export-derived-backend-p backend 'html)
(replace-regexp-in-string " \\([zuioaskvZUIOASKV]\\) " " \\1 " text)
(replace-regexp-in-string "!!\\(.*\\)!!" "<span style=\"background-color:yellow\">\\1</span>" text)
(replace-regexp-in-string "%%\\(.*\\)%%" "<span style=\"background-color:red\">\\1</span>" text)))
(add-to-list 'org-export-filter-plain-text-functions
'my-latex-filter-nobreaks
'my-html-filter-nobreaks)
File for testing:
* Test for code readability improving
This is a test. A beginner here. !!Custom yellow markup.!! %%Custom red markup.%%