Skip to content

Latest commit

 

History

History
416 lines (382 loc) · 78.4 KB

CHANGELOG.md

File metadata and controls

416 lines (382 loc) · 78.4 KB

Changelog

All notable changes to Miya Engine will be documented in this file.

The format is based on Keep a Changelog.

[Unreleased]

Added

  • {% block name required %} (and {% block name scoped required %}), as in Jinja2: a required block may hold only whitespace and comments, and rendering it fails with required block "name" not found unless another template in the chain also defines it. parser.BlockNode.Required holds the flag. See #42.
  • runtime.UsesInheritance(node), true when a template has an {% extends %} or, for a parsed template, uses super anywhere (a tree built in code is searched for a whole {{ super() }} only); it decides whether a template is rendered through the inheritance processor. parser.TemplateNode.MentionsSuper (with Parser.MentionsSuper()), set by the parser when super appears in the template, and parser.SuperNode.Bare, true for a super that is not called. See #38.
  • parser.CopyStatement, which copies one statement (and an if's elif branches) and shares its statement lists; parser.CloneStatement still copies the lists at every depth.

Changed

  • Breaking: a {% block %} without scoped sees only the template's top-level variables (render variables, globals and top-level {% set %}), as in Jinja2: the loop variable and loop of an enclosing {% for %}, {% with %} names, macro arguments and an outer block's {% set %} are no longer visible inside it. A scoped block sees them as before. The flag belongs to the block's position, so an override of a block in a parent's loop sees the loop variables only when the parent's block is scoped. To migrate, add scoped to the parent's {% block %} where its content (or an override) reads such a variable. parser.BlockNode.Scoped holds the flag. See #40.
  • The tree InheritanceProcessor.ResolveInheritance/ResolveInheritanceWith and SuperResolver.ProcessTemplateWithSuperCalls/ResolveSuperCalls return may be their input itself, or share statements and statement lists with it and with the parsed templates, where super() resolution changed nothing; a parent block rendered by several super() calls appears once, reachable from each call. Treat the tree as read-only, and do not walk it with a plain recursive walk, which visits a shared block once per call; at a super() cycle the tree also refers back to a block's content that contains it (#35). See #36.

Fixed

  • An inheritance chain of 12 or more templates in which each level calls super() renders, as in Jinja2, where it failed with super() call depth exceeded (possible infinite recursion). The error of a super() cycle that nothing stops now names the template and the line of the statement holding the super() that closes the cycle: super() in block "a" renders itself in template "c" at line N: .... See #37.

  • Breaking: a super() with no parent block fails when it is rendered, with there is no parent block called 'a' at line N, as in Jinja2, where it rendered nothing. This covers a block in a template without {% extends %} (rendered, or imported with {% import %}/{% from %}), a base block that calls super(), and a block only the child defines. Inside a block, a super() in a branch that is not taken still renders, and a bare super there is undefined, so the Jinja2 guard {% if super is defined %}{{ super() }}{% endif %} and super|default('') work; with strict undefined behaviour, evaluating that bare super other than in such a test fails with the same error. The line is that of the statement holding the call. In a template without {% extends %}, a super() anywhere in a block body (inside an expression such as {{ super()|upper }}, a {% with %}, {% call %}, {% filter %}, {% set %} or {% autoescape %} body, or a macro defined in the block) now gives the same error instead of super() call outside of block context. Remove or guard such super() calls before upgrading. See #38.

  • A super() cycle through nested blocks renders when a condition stops it, as in Jinja2: with base {% block a %}A{% if x is not defined %}{% block b %}B{% endblock %}{% endif %}{% endblock %} and a child whose b holds {% for x in [1] %}{% block a scoped %}a{{ super() }}{% endblock %}{% endfor %}, miya prints aAbaA where it failed with super() in block "a" renders itself. The cycle's super() renders the outer block's content when it is reached, so a guard on a loop variable or a namespace counter decides the depth. A cycle that nothing stops still fails with that message, now after 200 levels, and the error matches runtime.ErrMaxRecursion. Parent content holding such a cycle is built once instead of at every super() call, so its build no longer doubles per nesting level. See #35.

  • An {% extends %} inside {% if %} (or elif/else, nested ifs included) is run when its branch is taken, as in Jinja2, so {% if not standalone %}{% extends 'base.html' %}{% endif %} picks the parent per render; it was ignored and the template rendered without its parent. Blocks in the branches not taken still override the parent's. On import, the module's conditional or dynamic {% extends %} is followed with the module's context, so a missing parent fails the import. A template that extends twice, on render or import, fails with extended multiple times, and {% extends 1 %} fails on import as on render; both used to be accepted (render used the first parent). See #28.

  • A block override that calls super() more than once no longer doubles the merged template for every level of nested blocks: the parent block is built once and shared by its super() calls, so 24 nested blocks with two calls each build in under a millisecond instead of 13 seconds. A FromString child, which is rebuilt on every render, no longer copies every statement of the template when it calls super(). See #36.

[v0.3.0]

Added

  • parser.ForNode.LoopUnused, set by the parser when nothing in a {% for %} body can read loop (no loop name, and no block, include, import or extension tag); the evaluator then does not build loop. A ForNode built in Go leaves it false and gets loop as before. A Go function that takes the context and reads loop from it no longer finds the loop it is called in when the template never names loop.
  • miya.ErrRenderPanic, wrapped by the error Render, RenderTo and Environment.CallMacro return when they recover from a panic.
  • Environment.SetFilterParams(name, params...), Environment.AddFilterWithParams(name, fn, params...) and filters.Param declare a custom filter's parameter names so templates can pass them as keyword arguments. Keywords reach the filter as ordinary positional arguments; an unfilled earlier position receives its Param.Default, which is nil when unset. Also filters.KwArgs and runtime.KwargsFilterApplier.
  • runtime.InheritanceProcessor.ResolveInheritanceWith, which takes the evaluator for dynamic {% extends %}.
  • runtime.CompareNumbers, runtime.Equal, runtime.GroupTuple, filters.TestLookup and (*filters.FilterRegistry).SetTestLookup.
  • runtime.Markup, runtime.AsMarkup, runtime.Unmark, runtime.EscapeMarkup, runtime.KeepMarkupFunc and runtime.KwArgs (filters.KwArgs is now an alias of it). Go code that type-asserted filters.SafeValue on a |safe result should use runtime.AsMarkup.
  • String methods upper, lower, strip, lstrip, rstrip, split, replace, startswith, endswith, format, title, capitalize, join, count, find. str.format supports {0[key]}, {0.attr}, !r and !s. On a safe (Markup) string they return Markup and format, replace and join escape the arguments that are not safe.
  • d.get(key, default), and get/items/keys/values on string-to-string maps.
  • List methods index and count, plus append, extend and pop on lists stored with {% set %}, {% with %} or in a namespace() ({% do ns.items.append(x) %}). The mutating methods copy the list on the first write and never change the application's data. On any other list they fail with a hint to store it first ({% set items = items|list %}).
  • runtime.ErrTemplateNotFound and runtime.TemplateNotFoundError (with the missing template's Name), returned for templates the loader cannot find. A custom runtime.TemplateLoader that returns its own errors keeps the old rule (TemplateExists decides).
  • WithTruncateLeeway(n) environment option: the default leeway of truncate (Jinja2's truncate.leeway policy). Also filters.TruncateFilterWithLeeway, (*filters.FilterRegistry).Replace and runtime.RoundedFloat.
  • runtime.ErrOutputTooLarge and runtime.SizeError, wrapped by every size-limit error.
  • runtime.Unbox (turns the internal list box into a plain slice); runtime.ImportedNamespace.RawGet and, in the root package, Namespace.RawGet return the stored value without unboxing.
  • runtime.Number, runtime.BasicValue, runtime.SortedMapKeys, runtime.SortedMapPairs and runtime.UsesReflectLookup.
  • runtime: DictKey (the string a dict literal, subscript, in test or .get() uses for a key), Repr (Python's repr of a template value) with the ReprNamespace interface, Indirect (dereferences pointers to values), StringKeyMap (views a map with string keys as map[string]interface{}), BoxList, ModuleContexter (a context that can create an empty context sharing its environment, used by imports without context), EvalCompareNode and EvalDictNode.
  • parser: CompareNode, CompareOperand and NewCompareNode (chained comparisons such as a < b < c), DictNode and NewDictNode, DiscardNode and NewDiscardNode, MacroUsage (the special names a macro body references), and the tree helpers WalkStatements, ChildBodies, CloneStatement and CheckDuplicateBlocks (errors on duplicate block names, as Jinja2 does).
  • filters: (*FilterRegistry).RegisterWithParams, SetParams and ApplyKwargs register, declare the parameters of, and call a filter with keyword arguments; Environment.ApplyFilterKwargs does the same by name.
  • ReprData on *Namespace returns a copy of the namespace's data for runtime.Repr.
  • (*filters.FilterRegistry).IsBuiltin, (*branching.TestRegistry).IsBuiltin and TemplateContextAdapter.IsBuiltinFilter/IsBuiltinTest tell miya's own filters and tests from the ones added with AddFilter/AddTest.
  • miya.RenderPanicError, with the recovered panic Value and its Stack.
  • runtime.SprintV (fmt.Sprintf("%v", v) that prints a slice or map met again inside itself as [...]/map[...]) and runtime.FmtCycles (reports whether %v would recurse forever on a value).
  • runtime.MapLookup, used by the branching tests to read map keys the way the evaluator does, and the runtime.FilterLookup interface (HasFilter(name) bool), implemented by contexts that can tell whether a filter is registered.
  • TemplateContextAdapter.Child, TemplateContextAdapter.NewModuleContext, TemplateContextAdapter.HasFilter and runtime.ContextWrapper.Child: a child scope that reads through to its parent, an empty module context for imports without context, and a filter-existence check.
  • parser.IncludeNode.WithContext/WithoutContext ({% include … with context %} / without context) and parser.CallBlockNode.Parameters, Defaults and the embedded MacroUsage ({% call(a, b=1) m() %}).
  • runtime.InheritanceResolver and (*runtime.ImportSystem).SetInheritanceResolver: how an {% include %} resolves the included template's {% extends %}; the environment installs one, and an import system without one renders the included tree as it is.
  • loader.IsReadError(err): true for a permission or I/O error, which Environment.GetTemplate and ChainLoader's GetSource, GetSourceWithMetadata and LoadTemplate treat as an error rather than a missing template.

Fixed

  • InvalidateTemplate(name) also drops the cached chain (and merged template) of every template that extends name, directly or through a middle template; a child kept rendering the old parent until the cache TTL (15 minutes) or ClearCache.
  • super() in a block inside an extending template's top-level {% for %} or {% with %} (or in a grandchild's override of such a block) renders the parent block where the block runs and in the parent's slot; it failed with super() call outside of block context.
  • A {{ super() }} outside every block of an extending template or its parents (in a top-level macro, call block, set block or filter block) fails when it is evaluated, as in Jinja2 (UndefinedError: 'super' is undefined). In a parent template it rendered empty, so a template that relied on that now errors.
  • A block has its own variable scope, as in Jinja2: a {% set %} or macro inside a block is no longer visible after it or in later blocks, and super() renders the parent block in a scope of its own, so neither block sees the other's variables. Variables set outside the block and namespace() attributes are still shared. A template that set a variable inside a block to read it elsewhere (for example {% block title %}{% set page_title = 'X' %}{% endblock %} with the layout printing page_title) now gets an undefined value; set it at the child's top level or in a namespace().
  • super() renders the parent block with the child's overrides of the blocks nested inside it, as in Jinja2: a child that extends head with {{ super() }} and overrides title gets its own title. A super() inside such a nested block now renders that block's own parent. A super() cycle through nested blocks fails when it is rendered.
  • super() works inside an expression, as in Jinja2: {{ super()|upper }}, {{ super() ~ '!' }}, a macro argument, {% set p = super() %}, {% if super() %} and {% elif %}. The parent block renders each time such a super() is evaluated and not on a branch that is not taken. It used to fail with super() call outside of block context.
  • A block tag left open at the end of a template ({% if %} without {% endif %}, and so on) reports the line where the template ends; it said line 0, column 0.
  • {% import %} and {% from … import %} of a template that is missing or cannot be read name it once; the error said failed to load template "x" twice.
  • {% include %} of a template that is missing or cannot be read names it once; the error said included template "x" not found: failed to load template "x" or failed to load included template "x": failed to load template "x".
  • {% import %} and {% from … import %} of a template whose {% extends %} parent (or any template further up) is missing, fails to parse or extends itself now fail, as in Jinja2; the import succeeded and exported the child's macros. The parent's top-level code still does not run. A parent named by an expression is not loaded.
  • ChainLoader.LoadTemplate stops at a template that exists but cannot be read or does not compile, like GetSource; it used to return a later loader's copy.
  • enumerate(items, start=n) starts at n; it used to ignore start= and any start that was not a Go int (a negative literal, int64). A non-integer start, an unknown keyword or a third argument is an error.
  • An included template that extends another renders through its base, as in Jinja2: its blocks fill the base, super() works, and a missing parent is an error even with ignore missing. It used to render only its own blocks.
  • A template loaded by name whose {% extends %} names a fixed parent reuses its merged template across renders instead of rebuilding it each time (a two-level page with super() allocated 4.5× the same page written flat; now about the same). The merged template is cached with the template's hierarchy, per autoescape setting, and dropped with it by InvalidateTemplate of that template or of any template in its chain, ClearInheritanceCache, ClearCache and the cache TTL. FromString templates and a dynamic {% extends expr %} still rebuild on every render.
  • Macro calls, for … if filters and list and dict comprehensions no longer copy every variable in scope per call or per item; their cost no longer grows with the number of keys in the render data. A recursive loop() no longer formats its children into an unused string (which also called String() on Go values in them). Behaviour change: a macro defined inside another macro and called after the outer call returns (stored in a namespace, appended to a list, passed to caller()) now reads the enclosing scope's current values, as in Jinja2, instead of the values at the time the outer macro was called.
  • replace with a safe argument on a number or boolean, and map with safe arguments over number and list items, keep the safe text, as in Jinja2.
  • Typed Go maps with string keys look keys up the same way through [], in and .get() (none is "None"); range, lipsum, list +, batch, slice and format width/precision limit errors wrap ErrOutputTooLarge; wordwrap accepts a {% set %} block as its width again.
    • [], in and .get() on a map with interface keys (as YAML decoders produce) find a key that is the key itself, the same number in another numeric type (or bool 0/1), or its DictKey spelling (1.0 finds 1; 1 finds a "1" key; none finds a "None" key; a Markup key and a plain string find each other), without scanning the map. A lookup that misses no longer copies or sorts the map: 100 misses on a 20 001-entry map took 2.7 s.
    • Keys of other Go types in hand-built interface-key maps (int8, int32, uint, float32, named-string types and RoundedFloat) are found only by a key of the same Go type, no longer by value equality. A named-string lookup key also finds a Markup key. Pointer keys are never found, because the lookup key is dereferenced.
    • [], in, is in and .get() on any Go map look the key up without scanning or copying the map, and agree with each other:
      • a bool key is found by true/false or by 0/1;
      • an array key is found by a list whose items equal its elements;
      • any other key type (struct, pointer) is found only by a value of that type, compared with Go ==.
    • It used to be value equality, which changes three cases:
      • pointer fields in struct keys are now compared by address;
      • map[*int]V is no longer found by the number;
      • a number inside an array key with interface elements must have the same Go type.
    • On int64 and uint64 maps, a float at or beyond 2^63 (2^64 for uint64) no longer finds the largest keys. This matches Jinja2.
    • .get('5') on a 20 000-entry map[int]int took about 23 ms per call; .get() on any string-key typed map copied the map; '5' is in m on a typed map failed the render.
    • A []byte key now finds a typed string-key map's entry through .get() as well. On map[string]interface{} it still misses everywhere.
    • Pointer keys are dereferenced in [], in, .get() and dict literals ({p: 1} has the key '1', not an address).
    • An undefined key finds the "" entry of a string-key or interface-key map in [], .get() and in (Jinja2: not found).
  • Under autoescape, safe values stay safe through map with a filter ([s]|map('upper')), map(attribute=…, default=s), default(s), loop.cycle(s, …), join(d=s) and join(…, attribute=…), and through + with a Go named string type.
  • v|replace(old, new) with a safe old or new escapes v first, as Jinja2 does.
  • A safe value repeated with * stays safe under autoescape.
  • Undefined values print as Undefined inside lists and dicts, and make tojson fail as in Jinja2 instead of emitting miya's internal fields.
  • -7 is an integer.
  • The data strings inf, nan and infinity are not numbers in arithmetic or in numeric filters (w * 2 repeats them, w - 1 and w|abs are errors; w + 1 concatenates in lenient mode).
  • zipreport-go's own json filter swallows errors, so {{ {'a': nope}|json }} now prints null instead of miya's internal fields.
  • A none dict key prints None, and a rounded number finds its integer key.
  • RoundedFloat's Go fields are no longer template attributes.
  • {{ super() }} renders the parent block with the parent's autoescape setting.
  • map(filter) under autoescape runs the filter once per item; map('0') on list items reads the index again when autoescape is on; map('join', s) over a mix of lists and safe strings no longer errors with autoescape on (with autoescape off it and map('reverse') over such a mix still error; Jinja2 renders them). With autoescape on, [v, s]|map('reverse') works. For a list that mixes re-applied and other items, the other items' filter calls now run first, which can change the order of side effects and which error surfaces. A filter registered under a digit name such as "0" loses to the index on list items with autoescape on (Jinja2 calls the filter).
  • A macro (or caller()) can change a list passed to it, as in Jinja2: {% do l.append(x) %} inside the macro changes the caller's list. Lists passed from render data are copied, so application data is never changed.
  • Go functions that take a runtime.Context, and Namespace.Get/GetAttr/All() and ImportedNamespace.Get, see plain lists, never the internal box type. RawGet returns the raw value.
  • An attribute chain passed to a macro, a list method or a namespace lookup (m(l.pop().a.b)) is evaluated once.
  • An imported template now runs its whole top-level body, as Jinja2 does:
    • tuple and attribute {% set %}, {% do %} and for loops take effect;
    • only the taken {% if %} branch runs;
    • module macros can append to the module's lists;
    • names starting with _ (macros included) are not exported, and from ... import _x is an error.
  • Macros and {% set %} inside {% for %}, {% with %} and {% block %} bodies of a module are no longer exported, as in Jinja2.
  • Output the module prints is still discarded.
  • Filters now treat Go pointers, named types (type Status string, type Score float64, type Flag bool) and typed maps the way expressions already did:
    • map/sort/sum/groupby/selectattr/attr on lists of struct pointers used to give empty or zero results silently;
    • int/float/round/abs/sum on named numbers gave 0 or an error;
    • max/sort/unique failed on named strings;
    • dictsort/items/.keys() failed on maps with non-string keys, and the sequence filters wrapped a map as one item instead of using its keys;
    • dictsort(by='value') compared numbers as strings.
  • Undefined values are false in select/reject and in boolean filter arguments.
  • With autoescape on, %r and %a in a safe format string (<a title='%r'>) left the quotes raw, %c turned a number into a raw <, and a Go numeric or bool value with a String() or Format method skipped escaping as an argument of format, replace and join; a safe input given to wordwrap with a plain wrapstring spliced it raw between the attributes of a tag. All are escaped now.
  • truncate measured the HTML-escaped end when cutting, and escaped a safe end; it now measures the raw text and keeps a safe end, and an untruncated safe value stays safe. length and leeway accept a {% set n %}20{% endset %} number.
  • Typed Go maps, slices and arrays work in templates: m.key, m['key'], m[1], for k in m, for k, v in m, m.keys(), negative indexes, and the join, reverse, batch, items, keys, values and dictsort filters. Maps with string keys decoded from YAML (map[interface{}]interface{}) work too. Maps with non-string keys iterate in a fixed order (bools, numbers, then strings).
  • Maps with a named key type, unhashable keys in in or m[...], and struct fields reached through a nil embedded pointer no longer crash the render; a pointer that points to itself no longer hangs it.
  • Arithmetic (+ - * / **, unary -) works with every Go numeric type and named numeric types.
  • user.name finds the struct field Name, as documented.
  • Indexing, slicing, iterating, first and last on strings work on characters instead of UTF-8 bytes: {{ "açúcar"[1] }} prints ç, not Ã.
  • Slices with a negative step follow Python's bounds: {{ s[10::-1] }} no longer panics on a string or list shorter than 11, and s[:-10:-1] includes the first element.
  • Bad data and malformed templates return errors instead of panicking or crashing the process: nil in +, + on lists of different element types, nil functions (called or iterated), {% extends %} with a non-string (also in a parent template), mismatched -%}/-}}, negative truncate/truncatehtml length, huge center/pad_left/pad_right/indent/batch sizes, NaN and infinite currency, a crash in the trim-blocks pass, and templates nested more than 500 levels deep (previously a fatal stack overflow). Render, RenderTo and CallMacro recover any other panic as an error wrapping ErrRenderPanic.
  • Template.Release() no longer corrupts cached templates. A released FromString template used to render its raw source, a released GetTemplate template rendered nothing, and releasing a base template changed its children's output.
  • Dict literals keep their contents: {% set d = {'k': 'v'} %}{{ d.k }} prints v (it printed nothing, and every dict literal was empty). Each evaluation builds a new dict, so writes into one no longer carry over to the next render. Keys are stored as strings, as for every miya dict, so {1: 'a'}[1] and {1: 'a'}['1'] find the same entry, and a list key such as {[1, 2]: 'x'} is stored under "[1 2]" instead of raising an error as Jinja2 does.
  • With autoescape on, values that are not strings (named string types, errors, fmt.Stringers, lists, maps, structs) are escaped on output; a *runtime.SafeValue is treated as safe; {{ bytes }} prints a []byte as text (escaped) instead of [60 98 62]. urlize, urlizetruncate, nl2br and truncatehtml escape their input text. xmlattr output is no longer double-escaped. tojson escapes '. {% autoescape %} blocks keep their setting inside for loops and {% with %}. urlize(..., nofollow=true) no longer adds an extra nofollow to every link after the first.
  • Concurrent renders on one Environment that import templates no longer race or crash (concurrent map writes).
  • {% from x import name %} for a missing name gives an undefined value whose call fails with "does not export the requested name", not placeholder text.
  • Macros see their own file's top-level {% set %} variables, including block sets ({% set x %}...{% endset %}).
  • An imported template's own import/from statements run, so its macros can call the helpers it imports.
  • A self-import or mutual import fails with runtime.ErrMaxRecursion instead of returning a half-built module.
  • from ... import a as b works in templates that use {% extends %}.
  • with context / without context parse, including after a trailing comma in from ... import a, with context.
  • Filters honour keyword arguments, bound by name to Jinja2's parameters: sort(reverse=true), map(attribute="name", default="-"), sum(attribute="price", start=10), round(precision=1), join(d=", ", attribute="n"), int(base=16), truncate(length=…) and more. They used to be silently ignored.
  • trim(chars=none) strips whitespace, as in Jinja2.
  • Custom filters and tests, and keyword arguments to filters, work inside {% autoescape %} blocks. A custom filter or test used there failed with unknown filter / unknown test.
  • {% for … if … %}…{% else %} runs the else block when the filter leaves no items.
  • loop.depth counts recursion levels only (nested ordinary loops are each depth 1; recursive calls go 1, 2, 3…), and loop.depth0 exists.
  • Recursive loops apply their if filter at every level.
  • A for loop in a template without a parent that calls super() keeps its if filter and recursive flag.
  • The loop object is no longer reused across loops and renders (a stored loop showed another loop's values, and concurrent renders raced on it); AddGlobal, AddExtension and ConfigureInheritanceCache no longer race with renders; an extension is visible only after its OnLoad succeeds; inheritance-cache cleanup and loader statistics are race-free; NewTemplateCache with a negative size no longer panics; ConcurrentTemplateRenderer no longer panics on a second Stop, rejects RenderAsync before Start, and answers jobs pending at Stop.
  • Templates from miya's loaders (FileSystemLoader, EmbedLoader, StringLoader, ChainLoader, LRUFileSystemLoader) are compiled with the environment's settings: trim_blocks, lstrip_blocks, {{-/-}}, custom delimiters and extensions used to be ignored for them (they were, and still are, honoured for GetSource-only loaders).
  • Security: FileSystemLoader with followLinks false (the default) reads templates through os.Root, so no path or symlink can leave the search path. Before, only a symlink in the last path component was rejected, so linkdir/x.html could read files outside the template folder (on Windows a directory junction was not detected at all).
  • Template names are checked per segment, like Jinja2's split_template_path: a..b.html is a valid name, any .. segment is rejected (a/../b used to be accepted), and on POSIX a backslash is an ordinary character.
  • LoadTemplate on a loader without a parser returns an error instead of panicking.
  • FileSystemLoader.LoadTemplate re-parses a template whose file modification time changed. This affects direct LoadTemplate callers only: an Environment caches compiled templates itself and does not re-read files (use ClearCache/InvalidateTemplate).
  • Macro keyword arguments bind by name for local, imported and from-imported macros; defaults can use earlier parameters; varargs and kwargs work; a parameter without a default and not passed is undefined instead of an error.
  • Imported macros can call themselves and macros from their own file, and work in {% call %}.
  • {% call(args) macro() %} parses and passes arguments to the block; caller() is rendered on each call.
  • An {% autoescape %} block's setting applies inside macro and call-block bodies defined in it.
  • Runaway macro recursion reports the depth limit once instead of wrapping it at every level.
  • Data containing %} followed by blank lines no longer panics with trim_blocks.
  • {% elif %} branches of a base template were dropped when a child extended it.
  • Two FromString templates extending different parents rendered the first one's output.
  • ClearCache now also clears the inheritance cache, so changed parent templates are reloaded when the loader serves the new source. A loader's own cache (FileSystemLoader, EmbedLoader, LRUFileSystemLoader) is separate: call its ClearCache too.
  • Rendering a template that uses extends no longer formats the whole context on every render (9.8 ms → 8.5 µs with a 20 000-row context).
  • map("filtername", args...) applies the filter to each item, keyword arguments included.
  • groupby groups have .grouper and .list, the grouper keeps its type, and groupby(attr, default=...) works; map(attribute="grouper"), selectattr("grouper", ...) and sort(attribute="grouper") work on groups.
  • sort(attribute="a,b") sorts by several attributes.
  • The true and false tests exist (selectattr("paid", "true")); the in test compares numbers by value.
  • Collection filters accept strings, dicts (their keys, sorted) and typed Go slices.
  • The eq/equalto/ne tests compare like == (JSON 1 equals 1, lists element by element); the aliases ==, !=, <, <=, >, >=, lessthan, greaterthan exist.
  • {% filter %} blocks no longer write filter arguments unescaped ({% filter format(u) %}%s{% endfilter %}).
  • Breaking: in non-HTML escape contexts (ContextWrapper with JS, CSS, URL or JSON), only |safe/|marksafe results bypass the context escaper. nl2br, urlize, |e, tojson and the other HTML filters are escaped for the context; {{ d|tojson }} in a JS context, raw before, is now JS-escaped. Use |tojson|safe to emit JSON raw there.
  • An {% autoescape %} block inside a non-HTML ContextWrapper keeps that context's escaper.
  • In XML/XHTML contexts, concatenation, join and filter arguments escape with the XML escaper.
  • An imported template (also with context) escapes by its own setting, not the importer's {% autoescape %} block.
  • A recursive loop() result is safe or plain according to the context of the loop itself, not of the call site ({% autoescape true %}{{ loop(x.c) }}{% endautoescape %} in an autoescape-off loop escapes the inner output).
  • In non-HTML escape contexts, Markup items in a list returned by a filter ([u]|map('e')) are plain strings, so the context escaper runs on them.
  • joiner() keeps a safe separator (joiner('<br>'|safe)) instead of falling back to , .
  • Tests take one argument without parentheses (x is divisibleby 3); is in, is true, is false, is filter and is test work; a test registered as filter or test replaces the built-in meaning.
  • Keywords can be attribute names (d.if, d.block) and, except and/or/not/is/in/if/else, variable names in expressions and {% set %} (not yet for targets, macro parameters or keyword-argument names); identifiers may be non-ASCII (not NFKC-normalized); b.0 and L.0.1 index.
  • Number literals accept _, 0x/0o/0b and exponents (1e3); adjacent string literals join; (1, 2), (), set a, b = 1, 2, set (a, b) = ... and for v in 1, 2 parse; {{ a if b }} without else is undefined when b is false; [x for x in items if x > 5] (and the dict form) filter.
  • A comparison chain evaluates each operand once and stops at the first false comparison.
  • include accepts Jinja2's ignore missing before with context/without context; without context hides the render's variables.
  • Deeply nested not/- chains return template nesting too deep instead of crashing.
  • Long flat chains (1 + 1 + ..., a or b or ..., ~, **, x|f|f|..., a.b.b...) count towards the 500-level parse limit and return template nesting too deep instead of overflowing the stack when the template is rendered.
  • Printing a self-referencing list or dict prints [...] instead of crashing the process. Printing one container is capped at 64 MiB.
  • Strict mode: default, d, is defined, is undefined and is none accept undefined values; {{ a|default }} prints empty.
  • x['k'] is defined and x['k']|default(…) no longer fail when x is None or not subscriptable; the item counts as undefined, as in Jinja2.
  • include none ignore missing renders nothing.
  • is defined is true for a key whose value is None, and None is undefined is false.
  • An undefined value is an empty sequence for length, join, sum, sort, list, in, items and the other collection filters (by filter name, so a custom filter registered under one of these names also receives []); max/min/random of it are undefined; tojson of it is an error instead of internal fields.
  • include accepts a list of names and renders the first that exists.
  • {% with %} without assignments is accepted.
  • lower/upper tests follow Python ('' is lower is false, numbers are neither); true is number; a dict is a sequence.
  • int parses '3.7', ' 7 ', '1e3', '1_000' and base prefixes like Jinja2, and returns the default for floats outside the 64-bit range (they printed -9223372036854775808); an invalid base falls back like Jinja2 instead of erroring; float accepts surrounding whitespace and returns inf for '1e400'.
  • format_number returns an error for infinite or NaN values instead of printing +,Inf.
  • center defaults to 80 and pads like Python.
  • format_number and currency no longer put a separator after the minus sign (-123456|format_number printed -,123,456).
  • }}, %} and custom end delimiters no longer end a tag while a (, [ or { opened in it is still open, as in Jinja2: {{ {'a': {'b': 2}}.a.b }} renders 2, and a block end of } works with dict literals.
  • wordcount counts words like Jinja2 (\w+), so punctuation and hyphens separate words.
  • Errors from filter blocks and template inheritance keep their cause, so errors.Is finds ErrOutputTooLarge and other sentinels through them.
  • wordwrap on long words, hyphenated runs or long runs of spaces, and urlize on long runs of brackets or trailing punctuation, used to be quadratic: inputs of 200-400 KB took 5-22 s. Both are now linear, and their output is unchanged.
  • In non-HTML escape contexts, string methods on a safe value (.replace, .format, .join, .upper, …) return plain strings that the context escaper escapes, also inside {% autoescape false %}; they returned HTML-escaped Markup that was written raw. replace and the other markup-preserving filters on a safe value no longer escape their arguments twice there.
  • Runaway recursion through macro default arguments or includes reports the depth limit once instead of wrapping it at every level.
  • A list or dict that contains itself no longer crashes the process with a stack overflow when used as a dict key, compared with == or in, printed inside a struct, or passed to sort, unique, min, max, dictsort, pprint, is in, is lower or is upper, or used as a key on an undefined value.
  • Rendering one Context from several goroutines no longer races, and Context.All() reflects later writes to parent contexts.
  • GetTemplate no longer returns a FromString template for its internal cache name, and a FromString hash collision can no longer return another source's template.
  • for loops inside {% autoescape %} blocks or a ContextWrapper no longer copy every context variable on each iteration.
  • The replace, join and format filters enforce the 64 MiB result limit (errors wrap runtime.ErrOutputTooLarge), as the string methods already did. tojson(indent) is bounded by the same limit; a huge indent no longer panics, and an indent of 0 or less puts items on separate lines, as in Jinja2.
  • random picks a random item (or whole character) and accepts typed slices; it always returned the first item (or byte). An empty sequence gives undefined.
  • Filters and tests accept pointers to slices and maps, and typed maps: first, last, list, length, sort, unique, sum, xmlattr, is in, is sequence, is mapping and is iterable.
  • urlizetruncate no longer double-escapes safe input.
  • The JSON and CSS escape contexts write control characters as valid escapes (\u0001, \1 ); they wrote \u or \x followed by the raw character.
  • loop.changed compares values like ==, as in Jinja2: 1 and 1.0 (or true and 1, or a named Go string type and the plain string) are the same value.
  • A float literal beyond float64's range (1e400) is infinity, as in Python, instead of a compile error.
  • NewConcurrentTemplateRenderer with a worker count below 1 runs one worker; with 0 workers RenderAsync and Stop hung forever, and a negative count panicked.

Changed

  • ConcurrentTemplateRenderer.RenderAsync returns <-chan RenderResult with exported Output and Err; the old result type's fields could not be read outside the package.
  • Breaking: a {% block %} body and an {% include %}d template render with the environment's autoescape setting, as in Jinja2. An {% autoescape %} tag around the block or include no longer applies to it, in the template that defines it or in a child's override. Tags inside the block body or included template still apply. Move such a tag inside to keep the old output. A block inside a {% call %} body under {% autoescape false %} is now escaped twice, as in Jinja2. With autoescape off, an {% autoescape true %} tag around a block or include no longer escapes it.
  • Breaking: an error in an imported module's top-level code (for example an undefined attribute in {{ }}) now fails the import, where it used to be skipped.
  • Go functions that take a runtime.Context receive a wrapper that unboxes lists; reach the original context with interface{ Unwrap() runtime.Context }. Code that type-asserts the context to *miya.TemplateContextAdapter, *runtime.ContextWrapper or runtime.ContextAwareContext now gets ok == false.
  • Docs: a section on memory and untrusted templates.
  • Extension tags inside a macro that evaluate with CreateEvaluateFunc's raw context now see the internal box for list parameters (they saw a plain slice before); unbox with runtime.Unbox. Lists passed through the deprecated env.CallMacro path still cannot be appended to.
  • The list model is now documented: see "Lists" in docs/DO_STATEMENTS_IMPLEMENTATION.md.
  • time.Duration and other named integers are numbers in int, float, sum and round (a duration gives nanoseconds instead of 0).
  • %c in a safe format string ('%c'|safe|format(60)) is now an error, as in Jinja2; it used to turn a number from data into a raw <.
  • format, truncate and wordwrap receive their input and arguments unchanged under autoescape and mix safe and plain text themselves. Go callers of FormatFilter, TruncateFilter and WordwrapFilter that pass runtime.Markup get runtime.Markup back (truncate with a safe end escapes the plain text). Under autoescape off or outside the HTML family they are unchanged. A safe input with a plain wrapstring that is not whitespace (wordwrap(5, false, ' onerror=x ')) now gives a plain string, escaped when printed, as in Jinja2; a whitespace-only wrapstring such as '\n', or none, keeps the safe result (Jinja2 returns plain there). {% filter wordwrap(…, '<br>') %} now escapes its whole body (Jinja2 prints it raw).
  • Deliberate differences from Jinja2 here: %x, %o and %X format a number in a safe format string (markupsafe raises a TypeError); safe input with a safe wrapstring keeps the input's markup raw, so wrapping can split escaped entities and attribute values (it only matters with a safe wrapstring containing a quote but no >); %r of a safe argument prints the repr of its text, not Markup(...).
  • Breaking: urlize(trim_url_limit, nofollow, target, rel, extra_schemes) follows Jinja2. Links get rel="noopener", combined with rel and nofollow and sorted. Trailing punctuation stays outside the link, www. and e-mail addresses are linked, and URLs are not shortened unless trim_url_limit is given. The first argument used to be a boolean that trimmed at 40 characters.
  • Breaking: urlizetarget (miya-only) produces the same links: they get rel="noopener" and are no longer shortened to 40 characters.
  • Breaking: urlencode encodes strings with %20 and no longer encodes /, so it is not safe for building a single path segment: '../admin'|urlencode stays ../admin (it was ..%2Fadmin). Dicts and lists of pairs become query strings.
  • urlize HTML-escapes its target and rel values and omits an empty target.
  • title lowercases the rest of each word and capitalizes after - and brackets: 'ACME corp'|title is now Acme Corp. In a {% filter title %} block this applies to the markup too: <a href="/About-Us">read more</a> becomes <A Href="/about-Us">read More</a>, as in Jinja2.
  • striptags collapses whitespace to single spaces and removes comments.
  • Breaking: wordwrap(width, break_long_words, wrapstring, break_on_hyphens) follows Python's textwrap, as Jinja2 does. Long words are broken (pass break_long_words=false to keep them), words split after hyphens, runs of spaces inside a line are kept, and width defaults to 79. The second argument is break_long_words; it used to be break_on_hyphens.
  • Breaking: a nil pointer prints as empty, is false in {% if %}, is none, and is treated like none by default; it printed <nil> and was true. A non-nil pointer to a string, number, bool, slice or map behaves as the value it points to (it printed a memory address). Zero values of named bool, string and number types (type Flag bool) are false in {% if %} and in default(x, true), named bools and strings compare equal to plain ones, and named strings and numbers pass is string / is number.
  • Breaking: booleans are numbers in arithmetic and comparison, as in Python: true + 1 is 2 and true == 1 is true (both used to fail or be false).
  • Go methods are not callable from templates. The docs used to promise zero-argument method calls, which never worked; they now say so. Pass computed values as data, or register a global function.
  • Breaking: iterating a dict yields its keys, as in Jinja2: {% for k in d %} (and comprehensions, {% set a, b = d %}) used to yield the values. Use d.values() for values. {% for k, v in d %} still yields (key, value) pairs. Loops that unpack list-of-dict items into two variables ({% for a, b in list_of_dicts %}) now get each dict's two keys, as in Jinja2; use item.field instead.
  • Dicts are walked in sorted key order (for, .items(), .keys(), .values()), so output no longer changes between renders. The order is code-point order, as Python's sorted(): uppercase before lowercase, accented letters after z, and "10" before "9". This is a deliberate difference from Jinja2, which uses insertion order: Go maps have none.
  • dictsort is deterministic: keys (or values) that compare equal case-insensitively are ordered by code point, then by key. Jinja2 orders such ties by insertion order.
  • Breaking: range() over more than 1,000,000 items, lipsum() over 1000 paragraphs or sentences, list + producing more than 10,000,000 items, batch filling past 1,000,000 items, padding filters past 64 MiB and indent output past 64 MiB return an error; templates nested deeper than 500 levels fail to parse. A parent template whose {% extends %} is not a string literal is an error (it used to look up a template named <<DYNAMIC>>). These limits stop single huge allocations; they do not bound a render's memory or time.
  • Template.Release() now removes the template from the environment's template cache and leaves it usable. A later FromString/GetTemplate of the same source or name parses it again. The parser no longer pools AST nodes.
  • Breaking: a filter, global or data value that relied on a non-string type to bypass autoescape (for example Go's html/template.HTML) is now escaped; return runtime.SafeValue instead. filters.SafeValue is now an alias of runtime.SafeValue. xmlattr rejects attribute names containing whitespace, /, > or =. nl2br and urlize escape their input text even with autoescape off (filters cannot see the setting; urlize matches Jinja2). A truncated truncatehtml result is escaped text, including the end argument.
  • Breaking: and/or return one of their operands and skip the right side when the left decides, as in Jinja2: {{ name or 'default' }} prints the name, not true; {% if x != 0 and 10 / x %} no longer raises; templates that printed {{ a or b }} expecting true/false now print a value.
  • Breaking: imported templates run without the importer's context, as in Jinja2. {% import %} and {% from %} macros no longer see render variables or variables set before the import. Write {% import "x.html" as x with context %} (or from ... import ... with context) to keep the old visibility. Imports with context are built fresh each time, so a loop no longer reuses the first iteration's values.
  • Breaking: importing a template that does not exist, or one with a syntax error, is an error. Previously both rendered silently.
  • Breaking: a top-level {% set %} in an imported template that fails to evaluate (for example a strict-mode undefined variable) fails the render. Previously the variable silently held the text [Variable x from file].
  • Within one render, every import of a template without context shares one module, as in Jinja2 (an imported namespace() counter keeps counting across imports in a loop). Imports with context are built fresh each time. Unlike Jinja2, modules are never shared between renders. Importing a template that {% extends %} another runs only the child's top level: the parent's top-level macros and {% set %} are not exported, whereas Jinja2 exports them.
  • {{ x is defined }} is false when x holds an undefined value ({% set x = nope %}), as in Jinja2. In strict mode, printing a name that a {% from %} import did not find raises an error.
  • runtime.ImportSystem.LoadTemplateNamespace uses the context it is given as the module context, without cloning it, writes to it, and expects the loader to return an error for a missing template (TemplateExists is not consulted). An import on an evaluator that has no import system (for example one an extension creates with runtime.NewEvaluator()) is an error instead of binding placeholder macros.
  • Breaking: a keyword argument a filter cannot honour is an error instead of being ignored: an unknown name, or any keyword on a filter without declared parameters, including custom filters. Declare a custom filter's parameters with Environment.SetFilterParams or Environment.AddFilterWithParams; the error message says so.
  • Breaking: sum, min and max take positional arguments in Jinja2's order: sum(attribute, start) and min/max(case_sensitive, attribute). l|sum(10) used to mean start=10 and is now an error; write l|sum(start=10). l|max("n") used to mean attribute="n"; write l|max(attribute="n").
  • Breaking: a positional filter argument after a keyword argument (join(d="-", ",")) is a syntax error, as in Jinja2. A repeated keyword still binds the last value, as in Jinja2.
  • Breaking: // and % follow Python: they floor instead of truncating (-7 // 2 is -4, -7 % 3 is 2), keep float operands (7.5 % 2 is 1.5, 10 // 0.3 is 33), accept every Go numeric type, and reject strings ("10" // 3 used to be 3). With JSON data, where every number is a float, n // 2 is now a float, so (n // 2) is integer is false, as in Jinja2.
  • Breaking: each for-loop iteration starts from the scope outside the loop, as in Jinja2: a {% set %} in the loop body no longer carries over to the next iteration, and a recursive loop(...) call no longer sees the calling iteration's sets. Use namespace() to accumulate across iterations.
  • Breaking: assigning an attribute ({% set x.y = ... %}) works only on namespace() objects, and item assignment ({% set x[k] = ... %}) is an error, as in Jinja2; templates can no longer modify the caller's maps, slices, structs, or Go values that merely have Get/Set methods (embed runtime.NamespaceMarker to opt a type in). NewTemplateCache(0) disables the cache and a negative size means unbounded.
  • Breaking: Environment.GetTemplate reads every template through GetSource and compiles it itself; an AdvancedLoader's LoadTemplate is no longer used by the environment. Custom AdvancedLoaders must return the template text from GetSource for every name LoadTemplate accepts.
  • Breaking: a lexer configuration set on a loader's parser (loader.NewDirectTemplateParserWithConfig, SetLexerConfig) no longer affects rendering through an Environment. Set delimiters and whitespace options on the Environment instead.
  • Breaking: with followLinks false, a symlink inside the search path is followed only if it is relative and resolves inside the search path. An absolute symlink, or one that leaves the folder, is "template not found" (set SetFollowLinks(true) to follow every link, as before for directories). A relative symlinked file inside the folder is now accepted; it used to be rejected.
  • Breaking: in a ChainLoader, a template that exists in an earlier loader but does not compile is an error; it used to fall through to a later loader's copy.
  • LRUFileSystemLoader's size and TTL bound only its own LoadTemplate cache; they do not bound what an Environment caches.
  • Breaking: a macro body no longer sees the caller's local variables (loop variables, and {% set %} inside the calling macro or loop body). As in Jinja2, it sees its parameters and the scope where it was defined. Pass values as arguments. A {% set %} inside a {% block %} is still visible to macros called from that block, because miya blocks share the top-level context (unchanged).
  • Breaking: an unknown keyword argument, a keyword that repeats a positional argument, or more positional arguments than parameters is an error, unless the macro uses kwargs/varargs.
  • Breaking: a missing argument without a default is undefined, not an error.
  • Breaking: {% call %} on a macro that never calls caller() is an error.
  • Breaking: caller() inside a call block nested in a macro no longer reaches the outer macro's caller; it fails with no caller defined, as in Jinja2.
  • Breaking: {% call %} must be followed by a call ({% call w()|upper %} is a parse error, expected call), and a macro or call-block parameter named caller must have a default.
  • Breaking: a parameter named varargs or kwargs is an ordinary parameter and turns the catch-all off, as in Jinja2.
  • Breaking (Go): macros are *runtime.Macro values (Call(args, kwargs)), so Go code that type-asserted a macro to a func must use the new type. {{ m }} prints <Macro 'm'>. Each lookup of an imported macro returns a new value, so m.s is sameas m.s is now false.
  • Breaking (Go): a Go function used in {% call %} receives the caller differently. A func(...interface{}) gets a trailing map[string]interface{} holding caller; a func(Context, ...interface{}) no longer finds caller in its context.
  • Breaking: whitespace control is done by the lexer and matches Jinja2:
    • a comment on its own line no longer joins the lines around it, and inline comments keep the spaces around them;
    • -, trim_blocks and lstrip_blocks no longer act inside string literals, {% raw %} or data;
    • lstrip_blocks applies on the first line;
    • {%+, +%}, {#+ and +#} are supported;
    • \r\n and \r in templates become \n;
    • one trailing newline of the template is removed unless keep_trailing_newline is set (before, only when another whitespace option was on);
    • - markers now work in templates loaded through StringLoader or FileSystemLoader.
  • Breaking: {% raw %} content is output verbatim; it used to lose spaces, quotes and comments.
  • Breaking: Render no longer rewrites its output: whitespace inside <option> is kept, and data containing %} or {% keeps its blank lines and indentation. Render and RenderTo now produce the same output.
  • Breaking: the whitespace package is removed.
  • Breaking: CRLF and CR line endings in templates always become LF. There is no option to keep them (miya has no newline_sequence), so templates that must emit CRLF (MIME, CSV, ICS) need it produced from data or a filter.
  • Breaking: code that builds its own lexer.LexerConfig — loader.NewDirectTemplateParserWithConfig, DirectTemplateParser.SetLexerConfig, extensions.CreateTokensFromString — now gets that config's trim_blocks, lstrip_blocks and keep_trailing_newline applied (they were ignored), CRLF normalized, and the template's trailing newline removed unless the config sets KeepTrailingNewline. Templates rendered through an Environment use the environment's options instead.
  • {% raw +%} is rejected with an error, as in Jinja2.
  • Breaking: blocks inside if/elif/else, for, with, macro, filter, set blocks, call and autoescape can be overridden by a child template, and super() works there. A block nested inside a child's block override also overrides the parent's block of that name.
  • Breaking: a child template's top-level code runs before its parent's, as in Jinja2: its set, macro, import and if statements take effect, and text before {% extends %} is output. After {% extends %}, {{ }} and text are still not output (and not evaluated), but {% include %}, {% call %}, filter blocks and blocks inside for/with/autoescape now run and print before the parent's output; a missing include there is now an error.
  • Breaking: a root template's {% import %}/{% from %} is no longer moved to the top: a block that uses an import written after it fails, as in Jinja2. Move imports above the blocks that use them.
  • Breaking: two blocks with the same name in one template are an error (block 'a' defined twice), also when they sit in different if/else branches, as in Jinja2; such templates now fail to load.
  • Breaking: a dynamic {% extends expr %} follows the environment's undefined behaviour: in strict mode an undefined name in expr is an UndefinedError.
  • {% block name scoped %} is accepted.
  • Breaking: sort, min, max and groupby compare numbers numerically (true/false count as 1/0), strings case-insensitively (unless case_sensitive) and lists element by element, like Jinja2; comparing a number with a string is an error that names the attribute. [10, 9, 2]|sort used to give 10, 2, 9.
  • None (JSON null) and missing attributes never fail a sort: sort and groupby put them first, as one group (last with reverse), and min/max skip them. This deliberately differs from Jinja2, which raises TypeError.
  • Breaking: unique is case-insensitive by default and keeps 1 and "1" apart.
  • Breaking: min/max with attribute= return the item, not the attribute; on an empty list they return undefined (prints nothing) instead of failing.
  • Breaking: slice(n, fill_with) splits a list into n columns, as in Jinja2. It used to slice from index n.
  • Breaking: select, reject, selectattr and rejectattr apply the named test (select("odd"), selectattr("n", "gt", 1)); they used to ignore it. An unknown test name is an error.
  • Breaking: map("x") applies the filter x to items that have no attribute x (words|map("upper")). Items that have the attribute still map it (a miya extension; Jinja2 always applies the filter). With keyword arguments, map("round", precision=1) always applies the filter.
  • Breaking: attribute names are paths, as in Jinja2: attribute="c.name" looks up name inside c, and "0" indexes a list. A map key that itself contains a . is no longer found.
  • Breaking (Go API): SortFilter and UniqueFilter return []interface{} for []string input; GroupByFilter returns []interface{} of runtime.GroupTuple instead of [][]interface{}.
  • Breaking: under autoescape, the output of macros, caller(), recursive loop(), {% set %}...{% endset %} and {% filter %} blocks is safe Markup, as in Jinja2. It is no longer escaped a second time, so templates can drop |safe on macro calls (keeping it is harmless).
  • Breaking: |safe, |e/|escape, |forceescape, |urlize, |nl2br, |truncatehtml, |xmlattr, |tojson (and the other safe-producing filters) return runtime.Markup instead of filters.SafeValue or string. {{ "<"|e }} is no longer double-escaped.
  • Breaking: a {% filter %} block's result is escaped unless it is Markup. Jinja2 writes it raw. A custom filter that produces HTML for a filter block must return runtime.Markup or runtime.SafeValue.
  • Filters applied to a safe value escape their arguments where the result stays safe (replace, format, center, default, ...), as markupsafe does: {{ ('<b>%s</b>'|safe)|format(u) }} escapes u.
  • A macro's output is safe only if autoescape was on where the macro is defined. Jinja2 decides at the call site.
  • Go filters, tests and Go global functions receive a plain string for safe values; macros and the built-in namespace, dict, cycler and joiner keep receiving Markup.
  • A Go filter that returns runtime.SafeValue or *runtime.SafeValue still works; the value becomes Markup.
  • Breaking: operator precedence follows Jinja2: -2 ** 2 is 4, 2 ** 3 ** 2 is 64, -x|abs is (-x)|abs, and comparisons chain (a < b < c is a < b and b < c, so "apple" in fruits == true is false).
  • Breaking: ~ binds tighter than + and -: 'Page ' ~ n + 1 is ('Page ' ~ n) + 1, which prints Page 11 for n = 1 (it printed Page 2), and a + b ~ c is a + (b ~ c). Write 'Page ' ~ (n + 1).
  • Breaking: is applies to the operand right before it: x + 1 is divisibleby(3) is x + (1 is divisibleby(3)) and a == 1 is sameas(true) is a == (1 is sameas(true)). Write (x + 1) is divisibleby(3).
  • Breaking (extensions): ParserAdapter.ParseArguments uses the new expression grammar: adjacent string arguments join ({% tag "a" "b" %} gets one argument, "ab"), and keywords such as as are names.
  • To find affected templates: grep -nE '~[^}%]*[-+]|[-+][^}%]*~' -r templates/ (~ mixed with +/-) and grep -nE '[-+*/%<>=][^}%]* is ' -r templates/ (is after an operator).
  • Breaking: lists and dicts print like Python: ['a', 'b'], {'k': 1}, with True/False/None inside them (top-level true/false/empty are unchanged). Dicts print in sorted key order. Under autoescape the printed form is HTML-escaped, as in Jinja2.
  • Breaking: values with an Error() or String() method print through it inside lists and dicts too, and a []byte inside a list prints as a quoted string.
  • Breaking: * with a string literal repeats it, as in Python ('ab' * 3 is ababab; [1] * 2 repeats a list too), even when it looks like a number: '0' * 3 is 000 and '3' * 2 is 33 (it used to be 6). A numeric string from data still multiplies as a number.
  • d.items() returns a list of [key, value] pairs (in sorted key order), so |list, |length and printing work.
  • Breaking: {% include %} renders in a copy of the includer's context: {% set %} inside the included template no longer changes the includer.
  • Breaking: include … ignore missing ignores only a template that does not exist. An included template that fails to compile or to render, or that includes a missing template itself, is an error.
  • Breaking: {% with a = …, b = … %} evaluates every value in the scope outside the block, as Jinja2 does: b = a sees the outer a. The order used to be random.
  • Breaking: lt/le/gt/ge tests fail on None and on a string compared with a number; even/odd/divisibleby fail on strings and no longer truncate floats.
  • Breaking: in strict mode, o['missing'] and an out-of-range index are errors, and so is a.b is defined when a is undefined.
  • Breaking: truncate follows Jinja2. Strings up to 5 characters over the length are kept whole (leeway), so output can be up to length + 5 characters; pass leeway=0 where the text must fit, such as a table cell in a PDF, or set it for the whole environment with miya.WithTruncateLeeway(0). The end marker counts toward the length, the default length is 255, and a length shorter than the marker is an error. The word cut no longer stops at half the length: 'A Supercalifragilistic order'|truncate(16) is A....
  • Breaking: indent(width, first, blank): the third argument is Jinja2's blank (it used to be an indent string; pass a string as width instead), blank lines are not indented unless blank, and width defaults to 4.
  • Breaking: round with a precision returns a number instead of a string.
    • It prints exactly as before: 10|round(2) is 10.00, and rounding is half away from zero.
    • It now works in comparisons, arithmetic, is number and |int.
    • tojson emits 2.68, not "2.68".
    • Go code calling filters.RoundFilter gets a runtime.RoundedFloat; so do custom filters and global functions that receive a rounded value.
    • Templates that treated the result as a string change: x|round(2) == '0.00' is now false (compare with 0), x|round(2) < 'a' is an error, |length is an error, |first and |list no longer split it into characters, and is string/is iterable/is sequence turn false.
    • inf|round(2)|tojson is an error (JSON has no infinity; it was "+Inf").
    • round(0) (or no precision) of a value of 1e16 or more prints in exponent form, like any float (1e20|round prints 1e+20; it printed 100000000000000000000).
    • An unknown method is an error. A precision above 308, or one that overflows the value, returns it unchanged (it printed NaN or +Inf), and a value whose scaled form is beyond 2^53 is no longer distorted (1e20|round(3) printed 99999999999999983616.000).
  • filesizeformat prints kB and 1 Byte, truncates below 1 kB, and goes up to YB/YiB.
  • Unbalanced brackets are now reported by the lexer, with Jinja2's wording: {{ (1 }} gives lexer error in template ...: unexpected '}', expected ')' (was parser error ...: expected ')' after expression), and a stray closer such as {{ x) }} or the typo {{ x }<div> gives unexpected ')' / unexpected '}'. A bracket left open at the end of the template, or at an end delimiter that cannot close it (such as %>), is reported where it was opened: unexpected '%>', expected ')' (opened at line 2, column ...). Code that matches on the old error text needs updating.
  • Custom extension tags whose arguments contain unbalanced punctuation (for example :-)) now fail in the lexer. Jinja2 rejects them too.
  • Error columns on lines after the first are one higher than the actual column (an existing quirk, unchanged here); line numbers are exact.
  • Breaking: format uses Python % formatting instead of Go's fmt. '%d'|format(x) and '%i'|format(x) accept float operands such as JSON numbers, truncating them as Python does. %(name)s takes keyword arguments, and %r, %i, %u and %a work. Too few or too many arguments, %d of a string and a lone % are errors instead of printing %! text. Go-only verbs such as %v and %q are errors. miya differences: %x/%o/%X/%c and * accept whole floats, and %s prints None as empty and booleans as true/false.
  • A recovered render panic is a *RenderPanicError (still errors.Is(err, ErrRenderPanic)); the goroutine stack is in its Stack field instead of the error message. ConcurrentTemplateRenderer uses it too, and its panic message changed from "panic during template render".
  • Breaking: sum is an error for none and for items that are neither numbers nor numeric strings instead of skipping them (numeric strings still add, like miya's 1 + "2"; Jinja2 raises a TypeError); replace is an error for a count that is not a whole number (2.0 is accepted, 1.5 and "2" are not); first, last and list are errors for a value that is not iterable (list used to wrap it in a one-item list).
  • Breaking: integer arguments (widths, counts) outside Go's int range are errors instead of wrapping around, e.g. pad_left(1e19).
  • Breaking: the undefined result of random, first, last, min and max on an empty sequence follows the environment's undefined behavior, as Jinja2's environment.undefined does. With UndefinedStrict it is an error wherever an undefined variable would be: printed, in an operator, condition or loop, as a filter, function or macro argument, as a list or dict item, or assigned with {% set %} or {% with %}; only default/d (also later in a {% filter %} block's chain) and the defined, undefined and none tests accept it. The undefined items of map ([[]]|map('first')) follow the same behavior; with UndefinedStrict, join and sum fail on them. UndefinedDebug prints its placeholder. first and last of an empty sequence give undefined instead of none (([]|first) is defined and is none are false; [[]]|map('first')|list prints [Undefined]).
  • Breaking: with autoescape off in an HTML-family context, filters keep a safe input safe as markupsafe does (upper, lower, capitalize, trim, center, indent, reverse, last, string, default, format, truncate, escape, and map with them), and a safe result such as x|e stays safe, so a value {% set %} there is no longer escaped (again) when printed with autoescape on. center's fill is escaped, as markupsafe's Markup.center escapes it, and so is indent's string, where Jinja2 inserts it as it is (a deliberate difference); trim's characters are not, as in Jinja2. Whether autoescape is on or off, default on a safe input returns its argument as it is, as Jinja2's do_default does, instead of marking it safe or turning it into an escaped string: ""|safe|default(x, true) is escaped when printed, and ""|safe|default(items, true) is still a list. replace, title, wordwrap, join, urlize and xmlattr, and miya's nl2br, truncatehtml, urlizetruncate and urlizetarget, still return plain text with autoescape off, as Jinja2's do.
  • Breaking: in a non-HTML escape context (JS, CSS, URL or JSON through runtime.ContextWrapper), the output of a macro, caller(), a block {% set %}, loop() and a {% filter %} block is no longer escaped a second time when printed, and a filter block no longer escapes its literal text. That output stays escaped through ~ and + (a safe operand there is escaped for the context: Markup is HTML-safe only), safe, upper, lower, capitalize, center, indent and string, trim without arguments, the argument-less upper, lower, capitalize, strip, lstrip and rstrip methods (trim and the strips not in CSS, where they would drop the space that ends an escape), and as the input default returns; their arguments, safe ones included, are escaped for that context even with autoescape off. A case change leaves JS and JSON escape sequences such as \u003c intact. Other filters (title among them), indexing and slicing see its text as plain text, which is escaped again; in another escape context it is plain text too. Built-in filters and tests take it as it is inside lists and dicts, so [s]|first prints it escaped once. Go code (filters and tests added with AddFilter/AddTest, also through map, select and friends, functions and KeepMarkupFuncs, a function's context, runtime.Unbox, Namespace.Get) receives it as a plain string, also inside lists and dicts; Namespace.RawGet returns the value as stored, for the runtime. Lists and dicts are scanned for it only when Go code gets them in a render that made some, and by runtime.Unbox and Namespace.Get once any render made some; a scan that finds none allocates nothing.
  • Infinite and NaN floats print inf, -inf and nan as in Python (top-level output, ~, string, join, format, round). They printed Go's +Inf, -Inf and NaN outside lists. Go code calling runtime.FormatFloat, runtime.ToString or filters.ToString gets the new spelling too. Named Go float types (except inside lists), pprint and filesizeformat still print Go's spelling.
  • Breaking: two strings joined with + always concatenate, as in Jinja2: '5' + '1' is 51 (it was 6), '1e3' + '1' is 1e31, and numeric strings from data (a + b with a = "5", b = "1") concatenate too, as do |safe strings when autoescape is off. Convert first (a|int + b|int) to add them. A string and a number still add as numbers ('5' + 1 is 6), and -, * and / still treat two numeric strings as numbers ('5' - '1' is 4).
  • Docs: string + number coercion ('5' + 1 is 6, 'a' + 1 is a1) is listed as a deliberate difference from Jinja2.
  • Breaking: a template that exists but cannot be read (permission denied, an I/O error) is an error, as in Jinja2: Environment.GetTemplate no longer reports it as runtime.ErrTemplateNotFound (the error wraps the loader's error, so errors.Is(err, fs.ErrPermission) works), include … ignore missing no longer skips it, and ChainLoader.GetSource stops at it instead of trying the next loader. A custom loader must return (or wrap with %w) the underlying error for this to apply; any other loader error still counts as "not found".

Removed

  • Breaking: unused code that no render path reached: the inheritance package; runtime.OptimizedEvaluator, CachedEvaluator, BatchEvaluation, MemoryEfficientContext, FilterChainOptimizer, OptimizedFilterEvaluator, BatchFilterEvaluation, FilterPipeline and FastEvalNode; parser.FastEvaluator and the FastEval methods on parser.TextNode, LiteralNode, CommentNode and RawNode; the memory helpers in memory_optimization.go (MemoryOptimizedContext, StringInterner, ByteBufferPool, MemoryProfiler, MemoryEfficientTemplate, PrecomputedHash, SmallStringOptimizer, CachedEnvironmentOptions, DefaultCachedOptions, MemoryStats, GetMemoryStats and their globals); macros.MacroFunc, macros.MacroRegistry.Import and macros.MacroContext; and runtime.ContextHasher, InheritanceCache.GetResolvedTemplate and StoreResolvedTemplate (unused since template inheritance stopped caching per-context results). Rendering output is unchanged.
  • Breaking: runtime.ControlFlowEvaluator, runtime.NewControlFlowEvaluator, runtime.NestedLoopEvaluator, runtime.NewNestedLoopEvaluator and runtime.LoopInfo: a second loop and condition evaluator that no render path used, with semantics that differed from both Jinja2 and miya's evaluator (one loop object shared by every iteration, {% set %} carried across iterations). runtime.LoopControlError, NewBreakError and NewContinueError stay.

Deprecated

  • runtime.DictItems: nothing creates it since d.items() returns a list. It will be removed in a later minor release.
  • Environment.GetMacro, ListMacros, CallMacro and ClearMacros, and the macros package behind them. The registry mixes macros from every compiled template and binds arguments differently from template calls. They will be removed in a later minor release. To call a macro, render a template that imports it ({% from "lib.html" import m %}{{ m(x) }}), or walk Template.AST().
  • parser.ReleaseAST, parser.ReleaseNode, the parser.Release*Node functions, parser.GetNodePoolStats and parser.NodePoolStats do nothing.
  • filters.SelectFilter, RejectFilter, SelectAttrFilter and RejectAttrFilter: templates no longer use them (the registered filters apply tests); they keep their old value-comparing behaviour for direct Go callers.
  • filters.AutoEscapeFilter, registered as the autoescape filter: templates cannot call it (autoescape is a keyword) and Jinja2 has no such filter. Use escape (filters.EscapeFilter); Go callers of Environment.ApplyFilter("autoescape", ...) keep working for now.
  • InheritanceCache.SetResolvedTTL (does nothing), the resolvedTTL argument of Environment.ConfigureInheritanceCache (ignored), runtime.ResolvedTemplateCacheEntry and CacheStats.ResolvedCache (always zero).

[v0.2.0]

Changed

  • Breaking: the ==, !=, <, <=, >, >=, in operators compare numbers of any Go numeric type correctly. Previously a float64 (e.g. from JSON) compared wrongly against an int literal: 0 == 0.0 was false and (1 - 1) > 0 was true. Integers compare exactly. Comparing a string with a number using </> is now an error, as in Jinja2, and numeric strings compare as strings ("10" < "9").
  • Breaking: floats print like Jinja2 in output, ~ concatenation, and the string, join and e filters: no thousands separators, no rounding to two decimals, no scientific notation below 1e16. Whole floats still print without a decimal part. Use format_number or currency for formatted amounts.

Fixed

  • Includes, macro calls (including default arguments) and recursive loops nested more than 200 levels deep return runtime.ErrMaxRecursion instead of crashing the process with a stack overflow. ignore missing does not hide it.
  • Removed two test-only output rewrites: author links were stripped from templates named blog_post (or whose output contains blog-post), and empty imported macros returned debug text.

[v0.1.1]

Fixed

  • tojson filter now returns runtime.SafeValue instead of a plain string, preventing HTML auto-escaping of JSON output. This matches Jinja2's tojson behavior which returns Markup (a safe string). Previously, when auto-escaping was enabled, {{ data | tojson }} inside <script> blocks would produce HTML-escaped entities (e.g., " became &#34;), resulting in invalid JavaScript since browsers do not decode HTML entities in raw text elements like <script>.
  • Fixed data race in concurrent template rendering.

[v0.1.0] - Initial Release

Added

  • Template engine core: Lexer, parser, AST, and runtime evaluator pipeline.
  • Template inheritance: {% extends %}, {% block %}, {{ super() }} with multi-level support.
  • Control structures: {% if %} / {% elif %} / {% else %}, {% for %} with loop variable, {% set %}, {% with %}.
  • Expressions: Arithmetic, comparison, logical, membership (in/not in), string concatenation (~), ternary (a if cond else b), power (**), floor division (//).
  • 70+ built-in filters: String, numeric, collection, HTML/security, date, and encoding filters.
  • 26+ built-in tests: Type tests (number, string, mapping, etc.), value tests (defined, none, true, false), numeric tests (even, odd, divisibleby), container tests (iterable, sequence), and string tests (upper, lower).
  • Macros: {% macro %}, {% import %}, {% from ... import %} with default parameters.
  • Template includes: {% include %} with ignore missing support.
  • List and dictionary comprehensions: [expr for x in list], {k: v for x in list}, with filter and expression support.
  • Global functions: range(), dict(), cycler(), joiner(), namespace(), lipsum(), zip(), enumerate(), url_for().
  • Filter blocks: {% filter upper %}...{% endfilter %}.
  • Do statements: {% do expression %}.
  • Raw blocks: {% raw %}...{% endraw %}.
  • Autoescape control: {% autoescape %}...{% endautoescape %} with HTML auto-escaping enabled by default.
  • Whitespace control: {%-, -%}, {{-, -}} inline trimming, trimBlocks and lstripBlocks environment options.
  • Custom delimiters: Configurable variable, block, and comment delimiters.
  • Undefined variable behaviors: Silent (default), Strict, and Debug modes.
  • Template caching: Content-hash-based caching with sync.RWMutex protection.
  • AST node pooling: sync.Pool for frequently allocated node types to reduce GC pressure.
  • Evaluator pooling: Reusable evaluators via sync.Pool for concurrent rendering.
  • Inheritance caching: Configurable TTL-based cache for resolved template hierarchies.
  • Extension system: Custom tags and extensions via the extensions package.
  • Error system: Enhanced errors with source context, suggestions, stack traces, and 9 error type categories.
  • Template validation: Rule-based validator for common template mistakes.
  • Template debugging: Breakpoints, variable watching, and step mode.
  • Filesystem and memory loaders: Load templates from disk or in-memory maps.
  • Concurrent rendering: ConcurrentTemplateRenderer with worker pools and panic recovery.
  • Zero external dependencies: Built entirely on the Go standard library.