// Path: src/main/java/com/google/gwt/emul/java/io/Reader.java
// public abstract class Reader {
// 
//     public abstract void close() throws IOException;
// 
//     public abstract int read() throws IOException;
// 
//     public int read(char[] cbuf) throws IOException {
//         return read(cbuf, 0, cbuf.length);
//     }
// 
//     public abstract int read(char[] cbuf, int off, int len) throws IOException;
// }
// 
// Path: src/main/java/com/google/gwt/emul/java/io/StringReader.java
// public class StringReader extends Reader {
// 
//     /** The text to read. */
//     private final String text;
// 
//     /** The next position to read. */
//     private int position;
// 
//     /**
//      * Constructor.
//      * 
//      * @param text
//      *            The source text to read.
//      */
//     public StringReader(String text) {
//         this.text = text;
//         this.position = 0;
//     }
// 
//     /**
//      * Reads the next character in the source text.
//      * 
//      * @return The next character or -1 if end of text is reached.
//      */
//     public int read() throws IOException  {
//         return (this.position == this.text.length()) ? -1 : this.text
//                 .charAt(this.position++);
//     }
// 
//     @Override
//     public void close() throws IOException {
//     }
// 
//     @Override
//     public int read(char[] cbuf, int off, int len) throws IOException {
//         if (position >= text.length())
//             return -1;
//         int n = Math.min(text.length() - position, len);
//         text.getChars(position, position + n, cbuf, off);
//         position += n;
//         return n;
//     }
// 
// }


import java.io.StringReader;
import java.io.IOException;
import java.io.Reader;
/*
 * Copyright (C) 2011 René Jeschke <rene_jeschke@yahoo.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rjeschke.txtmark;

//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.InputStream;
//import java.io.InputStreamReader;

/**
 * Markdown processor class.
 * 
 * <p>
 * Example usage:
 * </p>
 * 
 * <pre>
 * <code>String result = Processor.process("This is ***TXTMARK***");
 * </code>
 * </pre>
 * 
 * @author René Jeschke <rene_jeschke@yahoo.de>
 */
public class Processor
{
    /** The reader. */
    private final Reader reader;
    /** The emitter. */
    private final Emitter emitter;
    /** The Configuration. */
    final Configuration config;
    /** Extension flag. */
    private boolean useExtensions = false;

    /**
     * Constructor.
     * 
     * @param reader
     *            The input reader.
     */
    protected Processor(final Reader reader, final Configuration config)
    {
        this.reader = reader;
        this.config = config;
        this.useExtensions = config.forceExtendedProfile;
        this.emitter = new Emitter(this.config);
    }

    /**
     * Transforms an input stream into HTML using the given Configuration.
     * 
     * @param reader
     *            The Reader to process.
     * @param configuration
     *            The Configuration.
     * @return The processed String.
     * @throws IOException
     *             if an IO error occurs
     * @since 0.7
     * @see Configuration
     */
    public final static String process(final Reader reader, final Configuration configuration) throws IOException
    {
        final Processor p = new Processor(reader, configuration);
        return p.process();
    }

    /**
     * Transforms an input String into HTML using the given Configuration.
     * 
     * @param input
     *            The String to process.
     * @param configuration
     *            The Configuration.
     * @return The processed String.
     * @since 0.7
     * @see Configuration
     */
    public final static String process(final String input, final Configuration configuration)
    {
        try
        {
// Path: src/main/java/com/google/gwt/emul/java/io/Reader.java
// public abstract class Reader {
// 
//     public abstract void close() throws IOException;
// 
//     public abstract int read() throws IOException;
// 
//     public int read(char[] cbuf) throws IOException {
//         return read(cbuf, 0, cbuf.length);
//     }
// 
//     public abstract int read(char[] cbuf, int off, int len) throws IOException;
// }
// 
// Path: src/main/java/com/google/gwt/emul/java/io/StringReader.java
// public class StringReader extends Reader {
// 
//     /** The text to read. */
//     private final String text;
// 
//     /** The next position to read. */
//     private int position;
// 
//     /**
//      * Constructor.
//      * 
//      * @param text
//      *            The source text to read.
//      */
//     public StringReader(String text) {
//         this.text = text;
//         this.position = 0;
//     }
// 
//     /**
//      * Reads the next character in the source text.
//      * 
//      * @return The next character or -1 if end of text is reached.
//      */
//     public int read() throws IOException  {
//         return (this.position == this.text.length()) ? -1 : this.text
//                 .charAt(this.position++);
//     }
// 
//     @Override
//     public void close() throws IOException {
//     }
// 
//     @Override
//     public int read(char[] cbuf, int off, int len) throws IOException {
//         if (position >= text.length())
//             return -1;
//         int n = Math.min(text.length() - position, len);
//         text.getChars(position, position + n, cbuf, off);
//         position += n;
//         return n;
//     }
// 
// }


// Path: src/main/java/com/github/rjeschke/txtmark/Processor.java
import java.io.StringReader;
import java.io.IOException;
import java.io.Reader;

/*
 * Copyright (C) 2011 René Jeschke <rene_jeschke@yahoo.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rjeschke.txtmark;

//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.InputStream;
//import java.io.InputStreamReader;

/**
 * Markdown processor class.
 * 
 * <p>
 * Example usage:
 * </p>
 * 
 * <pre>
 * <code>String result = Processor.process("This is ***TXTMARK***");
 * </code>
 * </pre>
 * 
 * @author René Jeschke <rene_jeschke@yahoo.de>
 */
public class Processor
{
    /** The reader. */
    private final Reader reader;
    /** The emitter. */
    private final Emitter emitter;
    /** The Configuration. */
    final Configuration config;
    /** Extension flag. */
    private boolean useExtensions = false;

    /**
     * Constructor.
     * 
     * @param reader
     *            The input reader.
     */
    protected Processor(final Reader reader, final Configuration config)
    {
        this.reader = reader;
        this.config = config;
        this.useExtensions = config.forceExtendedProfile;
        this.emitter = new Emitter(this.config);
    }

    /**
     * Transforms an input stream into HTML using the given Configuration.
     * 
     * @param reader
     *            The Reader to process.
     * @param configuration
     *            The Configuration.
     * @return The processed String.
     * @throws IOException
     *             if an IO error occurs
     * @since 0.7
     * @see Configuration
     */
    public final static String process(final Reader reader, final Configuration configuration) throws IOException
    {
        final Processor p = new Processor(reader, configuration);
        return p.process();
    }

    /**
     * Transforms an input String into HTML using the given Configuration.
     * 
     * @param input
     *            The String to process.
     * @param configuration
     *            The Configuration.
     * @return The processed String.
     * @since 0.7
     * @see Configuration
     */
    public final static String process(final String input, final Configuration configuration)
    {
        try
        {
            return process(new StringReader(input), configuration);