Skip to content

Instantly share code, notes, and snippets.

@yzhang2907
Last active August 11, 2024 19:14
Show Gist options
  • Select an option

  • Save yzhang2907/ca7bfb90ac28066ac08ae7e0b63d3257 to your computer and use it in GitHub Desktop.

Select an option

Save yzhang2907/ca7bfb90ac28066ac08ae7e0b63d3257 to your computer and use it in GitHub Desktop.

Pandoc: Convert From Markdown To Textile for Redmine

This document details how to convert Markdown documents to Textile documents for Redmine.

Steps

  1. Convert from markdown to textile using Pandoc:

     pandoc --from markdown --to textile --no-highlight FILENAME.md > FILENAME.textile
    
  2. (Optional) If you find the HTML codes that pop up in lieu of certain punctuations or special characters ugly, you can run a python script to unescape HTML character codes: python .\unescape_html_char_codes.py

    And then when prompted, enter exact filename of your textile file. Note that the existing textile file will be overwritten!

Unescape HTML Character Codes with Python

Save this snippet as unescape_html_char_codes.py if you want to use it for step 2 above.

import html

# Read in a file and unescape all HTML character codes.
def unescape_html_codes(filename):
    with open(filename, 'r', encoding='utf-16') as file:
        content = file.read()

    unescaped_content = html.unescape(content)

    with open(filename, 'w', encoding='utf-8') as output_file:
        output_file.write(unescaped_content)

if __name__ == "__main__":
    input_filename = input("Enter the filename: ")
    unescape_html_codes(input_filename)
    print("HTML character codes have been unescaped. Output saved to " + input_filename + "'.")

Notes

  • This does not work well with tables nested in bullet points or otherwise indented.
  • Redmine does not like the output for a code block, even though it is technically valid Textile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment