Commit 2cb9c1e4 authored by Denis Salem's avatar Denis Salem
Browse files

WIP entry preview/full content

parent 3fc5ba0d
authors: 'Denis Salem'
categories: 'test1,test2'
tags: ''
title:
style: features
---
## V __en__ C is super easy to use and learn!
.:GetRandomNumber::0::10::3:.
.:CodeHighlight::python::False::# Copyright 2016, 2018 Denis Salem
#
# This file is part of VenC.
#
# VenC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# VenC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import os
import pygments.lexers
import pygments.formatters
from venc2.helpers import die
from venc2.helpers import notify
from venc2.l10n import messages
class CodeHighlight:
def __init__(self, override):
self._override = override
self._includes = dict()
def get_style_sheets(self, argv=list()):
output = str()
for filename in self._includes.keys():
output += "<link rel=\"stylesheet\" href=\".:GetRelativeOrigin:."+filename+"\" type=\"text/css\" />\n"
return output
def export_style_sheets(self):
extra = os.listdir(os.getcwd()+"/extra/")
for key in self._includes:
if key not in extra or self._override:
stream = open(os.getcwd()+"/extra/"+key,'w')
stream.write(self._includes[key])
def highlight(self, argv):
try:
name = "venc_source_"+argv[0].replace('+','Plus')
lexer = pygments.lexers.get_lexer_by_name(argv[0], stripall=True)
formatter = pygments.formatters.HtmlFormatter(linenos=("table" if argv[1]=="True" else False), cssclass=name)
code = argv[2]
result = pygments.highlight(code.replace("\:",":"), lexer, formatter)
css = formatter.get_style_defs()
if not name+".css" in self._includes.keys():
self._includes[name+".css"] = css
return result
except pygments.util.ClassNotFound:
die(messages.unknown_language.format(argv[0]))
:.
some paragraphe
### some mathml
.:Latex2MathML::\begin{matrix*}[r]a & b \\ c & d \end{matrix*}:.
### another mathml
.:Latex2MathML::\left\{ \begin{array} { l } { 3x - 5y + 4z = 0} \\ { x - y + 8z = 0} \\ { 2x - 6y + z = 0} \end{array} \right. :.
......@@ -95,6 +95,7 @@
DONE | Add more coloration for message!
DONE | Specify where error occurs when parsing patterns.
DONE | More verbosity about wrong pattern arguments.
DONE | More verbosity about malformed entry.
DONE | Clear white spaces in error messages.
DONE | Speed up blog exportation ( almost seven times faster!).
DONE | Implement RelativeLocation.
......@@ -115,8 +116,8 @@
DONE | Adding Tex math to mathml support (depend on latex2mathml)
DONE | Add reStructuredText support, remove do_not_use_markdown option.
DONE | Improve reStructuredText integration with VenC.
TODO | add entry preview / full content.
TODO | Fix broken -xb theme
DONE | Quit gracefully when ftp timeout error.
WIP | add entry preview / full content.
TODO | Support for video.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
......
......@@ -108,7 +108,7 @@ def export_blog(argv=list()):
if len(argv) == 1:
if not argv[0] in themes_descriptor.keys():
die(Messages.theme_doesnt_exists.format(argv[0]))
die(messages.theme_doesnt_exists.format(argv[0]))
else:
theme_folder = os.path.expanduser("~")+"/.local/share/VenC/themes/"+argv[0]+"/"
......
......@@ -80,7 +80,7 @@ def new_entry(argv):
stream = codecs.open(output_filename, 'w', encoding="utf-8")
if len(argv) == 1:
output = yaml.dump(content, default_flow_style=False, allow_unicode=True) + "---\n"
output = yaml.dump(content, default_flow_style=False, allow_unicode=True) + "---VENC-BEGIN-PREVIEW---\n---VENC-END-PREVIEW---\n"
else:
try:
......
......@@ -46,6 +46,9 @@ def remote_copy(argv=list()):
except ftplib.error_perm as e:
die(str(e))
except TimeoutError as e:
die(str(e))
def ftp_export_recursively(origin, ftp):
folder = os.listdir(origin)
for item in folder:
......
......@@ -43,21 +43,26 @@ class Entry:
def __init__(self, filename):
# Loading
raw_data = open(os.getcwd()+"/entries/"+filename,'r').read()
try:
raw_content = raw_data.split("\n---\n")[1]
except: #empty entry
raw_content = ''
try:
metadata = yaml.load(raw_data.split("---\n")[0])
except yaml.scanner.ScannerError:
die(messages.possible_malformed_entry.format(filename))
if metadata == None:
die(messages.possible_malformed_entry.format(filename))
entry_parted = raw_data.split("---VENC-BEGIN-PREVIEW---\n")
if len(entry_parted) == 2:
entry_parted = [entry_parted[0]] + entry_parted[1].split("---VENC-END-PREVIEW---\n")
if len(entry_parted) == 3:
self.preview = PreProcessor(entry_parted[1])
self.content = PreProcessor(entry_parted[2])
try:
metadata = yaml.load(entry_parted[0])
except yaml.scanner.ScannerError as e:
die(messages.possible_malformed_entry.format(filename, ''), extra=str(e))
else:
cause = messages.missing_separator_in_entry.format("---VENC-END-PREVIEW---")
die(messages.possible_malformed_entry.format(filename, cause))
else:
cause = messages.missing_separator_in_entry.format("---VENC-BEGIN-PREVIEW---")
die(messages.possible_malformed_entry.format(filename, cause))
# Setting up optional metadata
for key in metadata.keys():
if not key in ["authors","tags","categories","entry_name"]:
......@@ -87,13 +92,6 @@ class Entry:
except KeyError:
die(messages.missing_mandatory_field_in_entry.format("authors", self.id))
try:
self.content = PreProcessor(raw_content)
except:
raise
die(messages.possible_malformed_entry.format(self.id))
try:
self.tags = [ {"tag":e} for e in list(metadata["tags"].split(",") if metadata["tags"] != str() else list())]
......
......@@ -51,8 +51,10 @@ def highlight_value(text, value, color="RED"):
)
# Terminate nicely with notification
def die(msg, color="RED"):
def die(msg, color="RED", extra=""):
notify(msg, color)
if extra != "":
print(extra)
exit()
# Being verborse is nice, with colours it's better
......
......@@ -46,7 +46,7 @@ class Messages:
ftp_path="Absolute path of your blog on FTP server."
clean_ftp_directory="Cleaning target FTP directory..."
copy_to_ftp_directory="Copying your blog to target FTP directory..."
possible_malformed_entry="Possible malformed entry {0}. Abort."
possible_malformed_entry="Possible malformed entry {0}. {1} Abort."
possible_malformed_blog_configuration="Possible malformed blog configuration. Abort."
blog_recompilation="Recompilation of your blog locally..."
export_archives="Exporting local entries sorted by dates..."
......@@ -84,3 +84,4 @@ class Messages:
wrong_permissions = "{0} : You don't have the right permissions on this file in {1}."
unknown_markup_language = "{0}: Unsupported markup language."
tex_math_error = "Malformed input string or unsupported markup from latex2mathml."
missing_separator_in_entry = "Missing separator {0}."
......@@ -45,7 +45,7 @@ class Messages:
ftp_path="Chemin absolu de votre blog sur l'hôte FTP."
clean_ftp_directory="Nettoyage du repertoire FTP de destination..."
copy_to_ftp_directory="Copie du blog vers le repertoire FTP de destination..."
possible_malformed_entry="La publication {0} est probablement mal formée... Abandon."
possible_malformed_entry="La publication {0} est probablement mal formée... {1} Abandon."
possible_malformed_blog_configuration="Le fichier de configuration du blog est probablement mal formée... Abandon."
blog_recompilation="Recompilation du blog locale..."
export_archives="Exportation locale des publications triées par dates..."
......@@ -82,4 +82,5 @@ class Messages:
wrong_permissions = "{0} : Vous n'avez pas les bonnes permissions d'accès sur ce fichier."
unknown_markup_language = "{0}: Langage de balisage non supporté dans {1}."
tex_math_error = "Chaine mal formé ou balise non supporté par latex2mathml."
missing_separator_in_entry = "Il manque le séparateur {0}."
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment