Permalink
Browse files

Initial commit

  • Loading branch information...
ShiraNai7 committed Nov 19, 2016
0 parents commit a67b55dddeccf180c367ca94f4eb10f4c6c6f7ce
Showing with 12,205 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +22 −0 LICENSE
  3. +147 −0 README.rst
  4. BIN resources/icons/arrow-right.png
  5. BIN resources/icons/bold.png
  6. BIN resources/icons/code-block-pygments.png
  7. BIN resources/icons/code-block.png
  8. BIN resources/icons/code.png
  9. BIN resources/icons/copy.png
  10. BIN resources/icons/cut.png
  11. BIN resources/icons/find-next.png
  12. BIN resources/icons/find-prev.png
  13. BIN resources/icons/find.png
  14. BIN resources/icons/floppy.png
  15. BIN resources/icons/folder.png
  16. BIN resources/icons/h1.png
  17. BIN resources/icons/h2.png
  18. BIN resources/icons/h3.png
  19. BIN resources/icons/h4.png
  20. BIN resources/icons/h5.png
  21. BIN resources/icons/h6.png
  22. BIN resources/icons/help.png
  23. BIN resources/icons/hr.png
  24. BIN resources/icons/image.png
  25. BIN resources/icons/info.png
  26. BIN resources/icons/italic.png
  27. BIN resources/icons/link.png
  28. BIN resources/icons/main.icns
  29. BIN resources/icons/main.ico
  30. BIN resources/icons/main.png
  31. BIN resources/icons/ol.png
  32. BIN resources/icons/page.png
  33. BIN resources/icons/paste.png
  34. BIN resources/icons/pdf.png
  35. BIN resources/icons/qt.png
  36. BIN resources/icons/redo.png
  37. BIN resources/icons/ul.png
  38. BIN resources/icons/undo.png
  39. BIN resources/icons/wrench.png
  40. +37 −0 resources/preview/docutils_extensions.py
  41. +39 −0 resources/preview/preview.css
  42. +108 −0 resources/preview/preview.js
  43. +15 −0 resources/preview/test.py
  44. +48 −0 resources/resources.qrc
  45. BIN resources/splash.png
  46. BIN resources/syntax-help/ball1.gif
  47. BIN resources/syntax-help/biohazard.png
  48. +3,438 −0 resources/syntax-help/directives.html
  49. +105 −0 resources/syntax-help/html4css1.css
  50. +1,308 −0 resources/syntax-help/quickref.html
  51. +7 −0 rstpad.local.pro.dist
  52. +101 −0 rstpad.pro
  53. +1 −0 rstpad.rc
  54. BIN screenshot.jpg
  55. +251 −0 src/App.cpp
  56. +69 −0 src/App.h
  57. +90 −0 src/AppSchemeHandler.cpp
  58. +23 −0 src/AppSchemeHandler.h
  59. +153 −0 src/Config.cpp
  60. +53 −0 src/Config.h
  61. +254 −0 src/FileManager.cpp
  62. +53 −0 src/FileManager.h
  63. +128 −0 src/PreviewManager.cpp
  64. +51 −0 src/PreviewManager.h
  65. +446 −0 src/PythonBridge.cpp
  66. +50 −0 src/PythonBridge.h
  67. +37 −0 src/PythonException.cpp
  68. +30 −0 src/PythonException.h
  69. +274 −0 src/PythonRunner.cpp
  70. +149 −0 src/RstRenderer.cpp
  71. +46 −0 src/RstRenderer.h
  72. +59 −0 src/UI/Code/CodeEdit.cpp
  73. +29 −0 src/UI/Code/CodeEdit.h
  74. +462 −0 src/UI/Code/EditManipulator.cpp
  75. +43 −0 src/UI/Code/EditManipulator.h
  76. +531 −0 src/UI/MainWindow.cpp
  77. +102 −0 src/UI/MainWindow.h
  78. +525 −0 src/UI/MainWindow.ui
  79. +78 −0 src/UI/PreviewView.cpp
  80. +33 −0 src/UI/PreviewView.h
  81. +672 −0 src/UI/PygmentLexersDlg.cpp
  82. +31 −0 src/UI/PygmentLexersDlg.h
  83. +95 −0 src/UI/PygmentLexersDlg.ui
  84. +9 −0 src/UI/SearchJob.cpp
  85. +30 −0 src/UI/SearchJob.h
  86. +75 −0 src/UI/SearchReplaceDlg.cpp
  87. +42 −0 src/UI/SearchReplaceDlg.h
  88. +264 −0 src/UI/SearchReplaceDlg.ui
  89. +221 −0 src/UI/SearchReplaceHandler.cpp
  90. +45 −0 src/UI/SearchReplaceHandler.h
  91. +18 −0 src/UI/SearchTextDlg.cpp
  92. +26 −0 src/UI/SearchTextDlg.h
  93. +209 −0 src/UI/SearchTextDlg.ui
  94. +125 −0 src/UI/SettingsDlg.cpp
  95. +43 −0 src/UI/SettingsDlg.h
  96. +536 −0 src/UI/SettingsDlg.ui
  97. +93 −0 src/UI/SyntaxHelpWindow.cpp
  98. +43 −0 src/UI/SyntaxHelpWindow.h
  99. +162 −0 src/UI/SyntaxHelpWindow.ui
  100. +21 −0 src/UI/WebPage.cpp
  101. +19 −0 src/UI/WebPage.h
  102. +3 −0 src/UI/uiresources.qrc
  103. +16 −0 src/main.cpp
  104. +10 −0 src/python.cpp
@@ -0,0 +1,2 @@
/rstpad.local.pro
/rstpad.pro.user
22 LICENSE
@@ -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.
@@ -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 :)
Binary file not shown.
BIN +304 Bytes resources/icons/bold.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +441 Bytes resources/icons/code.png
Binary file not shown.
BIN +309 Bytes resources/icons/copy.png
Binary file not shown.
BIN +648 Bytes resources/icons/cut.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +659 Bytes resources/icons/find.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +276 Bytes resources/icons/h1.png
Binary file not shown.
BIN +304 Bytes resources/icons/h2.png
Binary file not shown.
BIN +306 Bytes resources/icons/h3.png
Binary file not shown.
BIN +293 Bytes resources/icons/h4.png
Binary file not shown.
BIN +304 Bytes resources/icons/h5.png
Binary file not shown.
BIN +310 Bytes resources/icons/h6.png
Binary file not shown.
BIN +786 Bytes resources/icons/help.png
Binary file not shown.
BIN +317 Bytes resources/icons/hr.png
Binary file not shown.
BIN +516 Bytes resources/icons/image.png
Binary file not shown.
BIN +778 Bytes resources/icons/info.png
Binary file not shown.
Binary file not shown.
BIN +343 Bytes resources/icons/link.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +357 Bytes resources/icons/ol.png
Diff not rendered.
BIN +294 Bytes resources/icons/page.png
Diff not rendered.
BIN +605 Bytes resources/icons/paste.png
Diff not rendered.
BIN +459 Bytes resources/icons/pdf.png
Diff not rendered.
BIN +646 Bytes resources/icons/qt.png
Diff not rendered.
BIN +625 Bytes resources/icons/redo.png
Diff not rendered.
BIN +344 Bytes resources/icons/ul.png
Diff not rendered.
BIN +631 Bytes resources/icons/undo.png
Diff not rendered.
Diff not rendered.
@@ -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
@@ -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;
}
@@ -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];
}
}
@@ -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.

0 comments on commit a67b55d

Please sign in to comment.