Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gnome-builder
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Günther Wagner
gnome-builder
Commits
25f3c1ec
Commit
25f3c1ec
authored
Mar 14, 2017
by
Sébastien Lafargue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
html preview: add reStruccturedText support
To make it work, you need to have python3-docutils installed
parent
3b1a8402
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
plugins/html-preview/html-preview.plugin
plugins/html-preview/html-preview.plugin
+2
-2
plugins/html-preview/html_preview_plugin/__init__.py
plugins/html-preview/html_preview_plugin/__init__.py
+25
-3
No files found.
plugins/html-preview/html-preview.plugin
View file @
25f3c1ec
[Plugin]
Module=html_preview_plugin
Loader=python3
Name=HTML and Markdown Preview
Description=Live preview of HTML and Markdown documents.
Name=HTML
, reStructuredText
and Markdown Preview
Description=Live preview of HTML
, reStructuredText
and Markdown documents.
Authors=Christian Hergert <christian@hergert.me>
Copyright=Copyright © 2015 Christian Hergert
Builtin=true
...
...
plugins/html-preview/html_preview_plugin/__init__.py
View file @
25f3c1ec
...
...
@@ -34,6 +34,13 @@ from gi.repository import Ide
from
gi.repository
import
WebKit2
from
gi.repository
import
Peas
can_preview_rst
=
True
try
:
from
docutils.core
import
publish_string
except
ImportError
:
can_preview_rst
=
False
_
=
Ide
.
gettext
class
HtmlPreviewData
(
GObject
.
Object
,
Ide
.
ApplicationAddin
):
...
...
@@ -67,17 +74,23 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
actions
.
remove_action
(
'preview-as-html'
)
def
do_language_changed
(
self
,
language_id
):
enabled
=
(
language_id
in
(
'html'
,
'markdown'
))
enabled
=
(
language_id
in
(
'html'
,
'markdown'
,
'rst'
))
self
.
action
.
set_enabled
(
enabled
)
def
preview_activated
(
self
,
editor
):
document
=
editor
.
get_document
()
language
=
document
.
get_language
()
if
language
and
language
.
get_id
()
==
'rst'
and
not
can_preview_rst
:
return
view
=
HtmlPreviewView
(
document
,
visible
=
True
)
stack
=
editor
.
get_ancestor
(
Ide
.
LayoutStack
)
stack
.
add
(
view
)
class
HtmlPreviewView
(
Ide
.
LayoutView
):
markdown
=
False
rst
=
False
def
__init__
(
self
,
document
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -90,8 +103,12 @@ class HtmlPreviewView(Ide.LayoutView):
settings
.
enable_html5_local_storage
=
False
language
=
document
.
get_language
()
if
language
and
language
.
get_id
()
==
'markdown'
:
self
.
markdown
=
True
if
language
:
id
=
language
.
get_id
()
if
id
==
'markdown'
:
self
.
markdown
=
True
elif
id
==
'rst'
:
self
.
rst
=
True
document
.
connect
(
'changed'
,
self
.
on_changed
)
self
.
on_changed
(
document
)
...
...
@@ -125,6 +142,9 @@ class HtmlPreviewView(Ide.LayoutView):
</html>
"""
%
params
def
get_rst
(
self
,
text
):
return
publish_string
(
text
,
writer_name
=
'html5'
)
def
reload
(
self
):
base_uri
=
self
.
document
.
get_file
().
get_file
().
get_uri
()
...
...
@@ -133,6 +153,8 @@ class HtmlPreviewView(Ide.LayoutView):
if
self
.
markdown
:
text
=
self
.
get_markdown
(
text
)
elif
self
.
rst
:
text
=
self
.
get_rst
(
text
).
decode
(
"utf-8"
)
self
.
webview
.
load_html
(
text
,
base_uri
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment