From c8d30db4e31eca3b0689647430e1b72959244e8f Mon Sep 17 00:00:00 2001 From: "Romain F. T" Date: Sun, 9 Feb 2020 01:05:05 +0100 Subject: [PATCH] very beginning of issue #20 various minor improvements to the export dialog, the backend module, the prefs window, etc. to prepare the future implementation of a revealjs support --- POTFILES | 3 +- README.md | 3 +- example.css | 181 +++++++++--------- markdown_preview/__init__.py | 10 +- markdown_preview/backend_box.ui | 42 ++-- markdown_preview/kb_acc_data.py | 16 +- .../{export.py => prefs_and_export.py} | 81 +++++--- markdown_preview/preview.py | 22 ++- markdown_preview/revealjs_box.ui | 9 + ...gedit.plugins.markdown_preview.gschema.xml | 31 +-- 10 files changed, 231 insertions(+), 167 deletions(-) rename markdown_preview/{export.py => prefs_and_export.py} (90%) create mode 100644 markdown_preview/revealjs_box.ui diff --git a/POTFILES b/POTFILES index 85310e8..c9f4efa 100644 --- a/POTFILES +++ b/POTFILES @@ -1,4 +1,4 @@ -./markdown_preview/export.py +./markdown_preview/prefs_and_export.py ./markdown_preview/__init__.py ./markdown_preview/kb_acc_data.py ./markdown_preview/preview.py @@ -8,3 +8,4 @@ ./markdown_preview/menus.ui ./markdown_preview/prefs.ui ./markdown_preview/preview.ui +./markdown_preview/revealjs_box.ui diff --git a/README.md b/README.md index 2291408..95204f3 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,11 @@ - [ ] help labels and links for pandoc too! et toutes les pages en fait - [ ] CSS for admonitions (and other default plugins ?) - [ ] and pymdown ?? -- [ ] cesser les zouaveries avec pandoc et les pre-strings/post-strings, il y a de vraies options - [ ] reveal js https://github.com/jgm/pandoc/wiki/Using-pandoc-to-produce-reveal.js-slides - [ ] rendu - [ ] transitions + - [ ] numéros de pages - [ ] paramètres de thème -- [ ] compléter les descriptions des schémas - [ ] se souvenir du splitter - [ ] ajouter le réglage pour le splitter dans les préférences - [ ] bring back the fullscreen, but better diff --git a/example.css b/example.css index eef609d..1ce1510 100644 --- a/example.css +++ b/example.css @@ -1,22 +1,18 @@ -h1, -h2, -h3, -h4, -h5, -h6, -p, -blockquote { - margin: 0; - padding: 0; -} +/* example of a css file */ body { - font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif; - font-size: 13px; - line-height: 18px; - color: #737373; - background-color: white; - margin: 10px 13px 10px 13px; + font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif; + font-size: 13px; + line-height: 18px; + color: #737373; + background-color: white; + margin: 10px 13px 10px 13px; } + +h1, h2, h3, h4, h5, h6, p, blockquote { + margin: 0; + padding: 0; +} + table { margin: 10px 0 15px 0; border-collapse: collapse; @@ -30,131 +26,128 @@ th { } a { - color: #0069d6; + color: #0069d6; } a:hover { - color: #0050a3; - text-decoration: none; + color: #0050a3; + text-decoration: none; } a img { - border: none; + border: none; } + p { - margin-bottom: 9px; + margin-bottom: 9px; } -h1, -h2, -h3, -h4, -h5, -h6 { - color: #404040; - line-height: 36px; +h1, h2, h3, h4, h5, h6 { + color: #404040; + line-height: 36px; } h1 { - margin-bottom: 18px; - font-size: 30px; + margin-bottom: 18px; + font-size: 30px; } h2 { - font-size: 24px; + font-size: 24px; } h3 { - font-size: 18px; + font-size: 18px; } h4 { - font-size: 16px; + font-size: 16px; } h5 { - font-size: 14px; + font-size: 14px; } h6 { - font-size: 13px; + font-size: 13px; } hr { - margin: 0 0 19px; - border: 0; - border-bottom: 1px solid #ccc; + margin: 0 0 19px; + border: 0; + border-bottom: 1px solid #ccc; } blockquote { - padding: 13px 13px 21px 15px; - margin-bottom: 18px; - font-family:georgia,serif; - font-style: italic; + padding: 13px 13px 21px 15px; + margin-bottom: 18px; + font-family:georgia,serif; + font-style: italic; } blockquote:before { - content:"\201C"; - font-size:40px; - margin-left:-10px; - font-family:georgia,serif; - color:#eee; + content:"\201C"; + font-size:40px; + margin-left:-10px; + font-family:georgia,serif; + color:#eee; } blockquote p { - font-size: 14px; - font-weight: 300; - line-height: 18px; - margin-bottom: 0; - font-style: italic; + font-size: 14px; + font-weight: 300; + line-height: 18px; + margin-bottom: 0; + font-style: italic; } code, pre { - font-family: Monaco, Andale Mono, Courier New, monospace; + font-family: Monaco, Andale Mono, Courier New, monospace; } code { - background-color: #fee9cc; - color: rgba(0, 0, 0, 0.75); - padding: 1px 3px; - font-size: 12px; - -webkit-border-radius: 3px; - -moz-border-radius: 3px; - border-radius: 3px; + background-color: #fee9cc; + color: rgba(0, 0, 0, 0.75); + padding: 1px 3px; + font-size: 12px; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; } pre { - display: block; - padding: 14px; - margin: 0 0 18px; - line-height: 16px; - font-size: 11px; - border: 1px solid #d9d9d9; - white-space: pre-wrap; - word-wrap: break-word; + display: block; + padding: 14px; + margin: 0 0 18px; + line-height: 16px; + font-size: 11px; + border: 1px solid #d9d9d9; + white-space: pre-wrap; + word-wrap: break-word; } pre code { - background-color: #fff; - color:#737373; - font-size: 11px; - padding: 0; + background-color: #fff; + color:#737373; + font-size: 11px; + padding: 0; } sup { - font-size: 0.83em; - vertical-align: super; - line-height: 0; + font-size: 0.83em; + vertical-align: super; + line-height: 0; } kbd { - display: inline-block; - padding: 3px 5px; - font-size: 11px; - line-height: 10px; - color: #555; - vertical-align: middle; - background-color: #fcfcfc; - border: solid 1px #ccc; - border-bottom-color: #bbb; - border-radius: 3px; - box-shadow: inset 0 -1px 0 #bbb; + display: inline-block; + padding: 3px 5px; + font-size: 11px; + line-height: 10px; + color: #555; + vertical-align: middle; + background-color: #fcfcfc; + border: solid 1px #ccc; + border-bottom-color: #bbb; + border-radius: 3px; + box-shadow: inset 0 -1px 0 #bbb; } * { -webkit-print-color-adjust: exact; } @media screen and (min-width: 914px) { - body { - width: 854px; - margin:10px auto; - } + body { + width: 854px; + margin:10px auto; + } } @media print { - body,code,pre code,h1,h2,h3,h4,h5,h6 { + body, code, pre code, h1, h2, h3, h4, h5, h6 { color: black; } table, pre { page-break-inside: avoid; } -} \ No newline at end of file +} + diff --git a/markdown_preview/__init__.py b/markdown_preview/__init__.py index 3c0c460..d9f52a1 100644 --- a/markdown_preview/__init__.py +++ b/markdown_preview/__init__.py @@ -8,7 +8,7 @@ LOCALE_PATH = os.path.join(BASE_PATH, 'locale') from .preview import MdPreviewBar -from .export import MdExportDialog, MdConfigWidget +from .prefs_and_export import MdExportDialog, MdConfigWidget from .kb_acc_data import ACTIONS_NAMES from .kb_acc_data import SETTINGS_KEYS @@ -211,7 +211,7 @@ def view_method(self, name): else: return - print('action : ' + name) + # print('action : ' + name) # TODO terminer ça mdr if name == 'insert_table': v.insert_table() @@ -275,11 +275,11 @@ def do_create_configure_widget(self): return widget def on_open_prefs(self, *args): - w = Gtk.Window(title=_("Markdown Preview")) + w = Gtk.Window(title=_("Markdown Preview"), default_height=350) widget = MdConfigWidget(self.plugin_info.get_data_dir()) w.add(widget) w.present() - w.show_all() + w.show_all() # immonde mais reproduit le comportement de libpeas def export_doc(self, *args): dialog = MdExportDialog(self.preview.recognize_format(), self.window, self._settings) @@ -325,7 +325,7 @@ def populate_popup(self, view, popup): item.set_sensitive(False) popup.append(item) - def recognize_format(self): # FIXME doc.get_language() + def recognize_format(self): # TODO doc.get_language() doc = self.view.get_buffer() name = doc.get_short_name_for_display() temp = name.split('.') diff --git a/markdown_preview/backend_box.ui b/markdown_preview/backend_box.ui index 550034d..011395a 100644 --- a/markdown_preview/backend_box.ui +++ b/markdown_preview/backend_box.ui @@ -64,9 +64,16 @@ - + True - none + True + in + + + True + none + + @@ -142,6 +149,20 @@ + + + True + True + in + + + True + word-char + False + + + + horizontal @@ -149,16 +170,12 @@ True 16 - + True - - - True - True - word-char - False - - + True + True + 50 + @@ -167,6 +184,9 @@ center Remember + + end + diff --git a/markdown_preview/kb_acc_data.py b/markdown_preview/kb_acc_data.py index 5c96dfe..ed6ea7a 100644 --- a/markdown_preview/kb_acc_data.py +++ b/markdown_preview/kb_acc_data.py @@ -22,15 +22,15 @@ 'win.md-prev-insert-picture', 'win.md-prev-format-title-lower', 'win.md-prev-format-title-upper' -] # TODO pas fini évidemment +] # TODO obviously not finished SETTINGS_KEYS = [ - 'kb-italic', - 'kb-bold', - 'kb-insert-picture', - 'kb-title-lower', - 'kb-title-upper' -] # TODO pas fini évidemment + 'italic', + 'bold', + 'insert-picture', + 'title-lower', + 'title-upper' +] # TODO obviously not finished LABELS = [ _("Italic"), @@ -38,7 +38,7 @@ _("Insert a picture"), _("Lower title"), _("Upper title") -] # TODO pas fini évidemment +] # TODO obviously not finished ################################################################################ diff --git a/markdown_preview/export.py b/markdown_preview/prefs_and_export.py similarity index 90% rename from markdown_preview/export.py rename to markdown_preview/prefs_and_export.py index c046d63..19b8f2c 100644 --- a/markdown_preview/export.py +++ b/markdown_preview/prefs_and_export.py @@ -70,6 +70,10 @@ "the features of these extensions, please add their module names to the " + \ "list using the text entry and the '+' icon.") +HELP_LABEL_PANDOC = _("TODO explanation about pandoc") +# TODO there should be several distinct labels +pass + PANDOC_FORMATS_FULL = { 'beamer': _("LaTeX beamer slideshow (.tex)"), 'docx': _("Microsoft Word (.docx)"), @@ -92,6 +96,19 @@ ################################################################################ +class MdRevealjsSettings(): + def __init__(self, settings, parent_widget): + self._settings = settings + self.parent_widget = parent_widget + + builder = Gtk.Builder().new_from_file(BASE_PATH + '/revealjs_box.ui') + self.full_widget = builder.get_object('revealjs_box') + + # TODO + + ############################################################################ +################################################################################ + class MdCSSSettings(): def __init__(self, settings, related_window, parent_widget): self._settings = settings @@ -162,7 +179,6 @@ def __init__(self, label, settings, apply_to_settings): self.full_widget = builder.get_object('backend_box') builder.get_object('combo_label').set_label(label) self.backend_stack = builder.get_object('backend_stack') - self.full_widget.show_all() # XXX ugly backendCombobox = builder.get_object('backend_combobox') backendCombobox.append('python', "python3-markdown") backendCombobox.append('pandoc', "pandoc") @@ -182,6 +198,7 @@ def __init__(self, label, settings, apply_to_settings): # Load UI for the pandoc backend self.pandoc_cli_entry = builder.get_object('pandoc_command_entry') + builder.get_object('help_label_pandoc').set_label(HELP_LABEL_PANDOC) self.remember_button = builder.get_object('remember_button') self.remember_button.connect('clicked', self.on_remember) self.format_combobox = builder.get_object('format_combobox') @@ -255,7 +272,7 @@ def get_active_backend(self): return self.backend_stack.get_visible_child_name() def on_remember(self, b): - new_command = self.pandoc_command_entry.get_buffer().get_text() + new_command = self.pandoc_cli_entry.get_buffer().get_text() self._settings.set_string('custom-export', new_command) def set_pandoc_command(self, command): @@ -271,7 +288,8 @@ class MdExportDialog(Gtk.Dialog): output_extension = '.pdf' def __init__(self, file_format, gedit_window, settings, **kwargs): - super().__init__(use_header_bar=True, title=_("Export as…"), **kwargs) + super().__init__(use_header_bar=True, title=_("Export as…"), \ + default_width=640, default_height=400, **kwargs) self.file_format = file_format self.gedit_window = gedit_window self._settings = settings @@ -331,10 +349,11 @@ def on_pandoc_format_changed(self, w): self.output_extension = '.pdf' elif output_format == 'revealjs': options = '-t revealjs -s -V revealjs-url=http://lab.hakim.se/reveal-js' - # TODO slide numbers option ?? - # options = options + ' -V theme=moon -V transition=cube' - # options = options + ' -V showSlideNumber=all' # XXX ne marche pas + options = options + ' -V theme=blood' # beige black blood league moon night serif simple sky solarized white + options = options + ' -V transition=slide' + # none, fade, slide, convex (= cube ?), concave, zoom + options = options + ' -V slideNumber=true' # there are more options self.output_extension = '.html' accept_css = False # in fact, it does accept a stylesheet as an # option, but the 2 CSS will often be incompatible. @@ -436,18 +455,25 @@ def __init__(self, datadir, **kwargs): self._kb_settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE + '.keybindings') builder = Gtk.Builder().new_from_file(BASE_PATH + '/prefs.ui') -# builder.set_translation_domain('gedit-plugin-markdown-preview') # TODO + # builder.set_translation_domain('gedit-plugin-markdown-preview') # FIXME stack = builder.get_object('stack') sidebar = Gtk.StackSidebar(stack=stack) - ### GENERAL PAGE ####################################################### + self._build_general_page(builder) + self._build_style_page(builder) + self._build_backend_page(builder) + self._build_shortcuts_page(builder) + + self.add(sidebar) + self.add(stack) + def _build_general_page(self, builder): general_box = builder.get_object('general_box') positionCombobox = builder.get_object('positionCombobox') positionCombobox.append('auto', _("Automatic")) - positionCombobox.append('side', _("Side Panel")) - positionCombobox.append('bottom', _("Bottom Panel")) + positionCombobox.append('side', _("Side Pane")) + positionCombobox.append('bottom', _("Bottom Pane")) positionCombobox.set_active_id(self._settings.get_string('position')) positionCombobox.connect('changed', self.on_position_changed) @@ -456,17 +482,28 @@ def __init__(self, datadir, **kwargs): relativePathsSwitch.connect('notify::active', self.on_relative_changed) autoManageSwitch = builder.get_object('autoManageSwitch') - autoManageSwitch.set_state(self._settings.get_boolean('auto-manage-panel')) + autoManageSwitch.set_state(self._settings.get_boolean('auto-manage-pane')) autoManageSwitch.connect('notify::active', self.on_auto_manage_changed) - ### STYLE PAGE ######################################################### - + def _build_style_page(self, builder): style_box = builder.get_object('style_box') + + style_box.add(self._new_dim_label(_("TODO explanation about css"))) self.css_manager = MdCSSSettings(self._settings, None, self) style_box.add(self.css_manager.full_widget) - ### BACKEND PAGE ####################################################### + style_box.add(Gtk.Separator(visible=True)) + + style_box.add(self._new_dim_label(_("TODO explanation about revealjs"))) + self.revealjs_manager = MdRevealjsSettings(self._settings, self) + style_box.add(self.revealjs_manager.full_widget) + def _new_dim_label(self, string): + label = Gtk.Label(visible=True, halign=Gtk.Align.START, label=string) + label.get_style_context().add_class('dim-label') + return label + + def _build_backend_page(self, builder): self._backend = MdBackendSettings(_("HTML generation backend:"), \ self._settings, True) builder.get_object('backend_box').add(self._backend.full_widget) @@ -474,17 +511,14 @@ def __init__(self, datadir, **kwargs): self.on_pandoc_format_changed(self._backend.format_combobox) self._backend.format_combobox.connect('changed', self.on_pandoc_format_changed) - ### SHORTCUTS PAGE ##################################################### - + def _build_shortcuts_page(self, builder): self.shortcuts_treeview = builder.get_object('shortcuts_treeview') renderer = builder.get_object('accel_renderer') renderer.connect('accel-edited', self.on_accel_edited) renderer.connect('accel-cleared', self.on_accel_cleared) -# https://github.com/GNOME/gtk/blob/master/gdk/keynames.txt + # https://github.com/GNOME/gtk/blob/master/gdk/keynames.txt for i in range(len(SETTINGS_KEYS)): self.add_keybinding(SETTINGS_KEYS[i], LABELS[i]) - self.add(sidebar) - self.add(stack) ############################################################################ @@ -521,7 +555,7 @@ def on_position_changed(self, w): self._settings.set_string('position', position) def on_auto_manage_changed(self, w, a): - self._settings.set_boolean('auto-manage-panel', w.get_state()) + self._settings.set_boolean('auto-manage-pane', w.get_state()) def update_css(self, is_active, uri): self._settings.set_boolean('use-style', is_active) @@ -536,13 +570,12 @@ def on_pandoc_format_changed(self, w): self._backend.remember_button.set_sensitive(output_format == 'custom') if output_format == 'custom': - command = self._settings.get_string('custom-export') + command = self._settings.get_string('custom-render') self._backend.set_pandoc_command(command) - self.output_extension = '.pdf' return - command = 'pandoc $INPUT_FILE %s -o $OUTPUT_FILE' - options = '' + command = 'pandoc $INPUT_FILE %s' + options = '--metadata pagetitle=Preview' accept_css = True # TODO........ if self.css_manager.switch_css.get_state() and accept_css: diff --git a/markdown_preview/preview.py b/markdown_preview/preview.py index 51d774c..9b71c73 100644 --- a/markdown_preview/preview.py +++ b/markdown_preview/preview.py @@ -53,10 +53,10 @@ def __init__(self, parent_plugin, **kwargs): def do_activate(self): self._handlers = [] self._settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE) - id1 = self._settings.connect('changed::position', self.change_panel) - id2 = self._settings.connect('changed::auto-manage-panel', self.set_auto_manage) + id0 = self._settings.connect('changed::position', self.change_panel) + id1 = self._settings.connect('changed::auto-manage-pane', self.set_auto_manage) + self._handlers.append(id0) self._handlers.append(id1) - self._handlers.append(id2) self.pagination_mode = 'whole' self.set_auto_manage() self.build_preview_ui() @@ -84,7 +84,7 @@ def do_update_state(self): self.on_reload() def do_deactivate(self): - self._webview.disconnect(self._handlers[4]) # XXX if useful, use elsewhere + self._webview.disconnect(self._handlers[4]) # XXX if it's useful, use this elsewhere self._webview.disconnect(self._handlers[3]) self._webview.disconnect(self._handlers[2]) self._settings.disconnect(self._handlers[1]) @@ -111,7 +111,7 @@ def on_set_reload(self, *args): self._settings.set_boolean('auto-reload', self.auto_reload) def set_auto_manage(self, *args): - self.auto_manage_panel = self._settings.get_boolean('auto-manage-panel') + self.auto_manage_panel = self._settings.get_boolean('auto-manage-pane') def set_action_enabled(self, action_name, state): self.parent_plugin.window.lookup_action(action_name).set_enabled(state) @@ -141,9 +141,12 @@ def build_preview_ui(self): # This is the preview itself self._webview = WebKit2.WebView() self._webview.get_settings().set_property('enable_javascript', True) - self._handlers.append( self._webview.connect('context-menu', self.on_context_menu) ) - self._handlers.append( self._webview.connect('mouse-target-changed', self.on_remember_scroll) ) - self._handlers.append( self._webview.connect('load-changed', self.on_restore_scroll) ) + id2 = self._webview.connect('context-menu', self.on_context_menu) + id3 = self._webview.connect('mouse-target-changed', self.on_remember_scroll) + id4 = self._webview.connect('load-changed', self.on_restore_scroll) + self._handlers.append(id2) + self._handlers.append(id3) + self._handlers.append(id4) preview_box.pack_start(self._webview, expand=True, fill=True, padding=0) # Displaying error messages @@ -311,12 +314,13 @@ def on_reload(self, *args): def get_html_from_html(self, unsaved_text): # CSS not applied if it's HTML + # XXX splitting breaks the default CSS, should i care? return self.current_page(unsaved_text, HTML_SPLITTERS) def get_html_from_tex(self, css_uri): doc = self.parent_plugin.window.get_active_document() file_path = doc.get_location().get_path() - # TODO FIXME splitters ? + # TODO implement splitters # It uses pandoc to produce the html code command = ['pandoc', '-s', file_path, '--metadata', 'pagetitle=Preview'] diff --git a/markdown_preview/revealjs_box.ui b/markdown_preview/revealjs_box.ui new file mode 100644 index 0000000..2408829 --- /dev/null +++ b/markdown_preview/revealjs_box.ui @@ -0,0 +1,9 @@ + + + + True + vertical + + + + diff --git a/org.gnome.gedit.plugins.markdown_preview.gschema.xml b/org.gnome.gedit.plugins.markdown_preview.gschema.xml index db84cc1..356511f 100644 --- a/org.gnome.gedit.plugins.markdown_preview.gschema.xml +++ b/org.gnome.gedit.plugins.markdown_preview.gschema.xml @@ -8,13 +8,13 @@ false - - + Use relative paths + Enable relative paths for links and pictures - + true - Show/hide panel automatically - If true, the panel will be shown/hidden automatically if no + Show/hide pane automatically + If true, the pane will be shown/hidden automatically if no other plugin is active in it. @@ -25,13 +25,18 @@ 'pandoc' Favorite backend for the preview - python or pandoc + Can be 'python' or 'pandoc' '' Custom export command + + '' + Custom rendering command + + false Use a stylesheet @@ -44,33 +49,33 @@ ['extra', 'sane_lists', 'toc'] - - + Enabled extensions + List of enabled extensions for python3-markdown - + slash']]]> Add italic markup - + B']]]> Add bold markup - + P']]]> Insert an image - + minus']]]> Use a lower level of title by adding a "#" tag - + plus']]]> Use a upper level of title by removing a "#" tag