From 03984c1a5ca2bac2d167f7c714780a4093db25b5 Mon Sep 17 00:00:00 2001
From: Pouria Hadjibagheri
Date: Tue, 25 Apr 2017 10:42:00 +0100
Subject: [PATCH] Minor corrections.
---
dev.py | 50 +++----
dev.xml | 314 +++++++++++++++++++++++++++++++++++++++++-
markdownx/__init__.py | 2 +-
3 files changed, 333 insertions(+), 33 deletions(-)
diff --git a/dev.py b/dev.py
index 97f4370..39d0f6e 100644
--- a/dev.py
+++ b/dev.py
@@ -144,7 +144,7 @@ def from_terminal(subject):
def create_files(name):
from xml.etree.ElementTree import parse
- from xml.sax.saxutils import escape
+ from xml.sax.saxutils import escape, unescape
contents_xml = parse(XML_FILE_ABSOLUTE_PATH)
root = contents_xml.getroot()
@@ -161,18 +161,18 @@ def create_files(name):
with open(absolute_path, mode='r') as data_file:
file_io = data_file.read()
- contents_identical = template_contents.rstrip().lstrip() == file_io.rstrip().lstrip()
+ contents_identical = template_contents.strip() == escape(file_io.strip())
if not contents_identical and replace_contents_or_not(display_path):
file.find('contents').text = escape(file_io)
elif not contents_identical:
with open(absolute_path, mode='w') as file_io:
- file_io.write(template_contents + '\n')
+ file_io.write(unescape(template_contents) + '\n')
print('> REPLACED with default:', display_path)
else:
with open(absolute_path, mode='w') as target_file:
- target_file.write(template_contents)
+ target_file.write(unescape(template_contents))
print('> CREATED:', display_path)
@@ -180,19 +180,13 @@ def create_files(name):
st = stat(absolute_path)
chmod(absolute_path, st.st_mode | S_IEXEC)
- try:
- contents_xml.write(
- file_or_filename=XML_FILE_ABSOLUTE_PATH,
- xml_declaration=True,
- encoding='unicode',
- method='xml'
- )
- except LookupError:
- contents_xml.write(
- file_or_filename=XML_FILE_ABSOLUTE_PATH,
- xml_declaration=True,
- method='xml'
- )
+ contents_xml.write(
+ file_or_filename=XML_FILE_ABSOLUTE_PATH,
+ xml_declaration=True,
+ encoding='UTF-8',
+ method='xml'
+ )
+
return True
@@ -233,7 +227,7 @@ def clean():
with open(absolute_path, mode='r') as data_file:
file_content = data_file.read()
- if file.find('contents').text.rstrip().lstrip() == file_content.rstrip().lstrip():
+ if file.find('contents').text.strip() == escape(file_content.strip()):
delete(absolute_path, display_path)
continue
@@ -245,19 +239,13 @@ def clean():
delete(absolute_path, display_path)
- try:
- contents_xml.write(
- file_or_filename=XML_FILE_ABSOLUTE_PATH,
- xml_declaration=True,
- encoding='unicode',
- method='xml'
- )
- except LookupError:
- contents_xml.write(
- file_or_filename=XML_FILE_ABSOLUTE_PATH,
- xml_declaration=True,
- method='xml'
- )
+ contents_xml.write(
+ file_or_filename=XML_FILE_ABSOLUTE_PATH,
+ xml_declaration=True,
+ encoding='UTF-8',
+ method='xml'
+ )
+
return True
diff --git a/dev.xml b/dev.xml
index eb106ca..feab1cc 100644
--- a/dev.xml
+++ b/dev.xml
@@ -1 +1,313 @@
-
+
+Vagrantfile
+ Vagrant.configure("2") do |config|
+
+ config.vm.box = "bento/ubuntu-16.04"
+ config.vm.synced_folder ".", "/vagrant", disabled: true
+ config.vm.synced_folder "../django-markdownx", "/srv/django-markdownx", create: true
+ config.vm.provision :shell, :path => "bootstrap.sh", privileged: false
+ config.vm.network :forwarded_port, guest: 8000, host: 8000
+ config.vm.hostname = "django-markdownx"
+ config.ssh.forward_agent = true
+
+ config.vm.provider "virtualbox" do |vb|
+ vb.name = "django-markdownx"
+ vb.gui = true
+ vb.customize ["modifyvm", :id,
+ "--memory", "512",
+ "--ioapic", "on",
+ "--cpus", "2"]
+ end
+end
+
+ bootstrap.sh
+ #!/usr/bin/env bash
+
+# NOTE: Python alias
+alias python=python3
+
+# NOTE: Install dependencies
+sudo apt-get update -y
+sudo apt-get install -y gettext build-essential pkg-config nodejs-legacy npm python3-dev libjpeg-dev zlib1g-dev python-virtualenv virtualenvwrapper
+
+# NOTE: Install virtual environment
+source /etc/bash_completion.d/virtualenvwrapper
+mkvirtualenv --python=/usr/bin/python3 --no-site-packages --unzip-setuptools django-markdownx
+pip install --upgrade pip
+pip install -r /srv/django-markdownx/requirements.txt
+
+# NOTE: Folders
+sudo chown vagrant:vagrant /srv
+
+# NOTE: Bash
+sudo sed -i '$a cd /srv/django-markdownx/' ~/.bashrc
+sudo sed -i '$a workon django-markdownx' ~/.bashrc
+
+# NOTE: Install Node modules, compile static files and run migrations
+cd /srv/django-markdownx/
+npm install
+npm run dist
+python manage.py migrate
+
+echo -e '\e[33;1;5mDONE!\e[0m \e[33;1;3m Connect using "vagrant ssh" \e[0m'
+
+ package.json
+ {
+ "name": "django-markdownx",
+ "description": "Django Markdownx frontend (JavaScript).",
+ "version": "2.0.0",
+ "author": "Adi, Pouria Hadjibagheri",
+ "license": "2-clause BSD",
+ "engines": {
+ "node": ">=0.10",
+ "npm": ">=1.3"
+ },
+
+ "devDependencies": {
+ "watch": "~1",
+ "typescript": "~2.2",
+ "uglify-js": "~2.7",
+ "browserify": "~14.1",
+ "clean-css-cli": "~4"
+ },
+
+ "config": {
+ "tsfolder": "markdownx/.static/markdownx/js",
+ "jsoutput": "markdownx/static/markdownx/js",
+
+ "cssfolder": "markdownx/.static/markdownx/admin/css",
+ "cssoutput": "markdownx/static/markdownx/admin/css"
+ },
+
+ "scripts": {
+ "build:ts": "tsc -p $npm_package_config_tsfolder/tsconfig.json",
+ "build:js": "npm run build:ts && browserify $npm_package_config_tsfolder/markdownx.js -o $npm_package_config_jsoutput/markdownx.js && uglifyjs $npm_package_config_jsoutput/markdownx.js -o $npm_package_config_jsoutput/markdownx.js --beautify --stats",
+ "build:css": "cleancss $npm_package_config_cssfolder/markdownx.css -o $npm_package_config_cssoutput/markdownx.css --format beautify --debug",
+ "build": "npm run build:js && npm run build:css",
+
+ "dist:js": "npm run build:ts && browserify $npm_package_config_tsfolder/markdownx.js -o $npm_package_config_jsoutput/markdownx.js && uglifyjs $npm_package_config_jsoutput/markdownx.js -o $npm_package_config_jsoutput/markdownx.min.js --screw-ie8 --mangle --stats",
+ "dist:css": "npm run build:css && cleancss $npm_package_config_cssfolder/markdownx.css -o $npm_package_config_cssoutput/markdownx.min.css --compatibility ie9 --debug",
+ "dist": "npm run dist:js && npm run dist:css",
+
+ "watch:js": "watch 'npm run build:js' $npm_package_config_tsfolder -d -u",
+ "watch:css": "watch 'npm run build:css' $npm_package_config_cssfolder -d -u"
+ }
+}
+
+ runtests.py
+ from __future__ import absolute_import
+
+import os
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(__file__), 'markdownx'))
+
+import django
+from django.conf import settings
+
+configure_settings = {
+ 'DATABASES': {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': ':memory:',
+ }
+ },
+ 'INSTALLED_APPS': [
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.staticfiles',
+ 'markdownx',
+ ],
+ 'DEBUG': False,
+ 'STATIC_URL': '/static/',
+ 'TEMPLATES': [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [
+ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'markdownx/tests/templates'),
+ ],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.contrib.auth.context_processors.auth',
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.i18n',
+ 'django.template.context_processors.media',
+ 'django.template.context_processors.static',
+ 'django.template.context_processors.tz',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ 'debug': True,
+ },
+ },
+ ],
+ 'ROOT_URLCONF': 'tests.urls',
+}
+
+settings.configure(**configure_settings)
+django.setup()
+
+from django.test.utils import get_runner
+test_runner = get_runner(settings)
+failures = test_runner(
+ verbosity=1,
+ interactive=False,
+ failfast=False).run_tests(['tests'])
+sys.exit(failures)
+
+
+ Makefile
+ # Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+SPHINXPROJ = DjangoMarkdownx
+SOURCEDIR = docs-src
+BUILDDIR = docs
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+ create_docs.sh
+ #!/usr/bin/env bash
+
+# Compile the docs.
+make clean
+make html
+
+mv ./docs/html/* ./docs/
+
+# Open in the browser.
+URL="docs/index.html"
+
+echo "Documentations index file: $URL"
+
+[[ -x $BROWSER ]] && exec "$BROWSER" "$URL"
+path=$(which xdg-open || which gnome-open || which open) && exec "$path" "$URL"
+echo "Built the docs - but couldn't find a browser to open them."
+
+
+
+ manage.py
+ #!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings")
+ try:
+ from django.core.management import execute_from_command_line
+ except ImportError:
+ # The above import may fail for some other reason. Ensure that the
+ # issue is really that Django is missing to avoid masking other
+ # exceptions on Python 2.
+ try:
+ import django
+ except ImportError:
+ raise ImportError(
+ "Couldn't import Django. Are you sure it's installed and "
+ "available on your PYTHONPATH environment variable? Did you "
+ "forget to activate a virtual environment?"
+ )
+ raise
+ execute_from_command_line(sys.argv)
+
+ Dockerfile
+ FROM python:3.6
+ENV PYTHONUNBUFFERED 1
+RUN mkdir /markdownx
+WORKDIR /markdownx
+ADD requirements.txt /markdownx/
+RUN python3.6 -m pip install -U setuptools
+RUN python3.6 -m pip install -r requirements.txt
+ADD . /markdownx/
+
+ docker-compose.yml
+ version: '2'
+services:
+ web:
+ restart: always
+ build: .
+ command: python3.6 manage.py runserver 0.0.0.0:8000
+ volumes:
+ - .:/markdownx
+ ports:
+ - "8000:8000"
+
+ mem_limit: 500m
+ cpuset: "1"
+
+ runtests.py
+ from __future__ import absolute_import
+
+import os
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(__file__), 'markdownx'))
+
+import django
+from django.conf import settings
+
+configure_settings = {
+ 'DATABASES': {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': ':memory:',
+ }
+ },
+ 'INSTALLED_APPS': [
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.staticfiles',
+ 'markdownx',
+ ],
+ 'DEBUG': False,
+ 'STATIC_URL': '/static/',
+ 'TEMPLATES': [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [
+ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'markdownx/tests/templates'),
+ ],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.contrib.auth.context_processors.auth',
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.i18n',
+ 'django.template.context_processors.media',
+ 'django.template.context_processors.static',
+ 'django.template.context_processors.tz',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ 'debug': True,
+ },
+ },
+ ],
+ 'ROOT_URLCONF': 'tests.urls',
+}
+
+settings.configure(**configure_settings)
+django.setup()
+
+from django.test.utils import get_runner
+test_runner = get_runner(settings)
+failures = test_runner(
+ verbosity=1,
+ interactive=False,
+ failfast=False).run_tests(['tests'])
+sys.exit(failures)
+
+
\ No newline at end of file
diff --git a/markdownx/__init__.py b/markdownx/__init__.py
index c214986..d3b4f53 100755
--- a/markdownx/__init__.py
+++ b/markdownx/__init__.py
@@ -66,7 +66,7 @@
__license__ = 'BSD'
__maintainer__ = 'Adi, Pouria Hadjibagheri'
__url__ = 'https://github.com/neutronX/django-markdownx'
-__version__ = '2.0.13'
+__version__ = '2.0.14'
__description__ = 'A comprehensive Markdown editor built for Django.'
# ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-