Using Markdown for Python#

Overview#

This beginner-level course introduces the basics of Markdown and how to integrate it with Python. Markdown is a markup language commonly used to format text in a simple and readable way, enabling users to create dynamic documents for reports and documentation. On this course, we will explore dynamic documents, understanding how they work and why they are useful. Through hands-on examples, students will learn how to create, save, and share interactive documents that combine text, code, and output.

This course will be taught using Jupyter Lab but participants are welcome to use any platform or tool they prefer besides Jupyter Lab.

Course Objectives#

  • Understand the benefits of dynamic documents—including how they streamline workflows, enhance reproducibility, and foster collaboration.

  • Navigate and use JupyterLab for creating interactive documents that integrate code and documentation seamlessly.

  • Apply basic Markdown syntax to format text, structure content, and create readable, well-organized documents.

  • Embed Python code within Markdown documents to generate dynamic outputs, such as plots, tables, and results.

  • Create a dynamic document that integrates Python code and Markdown to combine narrative, code, and output into a single cohesive document.

  • Export and save dynamic documents in various formats (e.g., HTML, PDF, Markdown) for sharing, publishing, or printing.

Pre-requisite Knowledge#

  • Prerequisite Course: Complete the “Introduction to Python” course.

  • Software and Requirements (optional): Install JupyterLab, ensuring Python and pip are set up on your system. Follow the installation instructions on the above-mentioned CfRR website.

  • Markdown in JupyterLab: No additional installation needed for basic Markdown support in JupyterLab.

Developers#

This material was developed by Ruxandra Neatu and Michelle Ledbetter as part of the Coding for Reproducible Research programme.

License Info#

from IPython.display import Markdown, display

def display_markdown(file_path):
    try:
        with open(file_path, 'r') as file:
            content = file.read()
            display(Markdown(content))
    except FileNotFoundError:
        print(f"The file {file_path} was not found.")
    except Exception as e:
        print(f"An error occurred: {e}")

# Example usage:
file_path = '../individual_modules/markdown_with_python/LICENSE.txt'  # Replace with your file path
display_markdown(file_path)

Instructional Material

The instructional material in this course is copyright © 2024 University of Exeter and is made available under the Creative Commons Attribution 4.0 International licence (https://creativecommons.org/licenses/by/4.0/). Instructional material consists of material that is contained within the “individual_modules/markdown_with_python” folders in this repository, with the exception of code snippets and example programs found in files within these folders. Such code snippets and example programs are considered software for the purposes of this licence.

Software

Except where otherwise noted, software provided in this repository is made available under the MIT licence (https://opensource.org/licenses/MIT).

Copyright © 2024 University of Exeter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The software in this repository is adapted from software that is covered by the following copyright and permission notice:

Copyright © 2024 Software Carpentry

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.