grasp icon indicating copy to clipboard operation
grasp copied to clipboard

Allow escaping of '%' in templates

Open Chickensoupwithrice opened this issue 5 years ago • 2 comments

I'm using vim-zettel to manage my memex and would like to have notes start with '%title [%:description]'

I'm not sure if this breaks the org-mode spec, but having an escape key for % would be useful for my purposes. I know python but am still figuring out the code base currently, and RE is not my strong suit. Pointers on where to look to add escape characters to the RE parsing would be helpful. Line 66 in org_tools.py seems to be what I need to change?

Currently any text appended to '%' results in an error because it cannot find the variable.

Chickensoupwithrice avatar Sep 27 '20 12:09 Chickensoupwithrice

Hi, seems that org-mode spec suggests using \% for escaping https://orgmode.org/manual/Template-expansion.html#FOOT87 Would that suit you?

You're right, this line is responsible for template expansion https://github.com/karlicoss/grasp/blob/master/server/org_tools.py#L67 I haven't tried, but I think you'd need something like py_template = re.sub(r'[^\\]%[:]?([?\w]+)', r'{\1}', org_template), so it excludes the \% from matching.

karlicoss avatar Sep 30 '20 19:09 karlicoss

Yes, \% would suit me perfectly

Thanks for the regex, I will try changing the python and make a pull request if I'm successful :)

Chickensoupwithrice avatar Oct 03 '20 06:10 Chickensoupwithrice

I think this works now :)

Chickensoupwithrice avatar Jun 03 '23 04:06 Chickensoupwithrice