xonsh/docs/rst_helpers.py
Noorhteen Raja NJ bceaafae4d
Add groups to env vars (#4026)
* feat: add grouped-settings for env variables

fixes #4014

style: fix mypy errors

chore: update testing requirements versions

fix: update xonsh.tools import error

* chore: add news item

* fix: update Var.with_default handling env defaults

* fix: set env var.doc_default=DefaultNotGiven

there is a custom handler for it

* chore: update travis

speedup docs generation

* chore: add command to serve docs during development

* docs: add jinja2 helpers/renderers extension for sphinx

* docs: update envvars document

* docs: fix docs failing

* Update xonsh/environ.py

commit suggestion

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* Update xonsh/environ.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* Update xonsh/environ.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* Update xonsh/environ.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* Update xonsh/environ.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* Update xonsh/environ.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

* refactor: update rst-extension

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
2021-01-04 12:21:44 -05:00

43 lines
1,007 B
Python

"""ReST-Jinja2 helpers"""
import re
def underline_title(title: str, level: int = -1):
symbols = "-.^"
if level < len(symbols):
under = symbols[level]
else:
under = symbols[-1]
return under * len(title)
def to_valid_id(name: str) -> str:
return re.sub(r"[^\w]", "_", name.lower()).strip("_")
def to_valid_name(name: str) -> str:
return name.replace("`", "")
def indent_depth(depth: int = None):
return " " * ((1 if depth else 0) * 4)
def to_ref_string(title: str, underline=False, depth=-1) -> str:
title = str(title)
ref = f":ref:`{to_valid_name(title)} <{to_valid_id(title)}>`"
if underline:
return "\n".join([ref, underline_title(ref, depth)])
return ref
def iterator_for_divmod(iterable, div: int = 3):
items = list(iterable)
size = len(items)
rem = size % div
complement = size + div - rem
for i in range(complement):
if i < size:
yield items[i]
else:
yield None