Commit 3fc5ba0d authored by Denis Salem's avatar Denis Salem
Browse files

done with reStructuredText

parent 8ff3a188
......@@ -74,4 +74,11 @@ class CodeHighlight:
some paragraphe
### sub title
### 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. :.
......@@ -112,8 +112,11 @@
DONE | Massive refactorisation, code cleaning and optimisation.
DONE | Fix pattern recursion issue (CodeHighlight).
DONE | Fix vertical scroll bar in code snippet.
WIP | Add reStructuredText support, remove do_not_use_markdown option.
WIP | Adding LaTeX2mathml support.
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
TODO | Support for video.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
......@@ -125,10 +128,14 @@
TODO | Export empty blog.
TODO | Serv page.
TODO | fix FAQ https://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting
TODO | add entry preview / full content.
TODO | fix FAQ latex2mathml is incomplete
TODO | Remove illegal character from path.
TODO | Open with navigator manual.
TODO | Change nomenclature: Most of the usual patterns are changed. Fix doc.
TODO | Add translation for Deutsch and Spanish.
TODO | Client-side search engine.
TODO | Fix unit test.
# version 2.x.x
TODO | Add docutils reStructuredText parser settings override.
TODO | Decrease halt_level to render reStructuredText even if errors occurs.
......@@ -76,7 +76,7 @@ Si vous souhaitez faire votre propre thème HTML/CSS vous pouvez vous aider du t
Pour compiler le blog avec ce thème bien à vous:
venc -export-blog
venc --export-blog
VenC utilise par défaut le thème local quand aucun nom de thème ne lui est précisé.
......
......@@ -56,6 +56,8 @@ setup(name='VenC',
"Development Status :: 5 - Production/Stable"
],
install_requires=[
"docutils",
"latex2mathml",
'markdown',
'pyyaml',
'Pygments'
......
......@@ -187,19 +187,19 @@ def copy_recursively(src, dest):
shutil.copytree(src+filename, dest+filename)
except shutil.Error as e:
notify(Messages.directory_not_copied % e, "YELLOW")
notify(messages.directory_not_copied % e, "YELLOW")
except OSError as e:
if e.errno == errno.ENOTDIR:
shutil.copy(src+filename, dest+filename)
else:
notify(Messages.directory_not_copied % e, "YELLOW")
notify(messages.directory_not_copied % e, "YELLOW")
def edit_and_export(argv):
if len(argv) != 1:
die(Messages.missing_params.format("--edit-and-export"))
die(messages.missing_params.format("--edit-and-export"))
try:
proc = subprocess.Popen([datastore.blog_configuration["textEditor"], argv[0]])
......@@ -207,7 +207,7 @@ def edit_and_export(argv):
pass
except TypeError:
die(Messages.unknown_text_editor.format(datastore.blog_configuration["textEditor"]))
die(messages.unknown_text_editor.format(datastore.blog_configuration["textEditor"]))
except:
raise
......
......@@ -30,7 +30,7 @@ from venc2.helpers import die
from venc2.l10n import messages
import venc2.datastore.entry as Entry
import venc2.pattern as Pattern
import venc2.patterns as Pattern
import venc2.helpers as Helpers
# Hold methods associated to patterns
......
......@@ -68,7 +68,7 @@ def get_blog_configuration():
everything_is_okay = False
notify(messages.missing_mandatory_field_in_blog_conf.format(field),"RED")
if not blog_configuration["markup_language"] in ["none", "Markdown"]:
if not blog_configuration["markup_language"] in ["none", "Markdown", "reStructuredText"]:
everything_is_okay = False
notify(messages.unknown_markup_language.format(blog_configuration["markup_language"], "blogConfiguration.yaml"),"RED")
......
......@@ -44,7 +44,7 @@ class Entry:
# Loading
raw_data = open(os.getcwd()+"/entries/"+filename,'r').read()
try:
raw_content = raw_data.split("---\n")[1]
raw_content = raw_data.split("\n---\n")[1]
except: #empty entry
raw_content = ''
......
......@@ -83,3 +83,4 @@ class Messages:
pattern_argument_must_be_integer="It must be a positive integer."
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."
......@@ -81,4 +81,5 @@ class Messages:
pattern_argument_must_be_integer="L'argument doit être un entier positif."
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."
......@@ -19,10 +19,18 @@
import latex2mathml.converter
from venc2.l10n import messages
from venc2.helpers import PatternInvalidArgument
def Latex2MathML(argv):
latex = argv[0]
tex_math_string = argv[0]
try:
return latex2mathml.converter.convert(latex)
return latex2mathml.converter.convert(tex_math_string)
except Exception as e:
print(argv[0], e)
print(e)
raise PatternInvalidArgument(
"Tex math string",
tex_math_string,
messages.tex_math_error
)
......@@ -24,7 +24,7 @@ from venc2.helpers import PatternInvalidArgument
def get_venc_version(argv):
return venc_version
def include_html(argv):
def include_file(argv):
try:
filename = argv[0]
include_string = open("includes/"+filename, 'r').read()
......@@ -38,7 +38,7 @@ def include_html(argv):
non_contextual_pattern_names = {
"GetVenCVersion" : get_venc_version,
"IncludeHTML" : include_html
"IncludeFile" : include_file
}
......@@ -23,6 +23,8 @@ import venc2.l10n
import venc2.helpers
from copy import deepcopy
from docutils.core import publish_parts
from docutils.utils import SystemMessage
from venc2.helpers import get_formatted_message
from venc2.helpers import highlight_value
......@@ -41,11 +43,21 @@ CLOSE_SYMBOL = ":."
markup_language_errors = []
def handle_markup_language_error(message, line=None, string=None):
if not message in markup_language_errors:
notify(message, "RED")
markup_language_errors.append(message)
if line != None and string != None:
lines = string.split('\n')
for lineno in range(0,len(lines)):
if line - 1 == lineno:
print('\033[91m'+lines[lineno]+'\033[0m')
else:
print(lines[lineno])
# Because parsing is recursive we want to avoid useless computation
# by splitting a given string and mark where exactly are the patterns
# we want to process.
class PreProcessor():
def __init__(self, string):
self.blacklist = list()
......@@ -88,29 +100,45 @@ class PreProcessor():
self.keep_appart_from_markup_index = list()
def process_markup_language(self, markup_language, source):
new_sub_strings = [""]
string = ""
for index in range(0, len(self.sub_strings)):
if not index in self.keep_appart_from_markup_index:
new_sub_strings[-1] += self.sub_strings[index]
if index == len(self.sub_strings) - 1:
new_sub_strings[-1] = parse_markup_language(new_sub_strings[-1], markup_language, source)
string += self.sub_strings[index]
else:
new_sub_strings[-1] = parse_markup_language(new_sub_strings[-1], markup_language, source)
new_sub_strings.append(self.sub_strings[index])
new_sub_strings.append("")
string += "VENC_TEMPORARY_REPLACEMENT_"+str(index)
try:
string = parse_markup_language(string, markup_language, source)
# catch error from reStructuredText
except SystemMessage as e:
try:
line = int(str(e).split(':')[1])
msg = str(e).split(':')[2].strip()
handle_markup_language_error(source+": "+msg, line=line, string=string)
except Exception as ee:
print(ee, len(string.split('\n')))
handle_markup_language_error(source+", "+str(e))
for index in self.keep_appart_from_markup_index:
string = string.replace(
"<p>VENC_TEMPORARY_REPLACEMENT_"+str(index)+"</p>",
self.sub_strings[index]
)
return ''.join(new_sub_strings)
return string
def parse_markup_language(string, markup_language, source):
if markup_language == "Markdown":
string = markdown.markdown(string)
elif markup_language == "reStructuredText":
string = publish_parts(string, writer_name='html', settings_overrides={'doctitle_xform':False, 'halt_level': 2, 'traceback': True, "warning_stream":"/dev/null"})['html_body']
elif markup_language != "none":
err = messages.unknown_markup_language.format(markup_language, source)
if not err in markup_language_errors:
notify(messages.unknown_markup_language.format(markup_language, source), "RED")
markup_language_errors.append(err)
handle_markup_language_error(err)
return string
......@@ -239,7 +267,7 @@ class Processor():
to_remove = list()
for index in pre_processed.patterns_index:
current_pattern = pre_processed.sub_strings[index][2:-2].split('::')[0]
if current_pattern in ["CodeHighlight", "Latex2MathML"]:
if current_pattern in ["CodeHighlight", "Latex2MathML","IncludeFile"]:
pre_processed.keep_appart_from_markup_index.append(index)
if not current_pattern in self.blacklist:
......
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