Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ func (e *Engine) ParseTemplateAndCache(source []byte, path string, line int) (*T
func (e *Engine) SetAutoEscapeReplacer(replacer render.Replacer) {
e.cfg.SetAutoEscapeReplacer(replacer)
}

// RemoveTag removes the named tag definition from the engine's configuration.
// After calling RemoveTag the tag will no longer be recognized by subsequent
// parsing or rendering operations. The call is idempotent — removing a tag
// that is not registered is a no-op.
func (e *Engine) RemoveTag(name string) {
e.cfg.RemoveTag(name)
}
16 changes: 16 additions & 0 deletions engine_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,19 @@ func TestIssue63_UnicodeVariableNames(t *testing.T) {
require.Equal(t, "content", string(result))
})
}

func TestRemoveTag(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a test, this should go in engine_test.go. Or rename it to ExampleEngine_RemoveTag as a testable example.

engine := NewEngine()
engine.RegisterTag("echo", func(c render.Context) (string, error) {
return c.TagArgs(), nil
})
source := `{% echo hello world %}`

_, err := engine.ParseAndRenderString(source, emptyBindings)
require.NoError(t, err)

engine.RemoveTag("echo")

_, err = engine.ParseAndRenderString(source, emptyBindings)
require.Error(t, err)
}
Comment on lines +309 to +323
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test only verifies removing a custom tag (echo), but the PR description specifically mentions removing standard tags like {% include %} to get parse errors. Consider adding a test case that removes a standard tag to ensure this use case works as intended.

Example:

t.Run("RemoveStandardTag", func(t *testing.T) {
    engine := NewEngine()
    source := `{% if true %}test{% endif %}`
    
    _, err := engine.ParseAndRenderString(source, emptyBindings)
    require.NoError(t, err)
    
    engine.RemoveTag("if")
    
    _, err = engine.ParseAndRenderString(source, emptyBindings)
    require.Error(t, err)
})

Copilot uses AI. Check for mistakes.
5 changes: 5 additions & 0 deletions render/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ func (c *Config) FindTagDefinition(name string) (TagCompiler, bool) {
td, ok := c.tags[name]
return td, ok
}

// RemoveTag removes a tag definition.
func (c *Config) RemoveTag(name string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether this should be RemoveTag or UnregisterTag. The first reads better in isolation; the second has better symmetry with RegisterTag.

This is just a question for you, not a requirement for me to accept the PR. I'm okay with either. Don't do both though! This ends up making it harder to work with client code.

delete(c.tags, name)
}