Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
robfig opened this issue Jan 30, 2013 · 6 comments
Closed

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

robfig opened this issue Jan 30, 2013 · 6 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. Thinking
Milestone

Comments

@robfig
Copy link
Contributor

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
Copy link
Contributor

rsc commented Jan 30, 2013

Comment 1:

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

Status changed to Thinking.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

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

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@AbdouTlili
Copy link

is it supported yet ?

@seankhliao
Copy link
Member

@seankhliao seankhliao added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Dec 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. Thinking
Projects
None yet
Development

No branches or pull requests

4 participants