#!/usr/bin/ruby f = File.open(ARGV[0], "r") # separate by blocks so that I can leave them unformated block_separated = f.read.gsub("&", "&").gsub("<","<").gsub(">", ">") \ .gsub(/;;TABLE(;;.+;;)/, \ "```\n"+';;ASCII_TABLE\1'+"\n```").split /^```/ f.close outcome = "" # go through file for i in 0..block_separated.length-1 do part = block_separated[i] # format if not in block if i % 2 == 0 # headers part.gsub! /^### (.+)/, '

\1

' part.gsub! /^## (.+)/, '

\1

' part.gsub! /^# (.+)/, '

\1

' # bold part.gsub! /\*\*(.+?)\*\*/, '\1' # italic part.gsub! /\/\/(.+?)\/\//, '\1' # underscore part.gsub! /__(.+?)__/, '\1' # quote part.gsub! /`(.+?)`/, '\1' # link part.gsub! /\[(.+?)\]\((.+?)\)/, '\1' # img part.gsub! /\{(.+?)\}\((.+?)\)/, '' # lists part.gsub! /^\* (.+)/, '
  • \1
  • ' part.gsub! /(<\/li>\n)(?!
  • )/, '\1' + "\n" part.gsub! /^(?)(\n
  • )/, "\n" + '