Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle notes, etc. with MD admonitions (replaces #410) #540

Merged
merged 31 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a9be11f
Add admonition.py.
Apr 8, 2022
f248ddb
Rename admonition.py to md_extensions.py.
Apr 8, 2022
1c217ae
Format md_extensions.py with black.
Apr 8, 2022
6a07eed
md_extensions.py: fix imports.
Apr 8, 2022
8488c19
Add preprocessor for admonitions.
Apr 10, 2022
7cc8b69
Modify admonition block processor to reproduce FORD admonitions.
Apr 10, 2022
3402f09
Small fix in AdmonitionProcessor.
Apr 10, 2022
db48552
Remove todo item in AdmonitionPreprocessor docstring.
Apr 10, 2022
bee5938
Add support for admonitions with text on the first line after the sta…
Apr 11, 2022
eeda054
Add/improve comments and docstrings of AdmonitionPreprocessor.
Apr 11, 2022
222249f
Change order of methods of AdmonitionPreprocessor.
Apr 11, 2022
cd33a2d
Refactor AdmonitionPreprocessor.
Apr 11, 2022
2222e89
Add support for admonitions with end marker embedded in line.
Apr 11, 2022
147483a
Add support for admonitions with text before start marker
Apr 12, 2022
2ec925e
Make sure that built-in admonition extension is deeregistered.
Apr 12, 2022
565f804
Add admonition extension to standard extensions included in FORD.
Apr 12, 2022
8587b98
[skip ci] Apply black changes
mbraakhekke Apr 12, 2022
0ef5bc6
Merge branch 'master' into markdown-extensions
ZedThree Jul 10, 2023
4807c5c
Rename admonition extension module
ZedThree Jul 10, 2023
6e1d44b
Small tidy-up of admonition extension
ZedThree Jul 10, 2023
23dc67a
Fix issue with indentation in admonition preprocessor
ZedThree Jul 10, 2023
145cd90
Remove `sub_notes`, replaced by admonition extension
ZedThree Jul 10, 2023
6691b4a
Update copyright notice in md_admonition
ZedThree Jul 10, 2023
dc167f9
Add test for uppercase notes
ZedThree Jul 10, 2023
a92593b
Fix support for @endnote in middle of line
ZedThree Jul 10, 2023
781426b
Support note titles through markdown admonition syntax
ZedThree Jul 10, 2023
c54ec14
Fix a bunch of linting and typing errors in admonition
ZedThree Jul 10, 2023
25a5542
Subclass original admonition processor with slight changes
ZedThree Jul 10, 2023
e98bd2b
Add some error handling to admonition extension
ZedThree Jul 11, 2023
1b8968e
Expand docs for note boxes
ZedThree Jul 11, 2023
569ec07
Docs: Add missing image
ZedThree Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/ford.md_admonition.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ford.md\_admonition module
==========================

.. automodule:: ford.md_admonition
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/api/ford.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Submodules
ford.fortran_project
ford.graphs
ford.intrinsics
ford.md_admonition
ford.md_environ
ford.md_striped_table
ford.output
Expand Down
Binary file added docs/user_guide/note_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 68 additions & 19 deletions docs/user_guide/writing_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,74 @@ back to number equations as you would in a LaTeX document. For more
details on that feature, see the `MathJax Documentation
<http://docs.mathjax.org/en/latest/input/tex/eqnumbers.html>`__.

Special Environments
--------------------

Much like in Doxygen, you can use a ``@note`` environment to place the
succeeding documentation into a special boxed paragraph. This syntax may
be used at any location in the documentation comment and it will include
as the note’s contents anything until the first use of ``@endnote``
(provided there are no new ``@note`` or other environments, described
below, started before then). If no such ``@endnote`` tag can be found
then the note’s contents will include until the end of the paragraph
where the environment was activated. Other environments which behave the
same way are ``@warning``, ``@todo``, and ``@bug``.

Note that these designations are case-insensitive (which, as Fortran
programmers, we’re all used to). If these environments are used within
the first paragraph of something’s documentation and you do not manually
specify a summary, then the environment will be included in the summary
of your documentation. If you do not want it included, just place the
environment in a new paragraph of its own.
.. _sec-note-boxes:

Notes and Warning Boxes
-----------------------

If you want to call particular attention to a piece of information,
you can use the ``@note`` markup to place it in a highlighted box:

.. code:: markdown

@note
You can include any notes (or bugs, warnings, or todos) like so.
@endnote

becomes:

.. figure:: note_box.png
:alt: An example of a @note box

An example of a ``@note`` box

This syntax may be used at almost any location in the documentation
comment and it will include as the note’s contents anything until the
first use of ``@endnote`` (provided there are no new ``@note`` or
other boxes, described below, started before then). If no such
``@endnote`` tag can be found then the note’s contents will include
until the end of the paragraph where the environment was activated.

There are some variations on ``@note`` boxes, which are coloured
differently:

- ``@note``
- ``@warning``
- ``@todo``
- ``@bug``
- ``@history``

You can give them a custom title by putting it in quotes immediately
after the tag:

.. code:: markdown

@note "Custom title"
Note text
@endnote

These boxes all use the CSS class ``alert``, as well as
``alert-<name>`` (for example, ``alert-note``), so you can customise
them if you wish. You can even add your own CSS classes, although you
must also give a title in that case:

.. code:: markdown

@note highlight blink "Title"
Note text
@endnote

Note that these tags are case-insensitive (which, as Fortran
programmers, we’re all used to). If a note is used within the first
paragraph of something’s documentation and you do not manually specify
a summary, then the note will be included in the summary of your
documentation. If you do not want it included, just place the note in
a new paragraph of its own.

Notes can include other markdown, such as lists or code blocks, and
can be used in other places such as lists -- although you need to be
careful about indentation in such cases.


“Include” Capabilities
----------------------
Expand Down
10 changes: 3 additions & 7 deletions ford/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,15 @@ def main(proj_data, proj_docs, md):
if proj_data["summary"] is not None:
proj_data["summary"] = md.convert(proj_data["summary"])
proj_data["summary"] = ford.utils.sub_links(
ford.utils.sub_macros(ford.utils.sub_notes(proj_data["summary"])), project
ford.utils.sub_macros(proj_data["summary"]), project
)
if proj_data["author_description"] is not None:
proj_data["author_description"] = md.convert(proj_data["author_description"])
proj_data["author_description"] = ford.utils.sub_links(
ford.utils.sub_macros(
ford.utils.sub_notes(proj_data["author_description"])
),
ford.utils.sub_macros(proj_data["author_description"]),
project,
)
proj_docs_ = ford.utils.sub_links(
ford.utils.sub_macros(ford.utils.sub_notes(proj_docs)), project
)
proj_docs_ = ford.utils.sub_links(ford.utils.sub_macros(proj_docs), project)
# Process any pages
if proj_data["page_dir"] is not None:
page_tree = get_page_tree(
Expand Down
2 changes: 2 additions & 0 deletions ford/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, List, Union, Optional

from ford.md_environ import EnvironExtension
from ford.md_admonition import AdmonitionExtension


class MetaMarkdown(Markdown):
Expand All @@ -20,6 +21,7 @@ def __init__(
"markdown.extensions.extra",
"mdx_math",
EnvironExtension(),
AdmonitionExtension(),
]
if extensions is None:
extensions = []
Expand Down
7 changes: 6 additions & 1 deletion ford/css/local.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ body {
margin-right: 5px;
margin-top: 5px;
}


.alert-title {
margin-top: 0;
color: inherit;
}

div.toc {
font-size: 14.73px;
padding-left: 0px;
Expand Down
Loading