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

write markdown tables in RST file #129

Merged
merged 4 commits into from
Feb 18, 2021

Conversation

nathanesau
Copy link
Contributor

@nathanesau nathanesau commented Feb 7, 2021

tldr; We can now use markdown table syntax in RST file. Command for building docs is same as before (i.e. cmake -G \"Ninja Multi-Config\" -B build -DDOCS:STRING=YES && ninja -C build -f build-Release.ninja). This was achieved by modifying cmake docs command from ${SPHINX_EXECUTABLE} -b html to ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/preprocessor.py --input ${SPHINX_SOURCE} --output ${SPHINX_SOURCE}/__output__ && ${SPHINX_EXECUTABLE} -b html. Preprocessor may be useful for other custom RST syntax in future. Additional RST parsing can be added to docs/scripts/preprocessor.py in future.

Resolves #120.

Now, we can write tables in RST file using markdown syntax. This is pretty much as simple as it can get re. writing the tables. Supporting this requires additional step before the docs build, because markdown syntax isn't allowed in final RST file.

Verbs
=====
.. toctree::
.. contents::
   
*******
Monadic
*******

Tally
#####

.. doxygenfunction:: tally

******
Dyadic
******

******
Tables
******

Write markdown table in RST file.

| fruit | color | startswith |
| ----- | ----- | ---------- |
| apples | red | a |
| oranges | orange | o |

So, when building the docs, I added a preprocessor step (to existing CMAKE build docs command). The preprocessor scans all the RST files and creates parsed copy of each RST file in docs/source__out__. I have added that folder to .gitignore.

For above example, the parsed RST would be:

Verbs
=====
.. toctree::
.. contents::
   
*******
Monadic
*******

Tally
#####

.. doxygenfunction:: tally

******
Dyadic
******

******
Tables
******

Write markdown table in RST file.

======= ====== ==========
fruit   color  startswith
======= ====== ==========
apples  red    a         
oranges orange o         
======= ====== ==========

Notice that markdown table has been replaced with valid RST (type 2) table.

Then after building you will get a nice table.

Screenshot_2021-02-07_13-04-13

docs/scripts/preprocessor.py Outdated Show resolved Hide resolved
Copy link
Owner

@codereport codereport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, might refactor a couple things on next livestream

@codereport codereport added the ci / build This pertains to CI / build label Feb 18, 2021
@codereport codereport merged commit e9fa9a0 into codereport:main Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci / build This pertains to CI / build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Figure out how to get nicely & easily rendering tables in docs (.rst / Sphinx)
3 participants