Update documentation related to scope autocompletion
[geany-mirror.git] / plugins / export.c
blob1d5e813a12b89623ebff695e7d6209b6d0cfd4e6
1 /*
2 * export.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* Export plugin. */
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <ctype.h>
28 #include <math.h>
30 #include "geanyplugin.h"
33 GeanyData *geany_data;
35 PLUGIN_VERSION_CHECK(GEANY_API_VERSION)
36 PLUGIN_SET_INFO(_("Export"), _("Exports the current file into different formats."),
37 PACKAGE_VERSION, _("The Geany developer team"))
40 static GtkWidget *main_menu_item = NULL;
43 #define ROTATE_RGB(color) \
44 (((color) & 0xFF0000) >> 16) + ((color) & 0x00FF00) + (((color) & 0x0000FF) << 16)
45 #define TEMPLATE_HTML "\
46 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
47 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
48 <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
49 \n\
50 <head>\n\
51 <title>{export_filename}</title>\n\
52 <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n\
53 <meta name=\"generator\" content=\"Geany " PACKAGE_VERSION "\" />\n\
54 <meta name=\"date\" content=\"{export_date}\" />\n\
55 <style type=\"text/css\">\n\
56 {export_styles}\n\
57 </style>\n\
58 </head>\n\
59 \n\
60 <body>\n\
61 <p>\n\
62 {export_content}\n\
63 </p>\n\
64 </body>\n\
65 </html>\n"
67 #define TEMPLATE_LATEX "\
68 % {export_filename} (LaTeX code generated by Geany " PACKAGE_VERSION " on {export_date})\n\
69 \\documentclass[a4paper]{article}\n\
70 \\usepackage[a4paper,margin=2cm]{geometry}\n\
71 \\usepackage[utf8]{inputenc}\n\
72 \\usepackage[T1]{fontenc}\n\
73 \\usepackage{color}\n\
74 \\setlength{\\parindent}{0em}\n\
75 \\setlength{\\parskip}{2ex plus1ex minus0.5ex}\n\
76 {export_styles}\n\
77 \\begin{document}\
78 \n\
79 \\ttfamily\n\
80 \\setlength{\\fboxrule}{0pt}\n\
81 \\setlength{\\fboxsep}{0pt}\n\
82 {export_content}\
83 \\end{document}\n"
86 enum
88 FORE = 0,
89 BACK,
90 BOLD,
91 ITALIC,
92 USED,
93 MAX_TYPES
96 enum
98 DATE_TYPE_DEFAULT,
99 DATE_TYPE_HTML
102 typedef void (*ExportFunc) (GeanyDocument *doc, const gchar *filename,
103 gboolean use_zoom, gboolean insert_line_numbers);
104 typedef struct
106 GeanyDocument *doc;
107 gboolean have_zoom_level_checkbox;
108 ExportFunc export_func;
109 } ExportInfo;
111 static void on_file_save_dialog_response(GtkDialog *dialog, gint response, gpointer user_data);
112 static void write_html_file(GeanyDocument *doc, const gchar *filename,
113 gboolean use_zoom, gboolean insert_line_numbers);
114 static void write_latex_file(GeanyDocument *doc, const gchar *filename,
115 gboolean use_zoom, gboolean insert_line_numbers);
118 /* converts a RGB colour into a LaTeX compatible representation, taken from SciTE */
119 static gchar* get_tex_rgb(gint rgb_colour)
121 /* texcolor[rgb]{0,0.5,0}{....} */
122 gdouble rf = (rgb_colour % 256) / 256.0;
123 gdouble gf = ((rgb_colour & - 16711936) / 256) / 256.0;
124 gdouble bf = ((rgb_colour & 0xff0000) / 65536) / 256.0;
125 gint r = (gint) (rf * 10 + 0.5);
126 gint g = (gint) (gf * 10 + 0.5);
127 gint b = (gint) (bf * 10 + 0.5);
129 return g_strdup_printf("%d.%d, %d.%d, %d.%d", r / 10, r % 10, g / 10, g % 10, b / 10, b % 10);
133 /* convert a style number (0..127) into a string representation (aa, ab, .., ba, bb, .., zy, zz) */
134 static gchar *get_tex_style(gint style)
136 static gchar buf[4];
137 int i = 0;
141 buf[i] = (style % 26) + 'a';
142 style /= 26;
143 i++;
144 } while (style > 0);
145 buf[i] = '\0';
147 return buf;
151 static void create_file_save_as_dialog(const gchar *extension, ExportFunc func,
152 gboolean show_zoom_level_checkbox)
154 GtkWidget *dialog, *vbox;
155 GeanyDocument *doc;
156 ExportInfo *exi;
158 g_return_if_fail(extension != NULL);
160 doc = document_get_current();
161 g_return_if_fail(doc != NULL);
163 exi = g_new(ExportInfo, 1);
164 exi->doc = doc;
165 exi->export_func = func;
166 exi->have_zoom_level_checkbox = FALSE;
168 dialog = gtk_file_chooser_dialog_new(_("Export File"), GTK_WINDOW(geany->main_widgets->window),
169 GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
170 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
171 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
172 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
173 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
174 gtk_widget_set_name(dialog, "GeanyExportDialog");
176 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
177 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
178 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
180 /* file chooser extra widget */
181 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
182 gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), vbox);
184 GtkWidget *check_line_numbers;
186 check_line_numbers = gtk_check_button_new_with_mnemonic(_("_Insert line numbers"));
187 gtk_widget_set_tooltip_text(check_line_numbers,
188 _("Insert line numbers before each line in the exported document"));
189 gtk_box_pack_start(GTK_BOX(vbox), check_line_numbers, FALSE, FALSE, 0);
190 gtk_widget_show_all(vbox);
192 ui_hookup_widget(dialog, check_line_numbers, "check_line_numbers");
194 if (show_zoom_level_checkbox)
196 GtkWidget *check_zoom_level;
198 check_zoom_level = gtk_check_button_new_with_mnemonic(_("_Use current zoom level"));
199 gtk_widget_set_tooltip_text(check_zoom_level,
200 _("Renders the font size of the document together with the current zoom level"));
201 gtk_box_pack_start(GTK_BOX(vbox), check_zoom_level, FALSE, FALSE, 0);
202 gtk_widget_show_all(vbox);
204 ui_hookup_widget(dialog, check_zoom_level, "check_zoom_level");
205 exi->have_zoom_level_checkbox = TRUE;
208 g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
209 g_signal_connect(dialog, "response", G_CALLBACK(on_file_save_dialog_response), exi);
211 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(geany->main_widgets->window));
213 /* if the current document has a filename we use it as the default. */
214 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(dialog));
215 if (doc->file_name != NULL)
217 gchar *base_name = g_path_get_basename(doc->file_name);
218 gchar *file_name;
219 gchar *locale_filename;
220 gchar *locale_dirname;
221 const gchar *suffix = "";
223 if (g_str_has_suffix(doc->file_name, extension))
224 suffix = "_export";
226 file_name = g_strconcat(base_name, suffix, extension, NULL);
227 locale_filename = utils_get_locale_from_utf8(doc->file_name);
228 locale_dirname = g_path_get_dirname(locale_filename);
229 /* set the current name to base_name.html which probably doesn't exist yet so
230 * gtk_file_chooser_set_filename() can't be used and we need
231 * gtk_file_chooser_set_current_folder() additionally */
232 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dirname);
233 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), file_name);
234 g_free(locale_dirname);
235 g_free(locale_filename);
236 g_free(file_name);
237 g_free(base_name);
239 else
241 const gchar *default_open_path = geany->prefs->default_open_path;
242 gchar *fname = g_strconcat(GEANY_STRING_UNTITLED, extension, NULL);
244 gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(dialog));
245 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fname);
247 /* use default startup directory(if set) if no files are open */
248 if (!EMPTY(default_open_path) && g_path_is_absolute(default_open_path))
250 gchar *locale_path = utils_get_locale_from_utf8(default_open_path);
251 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
252 g_free(locale_path);
254 g_free(fname);
256 gtk_dialog_run(GTK_DIALOG(dialog));
260 static void on_menu_create_latex_activate(GtkMenuItem *menuitem, gpointer user_data)
262 create_file_save_as_dialog(".tex", write_latex_file, FALSE);
266 static void on_menu_create_html_activate(GtkMenuItem *menuitem, gpointer user_data)
268 create_file_save_as_dialog(".html", write_html_file, TRUE);
272 static void write_data(const gchar *filename, const gchar *data)
274 gint error_nr = utils_write_file(filename, data);
275 gchar *utf8_filename = utils_get_utf8_from_locale(filename);
277 if (error_nr == 0)
278 ui_set_statusbar(TRUE, _("Document successfully exported as '%s'."), utf8_filename);
279 else
280 ui_set_statusbar(TRUE, _("File '%s' could not be written (%s)."),
281 utf8_filename, g_strerror(error_nr));
283 g_free(utf8_filename);
287 static gchar *get_date(gint type)
289 const gchar *format;
291 if (type == DATE_TYPE_HTML)
292 /* needs testing */
293 #ifdef _GNU_SOURCE
294 format = "%Y-%m-%dT%H:%M:%S%z";
295 #else
296 format = "%Y-%m-%dT%H:%M:%S";
297 #endif
298 else
299 format = "%c";
301 return utils_get_date_time(format, NULL);
305 static void on_file_save_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
307 ExportInfo *exi = user_data;
309 if (response == GTK_RESPONSE_ACCEPT && exi != NULL)
311 gchar *new_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
312 gchar *utf8_filename;
313 gboolean insert_line_numbers;
314 gboolean use_zoom_level = FALSE;
316 if (exi->have_zoom_level_checkbox)
318 use_zoom_level = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
319 ui_lookup_widget(GTK_WIDGET(dialog), "check_zoom_level")));
321 insert_line_numbers = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
322 ui_lookup_widget(GTK_WIDGET(dialog), "check_line_numbers")));
324 utf8_filename = utils_get_utf8_from_locale(new_filename);
326 /* check if file exists and ask whether to overwrite or not */
327 if (g_file_test(new_filename, G_FILE_TEST_EXISTS))
329 if (dialogs_show_question(
330 _("The file '%s' already exists. Do you want to overwrite it?"),
331 utf8_filename) == FALSE)
332 return;
335 exi->export_func(exi->doc, new_filename, use_zoom_level, insert_line_numbers);
337 g_free(utf8_filename);
338 g_free(new_filename);
340 g_free(exi);
341 gtk_widget_destroy(GTK_WIDGET(dialog));
345 /* returns the "width" (count of needed characters) for the given number */
346 static gint get_line_numbers_arity(gint line_number)
348 gint a = 0;
349 while ((line_number /= 10) != 0)
350 a++;
351 return a;
355 static gint get_line_number_width(GeanyDocument *doc)
357 gint line_count = sci_get_line_count(doc->editor->sci);
358 return get_line_numbers_arity(line_count);
362 static void write_latex_file(GeanyDocument *doc, const gchar *filename,
363 gboolean use_zoom, gboolean insert_line_numbers)
365 GeanyEditor *editor = doc->editor;
366 ScintillaObject *sci = doc->editor->sci;
367 gint i, doc_len, style = -1, old_style = 0, column = 0;
368 gint k, line_number, line_number_width, line_number_max_width = 0, pad;
369 gchar c, c_next, *tmp, *date;
370 /* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */
371 gint styles[STYLE_MAX + 1][MAX_TYPES];
372 gboolean block_open = FALSE;
373 GString *body;
374 GString *cmds;
375 GString *latex;
377 /* first read all styles from Scintilla */
378 for (i = 0; i < STYLE_MAX; i++)
380 styles[i][FORE] = scintilla_send_message(sci, SCI_STYLEGETFORE, i, 0);
381 styles[i][BACK] = scintilla_send_message(sci, SCI_STYLEGETBACK, i, 0);
382 styles[i][BOLD] = scintilla_send_message(sci, SCI_STYLEGETBOLD, i, 0);
383 styles[i][ITALIC] = scintilla_send_message(sci, SCI_STYLEGETITALIC, i, 0);
384 styles[i][USED] = 0;
387 if (insert_line_numbers)
388 line_number_max_width = get_line_number_width(doc);
390 /* read the document and write the LaTeX code */
391 body = g_string_new("");
392 doc_len = sci_get_length(sci);
393 for (i = 0; i < doc_len; i++)
395 style = sci_get_style_at(sci, i);
396 c = sci_get_char_at(sci, i);
397 c_next = sci_get_char_at(sci, i + 1);
399 /* line numbers */
400 if (insert_line_numbers && column == 0)
402 line_number = sci_get_line_from_position(sci, i) + 1;
403 line_number_width = get_line_numbers_arity(line_number);
404 /* padding */
405 pad = line_number_max_width - line_number_width;
406 for (k = 0; k < pad; k++)
408 g_string_append(body, " ");
410 g_string_append_printf(body, "%d ", line_number);
413 if (style != old_style || ! block_open)
415 old_style = style;
416 styles[style][USED] = 1;
417 if (block_open)
419 g_string_append(body, "}\n");
420 block_open = FALSE;
422 if (i < doc_len)
424 g_string_append_printf(body, "\\style%s{", get_tex_style(style));
425 block_open = TRUE;
428 /* escape the current character if necessary else just add it */
429 switch (c)
431 case '\r':
432 case '\n':
434 if (c == '\r' && c_next == '\n')
435 continue; /* when using CR/LF skip CR and add the line break with LF */
437 if (block_open)
439 g_string_append(body, "}");
440 block_open = FALSE;
442 g_string_append(body, " \\\\\n");
443 column = -1;
444 break;
446 case '\t':
448 gint tab_width = sci_get_tab_width(editor->sci);
449 gint tab_stop = tab_width - (column % tab_width);
451 column += tab_stop - 1; /* -1 because we add 1 at the end of the loop */
452 g_string_append_printf(body, "\\hspace*{%dem}", tab_stop);
453 break;
455 case ' ':
457 if (c_next == ' ')
459 g_string_append(body, "{\\hspace*{1em}}");
460 i++; /* skip the next character */
462 else
463 g_string_append_c(body, ' ');
464 break;
466 case '{':
467 case '}':
468 case '_':
469 case '&':
470 case '$':
471 case '#':
472 case '%':
474 g_string_append_printf(body, "\\%c", c);
475 break;
477 case '\\':
479 g_string_append(body, "\\symbol{92}");
480 break;
482 case '~':
484 g_string_append(body, "\\symbol{126}");
485 break;
487 case '^':
489 g_string_append(body, "\\symbol{94}");
490 break;
492 /* mask "--", "<<" and ">>" */
493 case '-':
494 case '<':
495 case '>':
497 g_string_append_c(body, c);
498 if (c_next == c)
499 g_string_append(body, "\\/");
501 break;
503 default: g_string_append_c(body, c);
505 column++;
507 if (block_open)
509 g_string_append(body, "}\n");
510 block_open = FALSE;
513 /* force writing of style 0 (used at least for line breaks) */
514 styles[0][USED] = 1;
516 /* write used styles in the header */
517 cmds = g_string_new("");
518 for (i = 0; i < STYLE_MAX; i++)
520 if (styles[i][USED])
522 g_string_append_printf(cmds,
523 "\\newcommand{\\style%s}[1]{\\noindent{", get_tex_style(i));
524 if (styles[i][BOLD])
525 g_string_append(cmds, "\\textbf{");
526 if (styles[i][ITALIC])
527 g_string_append(cmds, "\\textit{");
529 tmp = get_tex_rgb(styles[i][FORE]);
530 g_string_append_printf(cmds, "\\textcolor[rgb]{%s}{", tmp);
531 g_free(tmp);
532 tmp = get_tex_rgb(styles[i][BACK]);
533 g_string_append_printf(cmds, "\\fcolorbox[rgb]{0, 0, 0}{%s}{", tmp);
534 g_string_append(cmds, "#1}}");
535 g_free(tmp);
537 if (styles[i][BOLD])
538 g_string_append_c(cmds, '}');
539 if (styles[i][ITALIC])
540 g_string_append_c(cmds, '}');
541 g_string_append(cmds, "}}\n");
545 date = get_date(DATE_TYPE_DEFAULT);
546 /* write all */
547 latex = g_string_new(TEMPLATE_LATEX);
548 utils_string_replace_all(latex, "{export_content}", body->str);
549 utils_string_replace_all(latex, "{export_styles}", cmds->str);
550 utils_string_replace_all(latex, "{export_date}", date);
551 utils_string_replace_all(latex, "{export_filename}", DOC_FILENAME(doc));
553 write_data(filename, latex->str);
555 g_string_free(body, TRUE);
556 g_string_free(cmds, TRUE);
557 g_string_free(latex, TRUE);
558 g_free(date);
562 static void write_html_file(GeanyDocument *doc, const gchar *filename,
563 gboolean use_zoom, gboolean insert_line_numbers)
565 GeanyEditor *editor = doc->editor;
566 ScintillaObject *sci = doc->editor->sci;
567 gint i, doc_len, style = -1, old_style = 0, column = 0;
568 gint k, line_number, line_number_width, line_number_max_width = 0, pad;
569 gchar c, c_next, *date, *doc_filename;
570 /* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */
571 gint styles[STYLE_MAX + 1][MAX_TYPES];
572 gboolean span_open = FALSE;
573 const gchar *font_name;
574 gint font_size;
575 PangoFontDescription *font_desc;
576 GString *body;
577 GString *css;
578 GString *html;
580 /* first read all styles from Scintilla */
581 for (i = 0; i < STYLE_MAX; i++)
583 styles[i][FORE] = ROTATE_RGB(scintilla_send_message(sci, SCI_STYLEGETFORE, i, 0));
584 styles[i][BACK] = ROTATE_RGB(scintilla_send_message(sci, SCI_STYLEGETBACK, i, 0));
585 styles[i][BOLD] = scintilla_send_message(sci, SCI_STYLEGETBOLD, i, 0);
586 styles[i][ITALIC] = scintilla_send_message(sci, SCI_STYLEGETITALIC, i, 0);
587 styles[i][USED] = 0;
590 /* read Geany's font and font size */
591 font_desc = pango_font_description_from_string(geany->interface_prefs->editor_font);
592 font_name = pango_font_description_get_family(font_desc);
593 /*font_size = pango_font_description_get_size(font_desc) / PANGO_SCALE;*/
594 /* take the zoom level also into account */
595 font_size = scintilla_send_message(sci, SCI_STYLEGETSIZE, 0, 0);
596 if (use_zoom)
597 font_size += scintilla_send_message(sci, SCI_GETZOOM, 0, 0);
599 if (insert_line_numbers)
600 line_number_max_width = get_line_number_width(doc);
602 /* read the document and write the HTML body */
603 body = g_string_new("");
604 doc_len = sci_get_length(sci);
605 for (i = 0; i < doc_len; i++)
607 style = sci_get_style_at(sci, i);
608 c = sci_get_char_at(sci, i);
609 /* sci_get_char_at() takes care of index boundaries and return 0 if i is too high */
610 c_next = sci_get_char_at(sci, i + 1);
612 /* line numbers */
613 if (insert_line_numbers && column == 0)
615 line_number = sci_get_line_from_position(sci, i) + 1;
616 line_number_width = get_line_numbers_arity(line_number);
617 /* padding */
618 pad = line_number_max_width - line_number_width;
619 for (k = 0; k < pad; k++)
621 g_string_append(body, "&nbsp;");
623 g_string_append_printf(body, "%d&nbsp;", line_number);
626 if ((style != old_style || ! span_open) && ! isspace(c))
628 old_style = style;
629 styles[style][USED] = 1;
630 if (span_open)
632 g_string_append(body, "</span>");
634 if (i < doc_len)
636 g_string_append_printf(body, "<span class=\"style_%d\">", style);
637 span_open = TRUE;
640 /* escape the current character if necessary else just add it */
641 switch (c)
643 case '\r':
644 case '\n':
646 if (c == '\r' && c_next == '\n')
647 continue; /* when using CR/LF skip CR and add the line break with LF */
649 if (span_open)
651 g_string_append(body, "</span>");
652 span_open = FALSE;
654 g_string_append(body, "<br />\n");
655 column = -1;
656 break;
658 case '\t':
660 gint j;
661 gint tab_width = sci_get_tab_width(editor->sci);
662 gint tab_stop = tab_width - (column % tab_width);
664 column += tab_stop - 1; /* -1 because we add 1 at the end of the loop */
665 for (j = 0; j < tab_stop; j++)
667 g_string_append(body, "&nbsp;");
669 break;
671 case ' ':
673 g_string_append(body, "&nbsp;");
674 break;
676 case '<':
678 g_string_append(body, "&lt;");
679 break;
681 case '>':
683 g_string_append(body, "&gt;");
684 break;
686 case '&':
688 g_string_append(body, "&amp;");
689 break;
691 default: g_string_append_c(body, c);
693 column++;
695 if (span_open)
697 g_string_append(body, "</span>");
698 span_open = FALSE;
701 /* write used styles in the header */
702 css = g_string_new("");
703 g_string_append_printf(css,
704 "\tbody\n\t{\n\t\tfont-family: %s, monospace;\n\t\tfont-size: %dpt;\n\t}\n",
705 font_name, font_size);
707 for (i = 0; i < STYLE_MAX; i++)
709 if (styles[i][USED])
711 g_string_append_printf(css,
712 "\t.style_%d\n\t{\n\t\tcolor: #%06x;\n\t\tbackground-color: #%06x;\n%s%s\t}\n",
713 i, styles[i][FORE], styles[i][BACK],
714 (styles[i][BOLD]) ? "\t\tfont-weight: bold;\n" : "",
715 (styles[i][ITALIC]) ? "\t\tfont-style: italic;\n" : "");
719 date = get_date(DATE_TYPE_HTML);
720 doc_filename = g_markup_escape_text(DOC_FILENAME(doc), -1);
721 /* write all */
722 html = g_string_new(TEMPLATE_HTML);
723 utils_string_replace_all(html, "{export_date}", date);
724 utils_string_replace_all(html, "{export_content}", body->str);
725 utils_string_replace_all(html, "{export_styles}", css->str);
726 utils_string_replace_all(html, "{export_filename}", doc_filename);
728 write_data(filename, html->str);
730 pango_font_description_free(font_desc);
731 g_string_free(body, TRUE);
732 g_string_free(css, TRUE);
733 g_string_free(html, TRUE);
734 g_free(doc_filename);
735 g_free(date);
739 void plugin_init(GeanyData *data)
741 GtkWidget *menu_export;
742 GtkWidget *menu_export_menu;
743 GtkWidget *menu_create_html;
744 GtkWidget *menu_create_latex;
746 menu_export = gtk_image_menu_item_new_with_mnemonic(_("_Export"));
747 gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_export);
749 menu_export_menu = gtk_menu_new ();
750 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_export), menu_export_menu);
752 /* HTML */
753 menu_create_html = gtk_menu_item_new_with_mnemonic(_("As _HTML..."));
754 gtk_container_add(GTK_CONTAINER (menu_export_menu), menu_create_html);
756 g_signal_connect(menu_create_html, "activate", G_CALLBACK(on_menu_create_html_activate), NULL);
758 /* LaTeX */
759 menu_create_latex = gtk_menu_item_new_with_mnemonic(_("As _LaTeX..."));
760 gtk_container_add(GTK_CONTAINER (menu_export_menu), menu_create_latex);
762 g_signal_connect(menu_create_latex, "activate",
763 G_CALLBACK(on_menu_create_latex_activate), NULL);
765 /* disable menu_item when there are no documents open */
766 ui_add_document_sensitive(menu_export);
767 main_menu_item = menu_export;
769 gtk_widget_show_all(menu_export);
773 void plugin_cleanup(void)
775 gtk_widget_destroy(main_menu_item);