Skip to content

Commit 8e05e45

Browse files
authored
Merge pull request #645 from Fortran-FOSS-Programmers/submodule-links
Enable linking to submodules
2 parents bbba0b4 + aa3e624 commit 8e05e45

File tree

7 files changed

+83
-28
lines changed

7 files changed

+83
-28
lines changed

docs/api/ford._markdown.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ford._markdown module
2+
==========================
3+
4+
.. automodule:: ford._markdown
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/api/ford.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Submodules
1717
ford.fortran_project
1818
ford.graphs
1919
ford.intrinsics
20+
ford._markdown
2021
ford.md_admonition
2122
ford.md_environ
2223
ford.md_striped_table

docs/developers_guide/index.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ This is a very rough outline of how FORD works internally.
4949
#. After each file has been parsed, the lists of entities are added to
5050
the `Project`'s lists of all the entities in the whole project.
5151

52-
#. After all the files have been parsed, the documentation comments are
53-
converted from Markdown to HTML, recursively down from the source
54-
files. At this point, metadata in the comments is also parsed.
55-
5652
#. Entities defined in other files are now "correlated" with their
5753
concrete objects. This is done recursively from
5854
`Project.correlate`, first by finding which modules are ``use``\ d
5955
by each entity, and then looking up names in the corresponding
6056
`FortranModule`.
6157

62-
#. Another recursive pass is done of the project to convert internal
63-
`links <writing-links>` to actual HTML links using `sub_links`.
58+
#. After all the files have been parsed, the documentation comments
59+
are converted from Markdown to HTML, recursively down from the
60+
source files. At this point, metadata in the comments is also
61+
parsed. Several markdown extensions, `AliasPreprocessor`,
62+
`FordLinkProcessor`, `RelativeLinksTreeProcessor`, handle aliases,
63+
links, and absolute to relative link conversion respectively. The
64+
`MetaMarkdown` class just wraps constructing the markdown object.
6465

6566
#. The static pages are processed with `get_page_tree`.
6667

docs/user_guide/writing_documentation.rst

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ the source-code this way. This::
4545
!! The ammount of pet food (in kilograms) which you have on hand.
4646
integer, intent(out) :: angry
4747
!! The number of pets angry because they weren't fed.
48-
48+
4949
!...
5050
return
5151
end subroutine feed_pets
@@ -65,7 +65,7 @@ looks better/more readable than::
6565
real, intent(inout) :: food
6666
!! The number of pets angry because they weren't fed.
6767
integer, intent(out) :: angry
68-
68+
6969
!...
7070
return
7171
end subroutine feed_pets
@@ -280,35 +280,73 @@ this is ``[[component(type):item(type)]]``:
280280
as a type and its public constructor). If multiple items with the
281281
same name exist and ``type`` is not specified then FORD’s behaviour
282282
is undefined; it will link to the first of those items which it
283-
finds. The available options are “procedure”, “subroutine”,
284-
“function”, “proc” (all of which are interchangeable and specify a
285-
procedure), “interface”, “absinterface” (both of which are for
286-
abstract interfaces), “block” (for the legacy ``block data`` program
287-
unit), and “type”, “file”, “module”, and “program” (which are
288-
self-explanatory).
283+
finds. The available options are:
284+
285+
- "procedure", "proc", "subroutine", "function" for any kind of
286+
procedure defined within the project
287+
- "interface", "absinterface" for abstract interfaces
288+
- "block" for the legacy ``block data`` construct
289+
- "type"
290+
- "file"
291+
- "module"
292+
- "submodule"
293+
- "program"
294+
- "namelist"
295+
296+
The majority of these can also be prefixed with "ext" to refer to
297+
entities defined in `external projects <option-external>`
289298
- ``item`` (optional) specifies an item within ``component`` which is
290299
to be linked to. The link’s target will be ``item``\ ’s location on
291300
``component``\ ’s page. If ``item`` is not present then the colon in
292301
the link must be omitted.
293302
- ``type`` (optional, but ``item`` must also be present) is
294303
``item``\ ’s type of Fortran construct. It can be used in the same
295-
manner as the component ``type``, but has different options. These
296-
are “variable”, “type”, “constructor”, “interface”, “absinterface”
297-
(abstract interface), “subroutine”, “function”, “final” (finalization
298-
procedure), “bound” (type-bound procedure), “modproc” (module
299-
procedure in a generic interface block), and “common”. None of these
300-
options are interchangeable. If no description is given then its
301-
meaning should be self-explanatory. If you specify an option that can
302-
not exist within ``component`` (for example, if ``component`` is a
303-
module and ``item`` is “bound”) then a warning message is issued and
304-
the link is not generated.
304+
manner as the component ``type``, but has different options:
305+
306+
- "absinterface" for abstract interfaces
307+
- "bound" for type-bound procedures
308+
- "common" for ``common`` blocks
309+
- "constructor" for structure constructor procedures
310+
- "final" for finalization procedures
311+
- "function"
312+
- "interface"
313+
- "modproc" for module procedures in generic interfaces
314+
- "subroutine"
315+
- "type"
316+
- "variable"
317+
318+
None of these options are interchangeable. If you specify an option
319+
that can not exist within ``component`` (for example, if
320+
``component`` is a module and ``item`` is “bound”) then a warning
321+
message is issued and the link is not generated.
322+
323+
For example, to link to a module called ``my_mod`` you could
324+
use ``[[my_mod]]`` or ``[[my_mod(module)]]``, while if you wanted to
325+
refer to a function called ``my_function`` in that module you could
326+
use any of (from least to most specific):
327+
328+
- ``[[my_function]]``
329+
- ``[[my_function(function)]]``
330+
- ``[[my_function(proc)]]``
331+
- ``[[my_mod:my_function]]``
332+
- ``[[my_mod(module):my_function]]``
333+
- ``[[my_mod:my_function(function)]]``
334+
- ``[[my_mod(module):my_function(function)]]``
305335

306336
If you have an overridden constructor a derived type, then it is
307337
strongly recommended that you specify ``item`` should you wish to link
308338
to either of them. Otherwise FORD will not know whether you are
309339
referring to the derived type itself or the interface for its
310340
constructor.
311341

342+
.. versionchanged:: 7.0.0
343+
Previously, links inside code blocks (with backticks) were
344+
resolved, now they are left verbatim, as with all other
345+
markup. That is, pre-v7, ```call [[my_subroutine]]``` would be
346+
rendered as ``call my_subroutine`` with a link to
347+
``my_subroutine``, while now it will be left as: ``call
348+
[[my_subroutine]]``.
349+
312350
.. _non-fortran-source-files:
313351

314352
Non-Fortran Source Files

ford/_markdown.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def __init__(
5151
aliases: Optional[Dict[str, str]] = None,
5252
project: Optional[Project] = None,
5353
):
54-
"""make thing"""
5554

5655
default_extensions: List[Union[str, Extension]] = [
5756
"markdown_include.include",

ford/fortran_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
LINK_TYPES = {
6363
"module": "modules",
64+
"submodule": "submodules",
6465
"extmodule": "extModules",
6566
"type": "types",
6667
"exttype": "extTypes",

test/test_project.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def test_submodule_uses(copy_fortran_file):
10431043

10441044

10451045
def test_make_links(copy_fortran_file):
1046-
links = "[[a]] [[b(type)]] [[b:c]] [[a:d]] [[b:e]] [[F(proc)]] [[A:G]] [[H]]"
1046+
links = "[[a]] [[b(type)]] [[b:c]] [[a:d]] [[b:e]] [[F(proc)]] [[A:G]] [[H]] [[I]]"
10471047

10481048
data = f"""\
10491049
module a !! {links}
@@ -1073,6 +1073,9 @@ def test_make_links(copy_fortran_file):
10731073
10741074
program h !! {links}
10751075
end program h
1076+
1077+
submodule (a) i !! {links}
1078+
end submodule i
10761079
"""
10771080
settings = copy_fortran_file(data)
10781081
project = create_project(settings)
@@ -1088,6 +1091,7 @@ def test_make_links(copy_fortran_file):
10881091
"f": "../proc/f.html",
10891092
"g": "../module/a.html#variable-g",
10901093
"h": "../program/h.html",
1094+
"i": "../module/i.html",
10911095
}
10921096

10931097
for item in chain(
@@ -1106,7 +1110,7 @@ def test_make_links_with_entity_spec(copy_fortran_file):
11061110
links = (
11071111
"[[a(module)]] [[b(type)]] [[b(type):c(variable)]] "
11081112
"[[A(MODULE):D(SUBROUTINE)]] [[B(TYPE):E]] [[F(PROC)]] "
1109-
"[[A(module):G(variable)]] [[H(program)]]"
1113+
"[[A(module):G(variable)]] [[H(program)]] [[I(SUBMODULE)]]"
11101114
)
11111115

11121116
data = f"""\
@@ -1137,6 +1141,9 @@ def test_make_links_with_entity_spec(copy_fortran_file):
11371141
11381142
program h !! {links}
11391143
end program h
1144+
1145+
submodule (a) i !! {links}
1146+
end submodule i
11401147
"""
11411148
settings = copy_fortran_file(data)
11421149
project = create_project(settings)
@@ -1152,6 +1159,7 @@ def test_make_links_with_entity_spec(copy_fortran_file):
11521159
"f": "../proc/f.html",
11531160
"g": "../module/a.html#variable-g",
11541161
"h": "../program/h.html",
1162+
"i": "../module/i.html",
11551163
}
11561164

11571165
for item in chain(
@@ -1166,7 +1174,7 @@ def test_make_links_with_entity_spec(copy_fortran_file):
11661174
assert link_locations == expected_links, (item, item.name)
11671175

11681176

1169-
def test_link_with_context(copy_fortran_file):
1177+
def test_make_links_with_context(copy_fortran_file):
11701178
data = """\
11711179
module a !! [[g]]
11721180
type b !! [[c]] [[e]] [[g]]

0 commit comments

Comments
 (0)