Skip to content

Commit

Permalink
Add flag_present conversion function for boolean directive options
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler miller authored and Arth-ur committed Mar 16, 2024
1 parent 33e7299 commit e1bf480
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sphinxcontrib/bitfield.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from docutils.parsers.rst.directives import flag
from bit_field import render, jsonml_stringify
from json import loads
from shlex import split
Expand All @@ -14,6 +13,14 @@ def legend(s):
return {k: v for k, v in zip(x[0::2], x[1::2])}


def flag_present(argument):
"""Set option value = True if option was set by user"""
if argument and argument.strip():
raise ValueError('no argument is allowed; "%s" supplied' % argument)
else:
return True


def figure_wrapper(directive, children, caption) -> nodes.figure:
# based on the figure_wrapper method in sphinx.ext.graphviz
# https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/graphviz.py
Expand All @@ -38,10 +45,10 @@ class BitfieldDirective(Directive):
'fontfamily': str,
'fontweight': str,
'strokewidth': float,
'compact': flag,
'hflip': flag,
'vflip': flag,
'uneven': flag,
'compact': flag_present,
'hflip': flag_present,
'vflip': flag_present,
'uneven': flag_present,
'trim': float,
'legend': legend,
'caption': directives.unchanged,
Expand Down

0 comments on commit e1bf480

Please sign in to comment.