diff --git a/data/reference_files/reference-a4.docx b/data/reference_files/reference-a4.docx new file mode 100644 index 0000000..c381135 Binary files /dev/null and b/data/reference_files/reference-a4.docx differ diff --git a/data/reference_files/reference-a4.odt b/data/reference_files/reference-a4.odt new file mode 100644 index 0000000..3fbb559 Binary files /dev/null and b/data/reference_files/reference-a4.odt differ diff --git a/data/ui/Export.ui b/data/ui/Export.ui index 3ea4419..39f6695 100644 --- a/data/ui/Export.ui +++ b/data/ui/Export.ui @@ -1,5 +1,5 @@ - + @@ -341,71 +341,40 @@ - + True False - start - 0 - out + vertical - + True False - 12 + start + 0 + out - + True False - 4 - 4 - vertical - True + 12 - - Self-contained - False - True - True - False - Produces a HTML that has no external dependencies (all images and stylesheets are included) - start - True - - - False - True - 0 - - - - - HTML5 - False - True - True - False - Use HTML5 syntax - start - True - True - - - False - True - 1 - - - - + True False + 4 + 4 + vertical + True - + + Self-contained + False True - False - Choose a CSS File that you want to use - 4 - CSS File + True + False + Produces a HTML that has no external dependencies (all images and stylesheets are included) + start + True False @@ -414,37 +383,151 @@ - + + HTML5 + False True - False - Choose a CSS File that you want to use - 8 - 8 + True + False + Use HTML5 syntax + start + True + True - True + False True 1 + + + True + False + + + True + False + Choose a CSS File that you want to use + 4 + CSS File + + + False + True + 0 + + + + + True + False + Choose a CSS File that you want to use + 8 + 8 + + + True + True + 1 + + + + + False + True + 2 + + - - False - True - 2 - + + + True + False + <b>HTML Options</b> + True + + + + False + True + 0 + - - + + True False - <b>HTML Options</b> - True + start + 0 + out + + + True + False + 12 + + + True + False + 4 + 4 + + + True + False + 4 + Paper size + + + False + True + 0 + + + + + True + False + 8 + 8 + 0 + 0 + + A4 + US Letter + + + + True + True + end + 1 + + + + + + + + + True + False + <b>PDF Options</b> + True + + + + False + True + 5 + 1 + @@ -465,6 +548,7 @@ True True True + start none https://pandoc.org/MANUAL.html @@ -529,44 +613,6 @@ cancel_btn export_btn - - - True - False - - - gtk-cancel - True - True - True - True - - - 1 - - - - - True - False - export_stack - - - - - Export - True - True - True - True - - - end - 2 - - - - False @@ -597,19 +643,6 @@ html HTML - 2 - - - - - True - False - save - pdf_filter - - - pdf - PDF @@ -623,6 +656,19 @@ 1 + + + True + False + save + pdf_filter + + + pdf + PDF + 2 + + True @@ -632,7 +678,7 @@ advanced Advanced - 4 + 3 @@ -644,5 +690,43 @@ + + + True + False + + + True + False + export_stack + + + + + gtk-cancel + True + True + True + True + + + 1 + + + + + Export + True + True + True + True + + + end + 2 + + + + diff --git a/uberwriter/export_dialog.py b/uberwriter/export_dialog.py index 7b9cbd4..95de282 100644 --- a/uberwriter/export_dialog.py +++ b/uberwriter/export_dialog.py @@ -155,6 +155,7 @@ class Export: self.dialog = self.builder.get_object("Export") self.stack = self.builder.get_object("export_stack") self.stack_switcher = self.builder.get_object("format_switcher") + self.paper_size = self.builder.get_object("combobox_paper_size") stack_pdf_disabled = self.builder.get_object("pdf_disabled") filename = filename or _("Untitled document.md") @@ -205,9 +206,7 @@ class Export: """ export_type = self.stack.get_visible_child_name() - args = [ - "--variable=papersize:a4" - ] + args = [] if export_type == "advanced": filename = self.adv_export_name.get_text() output_dir = os.path.abspath(self.filechoosers["advanced"].get_current_folder()) @@ -222,9 +221,12 @@ class Export: if self.builder.get_object("smart").get_active(): to += "+smart" - args.extend(self.get_advanced_arguments()) + args.extend(self.get_advanced_arguments(to, ext)) else: + args = [ + "--variable=papersize:a4" + ] filename = self.filechoosers[export_type].get_filename() if filename.endswith("." + export_type): filename = filename[:-len(export_type)-1] @@ -242,11 +244,12 @@ class Export: args.append("--lua-filter=%s" % helpers.get_script_path('relative_to_absolute.lua')) args.append("--lua-filter=%s" % helpers.get_script_path('task-list.lua')) + helpers.pandoc_convert( text, to=to, args=args, outputfile="%s/%s.%s" % (output_dir, basename, ext)) - def get_advanced_arguments(self): + def get_advanced_arguments(self, to_fmt, ext_fmt): """Retrieve a list of the selected advanced arguments For most of the advanced option checkboxes, returns a list @@ -254,6 +257,8 @@ class Export: Arguments: basename {str} -- the name of the file + to_fmt {str} -- the format of the export + ext_fmt {str} -- the extension of the export Returns: list of {str} -- related pandoc flags @@ -262,6 +267,16 @@ class Export: highlight_style = self.builder.get_object("highlight_style").get_active_text() conditions = [ + { + "condition": to_fmt == "pdf", + "yes": "--variable=papersize:" + self.get_paper_size(), + "no": None + }, + { + "condition": self.get_paper_size() == "a4" and (to_fmt == "odt" or to_fmt == "docx"), + "yes": "--reference-doc " + helpers.get_reference_files_path('reference-a4.'+to_fmt) + to_fmt, + "no": None + }, { "condition": self.builder.get_object("toc").get_active(), "yes": "--toc", @@ -319,6 +334,16 @@ class Export: return args + def get_paper_size(self): + paper_size = self.paper_size.get_active_text() + + paper_formats = { + "A4": "a4", + "US Letter": "letter" + } + + return paper_formats[paper_size] + def allow_export(self, widget, data, signal): """Disable export button if the visible child is "pdf_disabled" """ diff --git a/uberwriter/helpers.py b/uberwriter/helpers.py index 71df380..9cbe339 100644 --- a/uberwriter/helpers.py +++ b/uberwriter/helpers.py @@ -85,6 +85,15 @@ def get_script_path(script_file_name): return script_path +def get_reference_files_path(reference_file_name): + """Return the full path of a given filename under the reference_files dir + """ + refs_path = get_data_file('reference_files', '%s' % (reference_file_name,)) + if not os.path.exists(refs_path): + refs_path = None + return refs_path + + class NullHandler(logging.Handler): def emit(self, record): pass