Skip to content

Commit

Permalink
Merge pull request #12 from joshp23/joshp23-extras
Browse files Browse the repository at this point in the history
add all "extras"
  • Loading branch information
aliva authored Oct 6, 2019
2 parents a5d4b62 + d70c26a commit d30ccef
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
# Gedit Markdown Preview

## Install
This plugin depends on the `python3-markdown` package (install via your preferred method)

```sh
mkdir -p ~/.local/share/gedit/plugins/
cd ~/.local/share/gedit/plugins/
git clone https://github.com/aliva/gedit-markdownpreview.git markdownpreview
```

You need to install `python3-markdown` for this plugin.
Optionally install `pymdown-extensions` for extra utility with:
`pip3 install pymdown-extensions`

Tested on gedit 3.30.2

## Features:
This plugin supports standard Markdown, plus:
- [Code Highlighting](https://python-markdown.github.io/extensions/code_hilite/)
- [Abbreviations](https://python-markdown.github.io/extensions/abbreviations/)
- [Attribute Lists](https://python-markdown.github.io/extensions/attr_list/)
- [Definition Lists](https://python-markdown.github.io/extensions/definition_lists/)
- [Fenced Code Blocks](https://python-markdown.github.io/extensions/fenced_code_blocks/)
- [Footnotes](https://python-markdown.github.io/extensions/footnotes/)
- [Tables](https://python-markdown.github.io/extensions/tables/)

With optional `pymdown-extensions`:
- [Caret](https://facelessuser.github.io/pymdown-extensions/extensions/caret/) superscripting
- [Better Emphasis](https://facelessuser.github.io/pymdown-extensions/extensions/betterem/) for bold, itallic, and underscore
- [SuperFences](https://facelessuser.github.io/pymdown-extensions/extensions/superfences/) Improved Fenced Code Blocks
- [extrarawHTML](https://facelessuser.github.io/pymdown-extensions/extensions/extrarawhtml/) to Parse MD inside HTML blocks
- [Mark](https://facelessuser.github.io/pymdown-extensions/extensions/mark/) for simple highlighting
- [Task Lists](https://facelessuser.github.io/pymdown-extensions/extensions/tasklist/)
- [Tilde](https://facelessuser.github.io/pymdown-extensions/extensions/tilde/) for subscripting and strikethrough

## Usage

When viewing a markdown file press `ctrl+alt+m` to toggle markdown preview
Expand Down
49 changes: 35 additions & 14 deletions markdownpreview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from string import Template

import importlib.util

import gi
from markdown import markdown
from markdown.extensions import Extension
Expand Down Expand Up @@ -149,21 +151,40 @@ def buffer_changed(self, buffer, view):
buffer.get_end_iter(),
True,
)
html = markdown(
text,
extensions=[
'codehilite',
'fenced_code',
'tables',
AutoDirectionExtension(),
],
extension_configs={
'codehilite': {
'linenums': False,
'noclasses': True,
if importlib.util.find_spec('pymdownx') is not None:
html = markdown(
text,
extensions=[
'pymdownx.caret',
'pymdownx.extra',
'pymdownx.mark',
'pymdownx.tasklist',
'pymdownx.tilde',
'codehilite',
AutoDirectionExtension(),
],
extension_configs={
'codehilite': {
'linenums': False,
'noclasses': True,
}
}
}
)
)
else:
html = markdown(
text,
extensions=[
'extra',
'codehilite',
AutoDirectionExtension(),
],
extension_configs={
'codehilite': {
'linenums': False,
'noclasses': True,
}
}
)
html = Template(self.html_template).substitute(
content=html,
style=self.style_template,
Expand Down

0 comments on commit d30ccef

Please sign in to comment.