Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text/template: Allow func to take region as final argument #4727

Open
robfig opened this issue Jan 30, 2013 · 4 comments
Open

text/template: Allow func to take region as final argument #4727

robfig opened this issue Jan 30, 2013 · 4 comments
Labels
Milestone

Comments

@robfig
Copy link
Contributor

@robfig robfig commented Jan 30, 2013

I would like to extend Go templates to allow funcs to accept a region as an argument. 
This is useful any time you want to process or transform a section of text. 

For example, I would like to write a func that performs syntax highlighting
(server-side, while all existing solutions are in javascript):

{{/* A sample template */}}
...
A description of my ExampleFunc function and an example of its usage:
{{prettify "go"}}
func ExampleFunc() {
  ...
}
{{end}}

For that, I would like to use a template func with a signature like:

"prettify": func(lang, body string) template.HTML

The value of the parameter is the region, already executed.  This is necessary to allow
usage of template functionality within the region:

{{prettify "go"}}
  {{range .examples}}
    func Example1() {
      {{.}}
    }
  {{end}}
{{end}}

The func may be called using the current convention, e.g. {{prettify "go"
"func x()"}}, but the template system allows any func with a final argument of
type "string" to use the region form.
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jan 30, 2013

Comment 1:

Labels changed: added priority-later, removed priority-triage, go1.1.

Status changed to Thinking.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.