Skip to content

Commit

Permalink
Update the readme
Browse files Browse the repository at this point in the history
and split the prefs in 4 pages instead of 3
  • Loading branch information
maoschanz committed Feb 8, 2020
2 parents ea2fccf + b050905 commit f501a73
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 137 deletions.
102 changes: 70 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

<!-- TODO
- [ ] comment retirer le fichier CSS ??
- [ ] connecter le switch des préférences
- [x] code dans preview.py
- [ ] pages séparées (général/style)
- [ ] help labels and links for pandoc too! et toutes les pages en fait
- [ ] CSS for admonitions (and other default plugins ?)
- [ ] and pymdown ??
Expand All @@ -18,26 +14,47 @@
- [ ] se souvenir du splitter
- [ ] ajouter le réglage pour le splitter dans les préférences
- [ ] bring back the fullscreen, but better
- [ ] style broken with paginated HTML
~ TODO -->

This is a plugin for the Gedit text editor, previewing .md files in the side (`F9`) or the bottom (`Ctrl+F9`) pane.

<!-- Main features (version 0.8): -->

- Previewing:
- show a preview of a file
- dynamically update the preview
- zoom in or out on the preview
- search in the preview
- open links and image
- Exporting:
- print the preview
- export to any file format supported by [pandoc](https://pandoc.org/)
- or export to HTML with `python3-markdown` and its [extensions](https://python-markdown.github.io/extensions/)
- Edition assistance:
- insert an image in your file
- insert markdown tags in your text with right-click menu or keyboard shortcuts
## Main features

### Previewing

- show a preview of a file
- dynamically update the preview
- zoom in or out on the preview
- search in the preview
- open links and images

This works for Markdown files, HTML files, and theorically LaTeX files.

### Exporting

You can print the preview, or export it:

- if [pandoc](https://pandoc.org/) is installed on your system, you can export to any format it supports
- a stylesheet can be applied to most file formats
- options are available when exporting to a [https://revealjs.com](revealjs) slideshow (**WORK IN PROGRESS**)
- if only `python3-markdown` is installed, you can export to HTML
- a stylesheet can be applied
- `python3-markdown` [extensions](https://python-markdown.github.io/extensions/) can be used (including [third-party extensions](https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions) like [these great ones](https://facelessuser.github.io/pymdown-extensions/)

### Editing assistance

- insert an image in your file
- insert markdown tags in your text with right-click menu or keyboard shortcuts

----

## Screenshots

![With the preview in the side pane, menu opened](https://i.imgur.com/wo2pUrR.png)

![With the preview in the bottom pane, searching](https://i.imgur.com/NaVogWH.png)

----

Expand Down Expand Up @@ -82,26 +99,47 @@ The plugin's options can be accessed…
- from Gedit's preferences → Plugins → Markdown preview → Preferences
- or with the extension's "3-dots menu" → Options

Available settings include:
### General options

- The preview can be generated (and exported) with [pandoc](https://pandoc.org/) or [python-markdown](https://python-markdown.github.io/). A set of [extensions](https://python-markdown.github.io/extensions/) is provided with python-markdown.
- A stylesheet (CSS file) can be applied to the preview.
- Choose if you want the plugin to understand relative paths (for links and pictures). Not recommended if you use special characters in filenames (WebKit2GTK can't load URIs with special characters for some reason)
- Set keyboard shortcuts to add/remove tags *(beta)*
- Select the position of the pane
- Choose if you want the plugin to understand relative paths (for links and pictures). Not recommended if you use special characters in filenames (some versions of WebKit2GTK can't load URIs with special characters for some reason)

## Available languages
### Rendering options

- English
- French
- Dutch
The preview can be generated with [pandoc](https://pandoc.org/) or [python-markdown](https://python-markdown.github.io/).

----
##### Options with pandoc

## Screenshots
You can decide to render the file as classic HTML (it may then use the CSS file you set) or as HTML with the stylesheet and javascript code from _revealjs_. (**WORK IN PROGRESS**)

A third "custom" option is possible: be sure to write a full, correct command whose output will be HTML, press "Remember" to save your custom command. (**WORK IN PROGRESS**)

##### Options with python-markdown

A set of [extensions](https://python-markdown.github.io/extensions/) is provided natively with python-markdown. You can enable or disable them depending on your needs.

[Great third-party extensions](https://facelessuser.github.io/pymdown-extensions/) exist too, and once installed they can be added manually to the list.

### Style

A stylesheet (CSS file) can be applied to the preview.

- doesn't work when previewing HTML files
- doesn't work if you preview the file as a revealjs slideshow

![With the preview in the side panel, menu opened](https://i.imgur.com/wo2pUrR.png)
<!--TODO-->
<!--revealjs options-->

![With the preview in the bottom panel, searching](https://i.imgur.com/NaVogWH.png)
### Keyboard shortcuts

Set keyboard shortcuts to add/remove tags (**WORK IN PROGRESS**)

----

## Available languages

- English
- French
- Dutch


10 changes: 6 additions & 4 deletions markdown_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def remove_menu(self):
self.menu_ext_view = None # XXX ?

def add_all_accelerators(self):
self._settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE)
self._kb_settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE + '.keybindings')
for i in range(len(SETTINGS_KEYS)):
self.add_one_accelerator(SETTINGS_KEYS[i], ACTIONS_NAMES[i])

def add_one_accelerator(self, setting_key, action_name):
accels = self._settings.get_strv(setting_key)
accels = self._kb_settings.get_strv(setting_key)
if len(accels) > 0:
self.app.add_accelerator(accels[0], action_name, None)

Expand All @@ -83,8 +83,10 @@ def __init__(self):
def do_activate(self):
self._handlers = []
self._settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE)
self._handlers.append( self.window.connect('active-tab-changed', self.preview.on_file_changed) )
self._handlers.append( self.window.connect('active-tab-state-changed', self.preview.on_file_changed) )
sig_id0 = self.window.connect('active-tab-changed', self.preview.on_file_changed)
self._handlers.append(sig_id0)
sig_id1 = self.window.connect('active-tab-state-changed', self.preview.on_file_changed)
self._handlers.append(sig_id1)
self.connect_actions()
self.preview.do_activate()

Expand Down
8 changes: 4 additions & 4 deletions markdown_preview/css_box.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<object class="GtkBox" id="css_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<property name="spacing">16</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="spacing">12</property>
<property name="spacing">16</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand All @@ -31,7 +31,7 @@
<object class="GtkBox" id="css_sensitive_box">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="spacing">12</property>
<property name="spacing">16</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand All @@ -45,7 +45,7 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">5</property>
<property name="spacing">8</property>
<child>
<object class="GtkLabel" id="style_label">
<property name="visible">True</property>
Expand Down
36 changes: 18 additions & 18 deletions markdown_preview/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,13 @@ 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 ??
# TODO slide numbers option ??
# options = options + ' -V theme=moon -V transition=cube'
# options = options + ' -V showSlideNumber=all' # XXX ne marche pas
# beige black blood league moon night serif simple sky solarized white
self.output_extension = '.html'
# accept_css = False # XXX ?
accept_css = False # in fact, it does accept a stylesheet as an
# option, but the 2 CSS will often be incompatible.
else:
options = '-t ' + output_format
if output_format == 'beamer' or output_format == 'latex':
Expand Down Expand Up @@ -391,20 +395,14 @@ def export_p3md(self):
start, end = doc.get_bounds()
unsaved_text = doc.get_text(start, end, True)
content = markdown.markdown(unsaved_text, extensions=md_extensions)
# FIXME code complètement con ci-après
with open(file_chooser.get_filename(), 'w') as f:
f.write(content)
if self.css_manager.switch_css.get_active():
pre_string = '<html><head><meta charset="utf-8" />' + \
'<link rel="stylesheet" href="' + self.css_manager.css_uri + \
'" /></head><body>'
post_string = '</body></html>'
with open(file_chooser.get_filename(), 'r+') as f:
content = f.read()
f.seek(0, 0)
f.write(pre_string.rstrip('\r\n') + '\n' + content)
with open(file_chooser.get_filename(), 'a') as f:
f.write(post_string)
content = pre_string + content + post_string
with open(file_chooser.get_filename(), 'w') as f:
f.write(content)
file_chooser.destroy()
return True

Expand Down Expand Up @@ -435,15 +433,16 @@ def __init__(self, datadir, **kwargs):
# print(datadir) # TODO c'est le path de là où est le plugin, ça peut
# aider à mettre un css par défaut ?
self._settings = Gio.Settings.new(MD_PREVIEW_KEY_BASE)
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
stack = builder.get_object('stack')
sidebar = Gtk.StackSidebar(stack=stack)

### PREVIEW PAGE #######################################################
### GENERAL PAGE #######################################################

preview_box = builder.get_object('preview_box')
general_box = builder.get_object('general_box')

positionCombobox = builder.get_object('positionCombobox')
positionCombobox.append('auto', _("Automatic"))
Expand All @@ -460,10 +459,11 @@ def __init__(self, datadir, **kwargs):
autoManageSwitch.set_state(self._settings.get_boolean('auto-manage-panel'))
autoManageSwitch.connect('notify::active', self.on_auto_manage_changed)

preview_box.add(Gtk.Separator(visible=True))
### STYLE PAGE #########################################################

style_box = builder.get_object('style_box')
self.css_manager = MdCSSSettings(self._settings, None, self)
preview_box.add(self.css_manager.full_widget)
style_box.add(self.css_manager.full_widget)

### BACKEND PAGE #######################################################

Expand All @@ -489,7 +489,7 @@ def __init__(self, datadir, **kwargs):
############################################################################

def add_keybinding(self, setting_id, description):
accelerator = self._settings.get_strv(setting_id)[0]
accelerator = self._kb_settings.get_strv(setting_id)[0]
if accelerator is None:
[key, mods] = [0, 0]
else:
Expand All @@ -502,13 +502,13 @@ def on_accel_edited(self, *args):
self.shortcuts_treeview.get_model().set(tree_iter, [2, 3], [args[2], int(args[3])])
setting_id = self.shortcuts_treeview.get_model().get_value(tree_iter, 0)
accelString = Gtk.accelerator_name(args[2], args[3])
self._settings.set_strv(setting_id, [accelString])
self._kb_settings.set_strv(setting_id, [accelString])

def on_accel_cleared(self, *args):
tree_iter = self.shortcuts_treeview.get_model().get_iter_from_string(args[1])
self.shortcuts_treeview.get_model().set(tree_iter, [2, 3], [0, 0])
setting_id = self.shortcuts_treeview.get_model().get_value(tree_iter, 0)
self._settings.set_strv(setting_id, [])
self._kb_settings.set_strv(setting_id, [])

############################################################################
# Preview options ##########################################################
Expand Down
Binary file not shown.
Loading

0 comments on commit f501a73

Please sign in to comment.