mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
More information: https://groups.google.com/g/django-developers/c/tctDuKUGosc/ Refs: https://github.com/django/django/pull/14048
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
# Taken from https://github.com/django/django/blob/main/docs/_ext/djangodocs.py
|
|
|
|
import re
|
|
from sphinx import addnodes
|
|
|
|
|
|
# RE for option descriptions without a '--' prefix
|
|
simple_option_desc_re = re.compile(
|
|
r'([-_a-zA-Z0-9]+)(\s*.*?)(?=,\s+(?:/|-|--)|$)')
|
|
|
|
|
|
def setup(app):
|
|
app.add_crossref_type(
|
|
directivename="setting",
|
|
rolename="setting",
|
|
indextemplate="pair: %s; setting",
|
|
)
|
|
app.add_crossref_type(
|
|
directivename="templatetag",
|
|
rolename="ttag",
|
|
indextemplate="pair: %s; template tag"
|
|
)
|
|
app.add_crossref_type(
|
|
directivename="templatefilter",
|
|
rolename="tfilter",
|
|
indextemplate="pair: %s; template filter"
|
|
)
|
|
app.add_crossref_type(
|
|
directivename="fieldlookup",
|
|
rolename="lookup",
|
|
indextemplate="pair: %s; field lookup type",
|
|
)
|
|
app.add_description_unit(
|
|
directivename="django-admin",
|
|
rolename="djadmin",
|
|
indextemplate="pair: %s; django-admin command",
|
|
parse_node=parse_django_admin_node,
|
|
)
|
|
app.add_description_unit(
|
|
directivename="django-admin-option",
|
|
rolename="djadminopt",
|
|
indextemplate="pair: %s; django-admin command-line option",
|
|
parse_node=parse_django_adminopt_node,
|
|
)
|
|
|
|
|
|
def parse_django_admin_node(env, sig, signode):
|
|
command = sig.split(' ')[0]
|
|
env._django_curr_admin_command = command
|
|
title = "django-admin.py %s" % sig
|
|
signode += addnodes.desc_name(title, title)
|
|
return sig
|
|
|
|
|
|
def parse_django_adminopt_node(env, sig, signode):
|
|
"""A copy of sphinx.directives.CmdoptionDesc.parse_signature()"""
|
|
from sphinx.domains.std import option_desc_re
|
|
count = 0
|
|
firstname = ''
|
|
for m in option_desc_re.finditer(sig):
|
|
optname, args = m.groups()
|
|
if count:
|
|
signode += addnodes.desc_addname(', ', ', ')
|
|
signode += addnodes.desc_name(optname, optname)
|
|
signode += addnodes.desc_addname(args, args)
|
|
if not count:
|
|
firstname = optname
|
|
count += 1
|
|
if not count:
|
|
for m in simple_option_desc_re.finditer(sig):
|
|
optname, args = m.groups()
|
|
if count:
|
|
signode += addnodes.desc_addname(', ', ', ')
|
|
signode += addnodes.desc_name(optname, optname)
|
|
signode += addnodes.desc_addname(args, args)
|
|
if not count:
|
|
firstname = optname
|
|
count += 1
|
|
if not firstname:
|
|
raise ValueError
|
|
return firstname
|