private void exportToHTML() {
        // Prompt save dialog
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);

        chooser.addChoosableFileFilter(new ExtensionFileFilter(
                new String[]{".html"}, // Extensions we accept
                "HTML files (*.html)"));
        // Catch action of the File Chooser Dialog Window
        int option = chooser.showSaveDialog(this);

        // User pressed save
        if (option == JFileChooser.APPROVE_OPTION) {

            // Initialize output stream
            BufferedOutputStream out = null;

            try {
                // Create kit to export
                HTMLEditorKit kit = new HTMLEditorKit();

                // Get path
                String filePath = chooser.getSelectedFile().getAbsolutePath();

                // Add ".html  at the end of the string (only if it doesn't exist)
                if (!filePath.endsWith(".html")) {
                    filePath += ".html";
                }

                // Check if the html file already exists
                File HTMLFile = new File(filePath);
                if (!HTMLFile.isFile()) {
                    out = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
                } else {
                    // Confirm the save
                    int confirmoption = JOptionPane.showConfirmDialog(null,
                            "There is already a file with the same name in the selected folder. \n "
                            + "Do you want to overwrite this file?",
                            "File already exists",
                            JOptionPane.YES_NO_CANCEL_OPTION);
                    if (confirmoption == JOptionPane.YES_OPTION) {
                        File deletedFile = new File(filePath);
                        deletedFile.delete();
                        out = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
                    } else {
                        exportToHTML();
                        return;
                    }
                }
                // Get style document
                StyledDocument doc = this.textPane.getStyledDocument();
                String unescapedText = doc.getText(0, doc.getLength());
                doc.remove(0, doc.getLength());
                doc.insertString(0, escapeHTML(unescapedText), this.currentDocumentStyle);

                // Export
                kit.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());
                out.close();

                // Get filename and extension
                Filename fn = new Filename(filePath);
                String fileName = fn.filename();
                String extension = fn.extension().toLowerCase();

                // Get absolute path to the file (so path without filename and extension)
                String abspath = filePath.substring(0, filePath.length() - fileName.length() - extension.length() - 1);

                // Close this screen
                this.parent.setVisible(true);
                this.dispose();

                // Return parameters for creating Text Item
                this.parent.addTextMediaItemToList(fileName + "." + extension, abspath);

            } catch (IOException ex) {
                Logger.getLogger(CreateText.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadLocationException ex) {
                Logger.getLogger(CreateText.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }