#!/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' # link part.gsub! /\[(.+?)\]\((.+?)\)/, '\1' # img part.gsub! /\{(.+?)\}\((.+?)\)/, '' # lists part.gsub! /^\* (.+)/, '
#{part}" end end print outcome.strip