Skip to content

Commit d2bc02e

Browse files
committed
0.3.5:
Added an option to read in the comments something like :something varname:`something else` and add it to the variable parameters like type, default, shape...
1 parent c66c85e commit d2bc02e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = 'sphinxfortran_ng'
3-
version = '0.3.4'
3+
version = '0.3.5'
44
authors = [{name = "Lorenzo Crippa", email="[email protected]"}]
55
description = "An improved version of the sphinx-fortran python module"
66
readme = "README.md"

src/sphinxfortran_ng/fortran_autodoc.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,10 @@ def format_var(self, block, indent=0, bullet=False):
13381338
"""
13391339
# Description of the variable
13401340
options = self.get_varopts(block)
1341+
try:
1342+
varname = str(block['name'])
1343+
except:
1344+
varname = None
13411345
try:
13421346
typeshape = ':Type: ' +options['type']
13431347
del options['type']
@@ -1348,16 +1352,28 @@ def format_var(self, block, indent=0, bullet=False):
13481352
del options['shape']
13491353
except:
13501354
typeshape += '\n\n'
1355+
thedescription = block.get('desc', None)
13511356
try:
13521357
attrs = re.split(r"default=", options['attrs'])
13531358
attrs[0] = re.sub(r",\s*", ", ",':Attributes: ' + attrs[0].strip(','))
13541359
if len(attrs) > 1:
13551360
attrs[1] = ':Default: ' + attrs[1].strip(',')
1361+
#Search for patterns in the description of the type :something $varname:`something else`
1362+
if varname is not None:
1363+
pattern = rf':([\w\s]+) {re.escape(varname)}:`([^`]+)`'
1364+
searchfordefault = block.get('desc', None)
1365+
match = re.search(pattern, searchfordefault, re.IGNORECASE)
1366+
if match:
1367+
keyword = match.group(1) # The word inside `: :`
1368+
extracted = match.group(2) or match.group(3) # Extract quoted text or single word
1369+
thematch = ':'+keyword+': '+ extracted
1370+
attrs.append(thematch)
1371+
thedescription = re.sub(pattern, '', searchfordefault, flags=re.IGNORECASE)
13561372
attrs = '\n'.join(line for line in attrs if line.strip()) + '\n\n'
13571373
del options['attrs']
13581374
except:
13591375
attrs = ''
1360-
description = block.get('desc', None) + '\n\n' + typeshape + attrs
1376+
description = thedescription + '\n\n' + typeshape + attrs
13611377

13621378
if 'name' in block:
13631379
declaration = self.format_declaration(

0 commit comments

Comments
 (0)