Skip to content

Solved issue #2192 (Respect blank lines in capture templates)#2203

Merged
jethrokuan merged 5 commits intoorg-roam:mainfrom
alopezrivera:main
May 25, 2022
Merged

Solved issue #2192 (Respect blank lines in capture templates)#2203
jethrokuan merged 5 commits intoorg-roam:mainfrom
alopezrivera:main

Conversation

@alopezrivera
Copy link
Contributor

Issue: #2192

Motivation for this change

Unwanted removal of \n characters in Org Roam template strings.


org-capture-fill-template fills the template string, but it removes whitespace and newlines at the beginning and end of the template.*

org-roam-capture--fill-template removes all blank lines and restores them after calling org-capture-fill-template.

The regex formula used for this however (\n$) eliminates all blank lines in the template, whether or not they are at the beginning and end of the template.

By replacing it with [\n]*\\' only the blank lines at the end of the template will be removed -only the ones which will be later restored.

Example

With a default template as follows:

(setq org-roam-capture-templates
      '(("d" "default" plain "%?"
	    :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
			       "#+STARTUP: overview\n\n\n\n#+title:${title}\n\n\n")
	    :unnarrowed t)))

org-roam-capture--fill-template would previously output

"#+STARTUP: overview#+title:${title}\n\n\n"

while with the new formula it outputs (the user's input as would be expected)

"#+STARTUP: overview\n\n\n#+title:${title}\n\n\n"

*: paraphrased from the comment in org-roam-capture--fill-template

@jethrokuan
Copy link
Member

if you don't mind could you add a test case for your template so it doesn't regress

@alopezrivera
Copy link
Contributor Author

alopezrivera commented May 25, 2022

Just added the test case. Changed the CI workflow so it'll run on pushes to "main", as that's the default branch in my fork.

Edit: seems to be working fine! :)

@alopezrivera
Copy link
Contributor Author

Just reverted the CI trigger change (so runs are again triggered by pushes to "master")

@jethrokuan jethrokuan merged commit f144941 into org-roam:main May 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants