Skip to content

Commit

Permalink
tutorial on markdown extensions
Browse files Browse the repository at this point in the history
also, adding references to other content, to touched `conf.py`
  • Loading branch information
ofloveandhate committed Jul 24, 2024
1 parent 32c6673 commit 7aca334
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autodoc','sphinx.ext.autosectionlabel'
]

templates_path = ['_templates']
Expand All @@ -41,3 +41,7 @@
# test the path; not strictly needed
import markdown2canvas


rst_prolog = """
.. |markdowndefaults| replace:: :attr:`markdown2canvas.translation_functions.default_markdown_extensions`
"""
74 changes: 74 additions & 0 deletions docs/tutorials/markdown_python_extensions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@


Customize translation from Markdown to HTML via extensions to `markdown`
============================================================================


This library, `markdown2canvas`, essentially acts as a wrapper around a translation function `markdown2canvas.translation_functions.markdown2html`, or just `markdown2html` for short. The `markdown2html` function uses the Python library `markdown` (`link to library <https://python-markdown.github.io/>`_) to translate. You can customize the behaviour of this translation using "extensions" to the `markdown` library.


Background
------------

Before I tell you how to use your own custom set of extensions to `markdown`, here's a brief rundown of how `markdown2canvas` works when you publish a page or assignment to Canvas:

#. :doc:`The style is applied <styling_content>`.

#. The markdown header and footer from the used style are assembled around your `source.md`.
#. The html header and footer from the used style are assembled around that.

#. :doc:`Replacements are done <text_replacements>`.
#. Emoji shortcodes are emojified
#. The markdown is translated to HTML. THIS IS THE STEP YOU CAN CUSTOMIZE.
#. :doc:`Links to existing content are implemented <../making_links_to_existing_content>`, further modifying the HTML.
#. Local files and images which are linked-to in the source are uploaded (if necessary), and the HTML is adjusted to use the Canvas links to that content.
#. Content properties are set from `meta.json`.
#. The content is placed in modules as described in `meta.json`.

This tutorial is about customizing the first translation to HTML, by using `markdown` extensions.


Provided default `markdown` extensions
--------------------------------------------

This library provides a decent set of default extensions, chosen for

* Syntax highlighting of code
* Translating markdown tables
* Trying to make sure that markdown inside of HTML is translated, too

The specific default list is |markdowndefaults|.



Specifying your own list of extensions
-----------------------------------------

You may wish to use your own set of extensions. Easy! Just specify the list in your `defaults.json` file.

#. Edit `_course_metadata/defaults.json`.
#. Add a key-value pair.

* Key: `markdown_extensions`
* Value: A list of strings which are names of extensions.




Where to find more extensions
----------------------------------

I have found `the official `markdown` Extensions documentation <https://python-markdown.github.io/extensions/>` to be very helpful.

Cruise the list, find one that you need, and try it out by:

* Add it to the list of extensions you are using
* Publish the content to a test or sandbox course on Canvas
* Check it out! Did it do what you needed?


Limitations
---------------

ℹ️ Known limitation: This system is missing methods for you writing your own extensions to `markdown`. I do not know what happens if your list of extensions includes references to your own, but I suspect errors because they'll be strings, not Python modules, classes, or functions.

0 comments on commit 7aca334

Please sign in to comment.