Skip to content

Commit

Permalink
ReferenceStyle.type = 'custom' forces custom title
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtm committed Feb 24, 2021
1 parent 842517f commit 32fca18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Changed:

* docutils/Sphinx frontend: will default to referencing targets by number if
possible, even if a custom label is explicitly set. This behaviour can be
overridden in the style sheet (*custom_title* style property).
overridden in the style sheet by setting the *type* style property to
'custom'.

Fixed:

Expand Down
10 changes: 6 additions & 4 deletions src/rinoh/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


class ReferenceType(OptionSet):
values = 'reference', 'number', 'title', 'page'
values = 'reference', 'number', 'title', 'page', 'custom'


# examples for section "3.2 Some Title"
Expand All @@ -50,9 +50,6 @@ class ReferenceStyle(TextStyle, NumberStyle):
quiet = Attribute(Bool, False, 'If the given reference type does not exist'
'for the target, resolve to an empty string'
'instead of making a fuss about it')
custom_title = Attribute(Bool, False, 'Override the reference text '
'with a custom string supplied by'
'the frontend')


class ReferenceBase(MixedStyledTextBase):
Expand All @@ -63,6 +60,8 @@ def __init__(self, type=None, custom_title=None, style=None, parent=None,
super().__init__(style=style, parent=parent, source=source)
self.type = type
self.custom_title = custom_title
if custom_title:
custom_title.parent = self

def __str__(self):
result = "'{{{}}}'".format((self.type or 'none').upper())
Expand All @@ -87,6 +86,9 @@ def children(self, container, type=None):
if container is None:
return '$REF({})'.format(type)
target_id = self.target_id(document)
if type == ReferenceType.CUSTOM:
yield self.custom_title
return
try:
text = document.get_reference(target_id, type)
except KeyError:
Expand Down

0 comments on commit 32fca18

Please sign in to comment.