Code Monkey home page Code Monkey logo

markdown-to-moodle-xml's Introduction

Markdown to Moodle XML

What is this?

Tool to convert this:

# Test 1

* What is the color of the sky?
    - red
    - green
    - blue 
    - yellow

* Which ones are programmer's text editor?
    - sublime text 
    - vim 
    - atom 
    - microsoft word

# Test 2

* Who is the main protagonist in Dragon Ball?
    - Son Goku 
    - Picolo
    - Son Gohan
    - Vegeta

* Look at this code:
`` ```javascript
var a = 5
let b = 6
const c = 7
``  ```
Which one is immutable?
    - a
    - b
    - c 

* What is this?
    ![turtle](turtle.png)
    - A turtle 
    - A bird

* How do you spell $\alpha + \beta$?
    - a plus b
    - alpha plus beta
    - a fish and a funny flag

into this:

<?xml version="1.0" ?><quiz><question type="multichoice"><name><text>15f6bfae9c738eb5d5a625137c68f9d97217c9837bcef14f390b01f7</text></name><questiontext format="html"><text><![CDATA[What is the color of the sky?]]></text></questiontext><answer fraction="0"><text>red</text></answer><answer fraction="0"><text>green</text></answer><answer fraction="100.0"><text>blue</text></answer><answer fraction="0"><text>yellow</text></answer><shuffleanswers>1</shuffleanswers><single>true<answernumbering>abc</answernumbering></question><question type="multichoice"><name><text>1eb06c0febabb0ca206aa732e0bb607e50467a84209bf89b311afe3a</text></name><questiontext format="html"><text><![CDATA[Which ones are programmer's text editor?]]></text></questiontext><answer fraction="33.33"><text>sublime text</text></answer><answer fraction="33.33"><text>vim</text></answer><answer fraction="33.33"><text>atom</text></answer><answer fraction="0"><text>microsoft word</text></answer><shuffleanswers>1</shuffleanswers>false</single><answernumbering>abc</answernumbering></question></quiz>

and this:

<?xml version="1.0" ?><quiz><question type="multichoice"><name><text>85de507bd37c9dce0bac518e16fd8fa5b55cff8861fb49ec57f133cd</text></name><questiontext format="html"><text><![CDATA[Who is the main protagonist in Dragon Ball?]]></text></questiontext><answer fraction="100.0"><text>Son Goku</text></answer><answer fraction="0"><text>Picolo</text></answer><answer fraction="0"><text>Son Gohan</text></answer><answer fraction="0"><text>Vegeta</text></answer><shuffleanswers>1</shuffleanswers><single>true<answernumbering>abc</answernumbering></question><question type="multichoice"><name><text>6761a53fa753fbc447640804062afb329b98e9931e825ae0914255dd</text></name><questiontext format="html"><text><![CDATA[Look at this code:<pre>var a = 5
let b = 6
const c = 7
</pre>Which one is immutable?
]]></text></questiontext><answer fraction="0"><text>a</text></answer><answer fraction="0"><text>b</text></answer><answer fraction="100.0"><text>c</text></answer><shuffleanswers>1</shuffleanswers><single>true<answernumbering>abc</answernumbering></question></quiz>

Why?

  • Because writing quizes in markdown format is more pleasant than write it in ms-office, libre-office or GIFT format.
  • You can transform markdown file into pdf by using pandoc: pandoc -f markdown -o example.pdf example.md
  • Because our life is too short to copy-pasting the quizzes into moodle
  • Because sometimes macro doesn't work

How to use?

Simply cast: python m2m.py <your-md-file>

Can I try it?

Sure, cast this: python m2m.py example.md

New files will be created: example.md-Test 1.xml and example.md-Test 2.xml

Is there anything special with the markdown file?

Yes.

  • First, I treat # section as beginning of new section, because sometimes I write a quizes for different subjects in a single file.
  • Second, I treat * question as question. A question can contains multi-line string
  • Third, I treat - answer as wrong answer and - answer<space> as correct answer. The correct answer has extra space behind. An answer only contains single line
  • Any line preceeded by triple backtick will be converted to <pre> or </pre>
  • Any ![]() will be converted into <img src="data:image/png,base64,..."/>
  • Any $latex$ or $$latex$$ will be converted into \(\)

Prerequisites

  • Python
  • markdown python package (pip install markdown)
  • Human, non-muggle

Bonus: Web App

I also make a web app so you can write your markdown on the web and convert it into pdf, doc, and moodle xml at once.

Prerequisites

  • Flask pip install Flask
  • pypandoc pip install pypandoc

Run the server

python app.py

Access the page

You can access the web app by pointing your browser to http://localhost:5000

Run as a Docker Container

Additionally, you can run the Web App as a docker container:

docker run -d -p 5000:5000 --name markdown-to-moodle gofrendi/markdown-to-moodle

markdown-to-moodle-xml's People

Contributors

gofrendiasgard avatar agsedov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.