Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a67b55d
Showing
104 changed files
with
12,205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/rstpad.local.pro | ||
/rstpad.pro.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2016 Pavel Batečko (ShiraNai7) | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
RSTPad | ||
###### | ||
|
||
reStructuredText editor with live preview. | ||
|
||
.. image:: screenshot.jpg | ||
|
||
.. contents:: | ||
|
||
|
||
Features | ||
******** | ||
|
||
- live preview with autoscroll | ||
|
||
- configurable orientation (horizontal / vertical) | ||
|
||
- search & replace | ||
|
||
- toolbar with common elements: | ||
|
||
- headings | ||
- bold, italic | ||
- inline code | ||
- code blocks | ||
- horizontal rule | ||
- lists | ||
- link | ||
- image | ||
|
||
- inserting highlighted code blocks (Pygments) | ||
|
||
- autocomplete for known lexer names | ||
|
||
- built-in help pages | ||
|
||
- syntax cheat sheet | ||
- directives | ||
|
||
- export to PDF | ||
|
||
|
||
|
||
Known limitations | ||
***************** | ||
|
||
- UTF-8 documents only | ||
|
||
|
||
Implementation details | ||
********************** | ||
|
||
- the application contains an embedded Python interpreter | ||
|
||
- Python libraries are located in the application's directory / bundle | ||
|
||
- the Docutils library is used to convert RST to HTML on the fly | ||
|
||
- the converstion is done in a separate thread | ||
- *resources/preview/docutils_extensions.py* overrides some of the HTML writer's methods to insert additional tags and attributes | ||
|
||
- HTML output is displayed using Qt WebEngine | ||
|
||
- external links are delegated to QDesktopServices | ||
- autoscroll is implemented in JavaScript | ||
- the preview is "frozen" during loading and autoscrolling to allow for smooth transitions (a previously rendered frame is used for the duration) | ||
|
||
|
||
Compilation | ||
*********** | ||
|
||
Prerequisites | ||
============= | ||
|
||
- QT 5.7 & Qt Creator | ||
- Python 2.7 (32bit or 64bit depending the used compiler) | ||
- `Pygments <https://pypi.python.org/pypi/Pygments>`_ (tested with 2.1.3) | ||
- `Docutils <https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/>`_ (tested with 0.13, revision 7975) | ||
|
||
|
||
Build configuration | ||
=================== | ||
|
||
.. NOTE:: | ||
- OS X notes and examples assume that Python 2.7 has been installed using Homebrew. | ||
- The paths used below (such as *C:/python*) are just examples. Use actual paths :) | ||
- Use forward slashes in all paths. Omit trailing slashes. | ||
|
||
Copy *rstpad.local.pro.dist*, name it *rstpad.local.pro* and set the following variables: | ||
|
||
- ``PYTHON_LINK`` | ||
|
||
- Python linker flags | ||
- Windows: ``-LC:/python/libs -lpython27`` | ||
- OS X: use the `python-config <http://manpages.ubuntu.com/manpages/precise/man1/python-config.1.html>`_ utility to determine linker flags: | ||
|
||
- ``python2.7-config --ldflags`` | ||
|
||
- ``PYTHON_INCLUDE_PATH`` | ||
|
||
- path to a directory containing Python's header files | ||
|
||
- Windows: ``C:/python/include`` | ||
- OS X: ``/usr/include/python2.7`` | ||
|
||
- ``PYTHON_SYS_PATH`` | ||
|
||
- path to a directory containing: | ||
|
||
- ``libs.zip`` - the Python standard library as a ZIP archive | ||
- ``pygments``, ``docutils`` - library directories (these cannot be inside *libs.zip*) | ||
- any *.pyd*, *.dll* and *.so* modules that should be available in a standard Python installation | ||
|
||
- *.pyc* files should be excluded | ||
|
||
|
||
Windows deployment | ||
================== | ||
|
||
#. Use the `Windows Deployment Tool <http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool>`_ with the release binary to fetch required DLLs. | ||
|
||
Example: ``windeployqt.exe --release --no-translations rstpad.exe`` | ||
|
||
#. Locate and copy the correct ``python27.dll`` file or the application won't work on machines without Python 2.7 installed. | ||
|
||
- possible locations depend on how you've installed Python and on its version: | ||
|
||
- *C:\\Windows\\System\\python27.dll* | ||
- *C:\\Windows\\SysWoW64\\python27.dll* | ||
|
||
- make sure you're ussing the correct version (32 vs 64bit) | ||
|
||
|
||
OS X deployment | ||
=============== | ||
|
||
Use the `Mac Deployment Tool <http://doc.qt.io/qt-5/osx-deployment.html#the-mac-deployment-tool>`_ to convert the resulting application into a *.dmg* file: | ||
|
||
:: | ||
|
||
macdeployqt RSTPad.app -dmg | ||
|
||
|
||
Other platforms | ||
=============== | ||
|
||
Not tested yet. You're on your own :) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
global Node | ||
|
||
import docutils.writers.html5_polyglot as html_writer | ||
from docutils.nodes import Node | ||
|
||
# store original methods | ||
global orig_starttag | ||
global orig_visit_document | ||
|
||
orig_starttag = html_writer.HTMLTranslator.starttag | ||
orig_visit_document = html_writer.HTMLTranslator.visit_document | ||
|
||
# starttag() override | ||
def starttag(self, node, tagname, suffix='\n', empty=False, **attributes): | ||
# define the data-line attribute if this is a Node with a known line | ||
line = None | ||
|
||
if isinstance(node, Node): | ||
line = node.line | ||
|
||
if line is None and node.parent is not None: | ||
line = node.parent.line | ||
|
||
if line is not None: | ||
attributes['data-line'] = str(node.line) | ||
|
||
return orig_starttag(self, node, tagname, suffix, empty, **attributes) | ||
|
||
# visit_document() override | ||
def visit_document(self, node): | ||
self.head.append('<link rel="stylesheet" type="text/css" href="qrc:///preview/preview.css">') | ||
self.head.append('<script type="text/javascript" src="qrc:///preview/preview.js"></script>') | ||
orig_visit_document(self, node) | ||
|
||
# replace methods | ||
html_writer.HTMLTranslator.starttag = starttag | ||
html_writer.HTMLTranslator.visit_document = visit_document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Global */ | ||
body { | ||
margin: 0 !important; | ||
padding: 1em !important; | ||
font-family: sans-serif; | ||
} | ||
h1:first-child { | ||
margin-top: 0 !important; | ||
} | ||
.document { | ||
max-width: 950px !important; | ||
margin-left: 0 !important; | ||
margin-right: 0 !important; | ||
} | ||
blockquote { | ||
border-left: 4px solid #d5d5d5; | ||
padding-left: 14px; | ||
} | ||
|
||
/* RST renderer exception */ | ||
.rst-exception { | ||
margin: 40px; | ||
border: medium outset; | ||
padding-right: 1em; | ||
padding-left: 1em; | ||
} | ||
.rst-exception pre { | ||
overflow: auto; | ||
} | ||
.rst-exception-message { | ||
white-space: pre-wrap; | ||
font-weight: bold; | ||
font-family: sans-serif; | ||
color: red; | ||
} | ||
.rst-exception-trace { | ||
font-size: smaller; | ||
color: gray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Logic invoked from C++ code | ||
*/ | ||
class RstPadApi { | ||
/** | ||
* @param {Number} position | ||
*/ | ||
static scrollToPosition(position) { | ||
window.scrollTo(0, position); | ||
} | ||
|
||
/** | ||
* @param {Number} line | ||
*/ | ||
static scrollToLine(line) { | ||
let position = this.getPositionForLine(line); | ||
|
||
if (null !== position) { | ||
this.scrollToPosition(position); | ||
} | ||
} | ||
|
||
/** | ||
* @param {Number} line | ||
* @returns {Number|null} | ||
*/ | ||
static getPositionForLine(line) { | ||
let map = this.getLineMap(); | ||
|
||
//console.log('getPositionForLine ' + line); | ||
|
||
// try to use element at the exact line | ||
if (map[line]) { | ||
//console.log('found exact element for line ' + line); | ||
return this.getElementPosition(map[line]); | ||
} | ||
|
||
// find the nearest lines | ||
let nearestPrevLine = null; | ||
let nearestNextLine = null; | ||
|
||
for (let mappedLine in map) { | ||
if (map.hasOwnProperty(mappedLine)) { | ||
mappedLine = mappedLine / 1; | ||
//console.log('mappedLine = ' + mappedLine + '(' + typeof(mappedLine) + ') nearestPrevLine = ' + nearestPrevLine + ' nearestNextLine = ' + nearestNextLine); | ||
|
||
if (mappedLine < line) { | ||
if (null === nearestPrevLine || mappedLine > nearestPrevLine) { | ||
nearestPrevLine = mappedLine; | ||
} | ||
} else if (null === nearestNextLine || mappedLine < nearestNextLine) { | ||
nearestNextLine = mappedLine; | ||
} | ||
} | ||
} | ||
|
||
//console.log('nearestPrevLine = ' + nearestPrevLine + ' nearestNextLine = ' + nearestNextLine); | ||
|
||
// estimate a position between the previous and next lines | ||
if (nearestPrevLine && nearestNextLine) { | ||
let prevElemPos = this.getElementPosition(map[nearestPrevLine], 'bottom'); | ||
let nextElemPos = this.getElementPosition(map[nearestNextLine], 'top'); | ||
|
||
//console.log('prevElemPos = ' + prevElemPos + ' nextElemPos = ' + nextElemPos); | ||
//console.log('percentage = ' + ((line - nearestPrevLine) / (nearestNextLine - nearestPrevLine))); | ||
|
||
if (prevElemPos < nextElemPos) { | ||
return prevElemPos + (nextElemPos - prevElemPos) * (line - nearestPrevLine) / (nearestNextLine - nearestPrevLine); | ||
} | ||
} | ||
|
||
// only one of the lines was found or the positions are unexpected | ||
if (nearestPrevLine || nearestNextLine) { | ||
//console.log('using one of the lines = ' + (nearestPrevLine || nearestNextLine)); | ||
return this.getElementPosition(map[nearestPrevLine || nearestNextLine]); | ||
} | ||
|
||
// failure | ||
//console.log('failure'); | ||
return null; | ||
} | ||
|
||
/** | ||
* @returns {Object} line => HTMLElement | ||
*/ | ||
static getLineMap() { | ||
if (!this._lineMap) { | ||
this._lineMap = {} | ||
let elements = document.querySelectorAll('*[data-line]'); | ||
|
||
for (let i = 0; i < elements.length; ++i) { | ||
this._lineMap[elements[i].dataset.line] = elements[i]; | ||
} | ||
} | ||
|
||
return this._lineMap; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} elem | ||
* @param {String} type | ||
* @returns {Number} | ||
*/ | ||
static getElementPosition(elem, type = 'top') { | ||
return window.pageYOffset + elem.getBoundingClientRect()[type]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
import docutils.core | ||
|
||
execfile(os.path.dirname(os.path.realpath(__file__)) + '/docutils_extensions.py') | ||
|
||
source = """ | ||
Hello | ||
===== | ||
How are you | ||
"""; | ||
|
||
print docutils.core.publish_string(source, None, None, None, 'standalone', None, 'restructuredtext', None, 'html5', None, None, {'output_encoding': 'unicode'}) |
Oops, something went wrong.