require 'itex2MML' require 'thread' module Itex2MML class Error < RuntimeError; end class Parser def self.semaphore @semaphore ||= Mutex.new end def html_filter(string) parse(string, :itex2MML_html_filter) end def filter(string) parse(string, :itex2MML_filter) end private def parse(string, message) string = string.to_str self.class.semaphore.synchronize do raise Itex2MML::Error unless Itex2MML.send(message, string, string.length) == 0 Itex2MML.itex2MML_output end end end end