Skip to content
Myr

Merge pull request #1167 from LarsKollstedt/allow_indent_with_generic_char

Before adoption: this commit came in with the history the project adopted, so no landing records it.

indent filter can indent with arbitrary characters

authored by David Lord · committed by GitHub · parents 7bea919, 8016b5f · Browse files · 3 files+18 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−3 removed

  • tests:+4 added−0 removed
  • other:+14 added−3 removed

3 files+18 added−3 removed

modified:src/jinja2/filters.py+12 added-3 removed
746 unmodified lines
747748 return rv749750751def do_indent(s: str, width: int = 4, first: bool = False, blank: bool = False) -> str:751def do_indent(752 s: str, width: t.Union[int, str] = 4, first: bool = False, blank: bool = False753) -> str:754 """Return a copy of the string with each line indented by 4 spaces. The755 first line and blank lines are not indented by default.756755 :param width: Number of spaces to indent by.757 :param width: Number of spaces, or a string, to indent by.758 :param first: Don't skip indenting the first line.759 :param blank: Don't skip indenting empty lines.760761 .. versionchanged:: 3.0762 ``width`` can be a string.763764 .. versionchanged:: 2.10765 Blank lines are not indented by default.766767 Rename the ``indentfirst`` argument to ``first``.768 """769 if isinstance(width, str):770 indention = width771 else:764 indention = " " * width772 indention = " " * width773774 newline = "\n"775776 if isinstance(s, Markup):777 indention = Markup(indention)
832 unmodified lines
modified:tests/test_filters.py+4 added
183 unmodified lines
184 Tests cases where the filter input is a Markup type185 """186 self._test_indent_multiline_template(env, markup=True)187188 def test_indent_width_string(self, env):189 t = env.from_string("{{ 'jinja\nflask'|indent(width='>>> ', first=True) }}")190 assert t.render() == ">>> jinja\n>>> flask"191192 @pytest.mark.parametrize(193 ("value", "expect"),194 (195 ("42", "42"),
633 unmodified lines
modified:CHANGES.rst+2 added
46 unmodified lines
47 decorated with ``@environmentfunction``, ``@evalcontextfunction``,48 or ``@contextfunction``. :issue:`842`, :pr:`1248`49- Support ``pgettext`` and ``npgettext`` (message contexts) in i18n50 extension. :issue:`441`51- The ``|indent`` filter's ``width`` argument can be a string to52 indent by. :pr:`1167`535455Version 2.11.356--------------
780 unmodified lines