/**
   * Converts the parsed source code to HTML by adding color information, adding line breaks and
   * replacing characters as needed for HTML. Also adds a table with line numbers etc.
   */
  public void convert(JavaSource source, JavaSourceConversionOptions options, BufferedWriter writer)
      throws IOException {
    if (source == null) {
      throw new IllegalStateException(
          "Trying to write out converted code without having source set.");
    }

    writer.write(BLOCK_HEADER);

    // 1) Header with filename if available
    if (options.isShowFileName() && source.getFileName() != null) {
      // TODO: Pretty print file name
    }

    writer.write("{");
    writer.newLine();
    writer.write("\\noindent \\ttfamily");
    writer.newLine();

    int lineCount = source.getLineCount();
    int lineNumber = 1;
    JavaSourceIterator iterator = source.getIterator();
    while (iterator.hasNext()) {
      JavaSourceRun run = iterator.getNext();
      if (run.isAtStartOfLine() && options.isShowLineNumbers()) {
        writeLineNumber(writer, lineNumber++, lineCount);
      }
      toTeX(run, writer);
      if (run.isAtEndOfLine()) {
        writer.write("\\\\");
        writer.newLine();
      }
    }

    writer.newLine();
    writer.write("}");
    writer.newLine();
  }