forked from lijiext/lammps
Raise exception and output error if ulb,ule and olb,ole are unbalanced
This commit is contained in:
parent
1dc19eceb2
commit
c61d5a1a29
|
@ -25,6 +25,7 @@ import re
|
|||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
class Markup(object):
|
||||
BOLD_START = "["
|
||||
BOLD_END = "]"
|
||||
|
@ -77,6 +78,7 @@ class Markup(object):
|
|||
text = text.replace('\"%s\"_%s' % (name, link), href, 1)
|
||||
return text
|
||||
|
||||
|
||||
class HTMLMarkup(Markup):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -101,6 +103,7 @@ class HTMLMarkup(Markup):
|
|||
|
||||
return "<A HREF = \"" + href + "\">" + content + "</A>"
|
||||
|
||||
|
||||
class Formatting(object):
|
||||
UNORDERED_LIST_MODE = "unordered-list"
|
||||
ORDERED_LIST_MODE = "ordered-list"
|
||||
|
@ -435,6 +438,7 @@ class Formatting(object):
|
|||
|
||||
return rows
|
||||
|
||||
|
||||
class HTMLFormatting(Formatting):
|
||||
def __init__(self, markup):
|
||||
super().__init__(markup)
|
||||
|
@ -448,6 +452,7 @@ class HTMLFormatting(Formatting):
|
|||
def raw_html(self, content):
|
||||
return content
|
||||
|
||||
|
||||
class TxtParser(object):
|
||||
def __init__(self):
|
||||
self.markup = HTMLMarkup()
|
||||
|
@ -630,6 +635,7 @@ class TxtParser(object):
|
|||
|
||||
i += 1
|
||||
|
||||
|
||||
class Txt2Html(TxtParser):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -641,6 +647,7 @@ class Txt2Html(TxtParser):
|
|||
line.startswith(".. END_HTML_ONLY") or \
|
||||
super().is_paragraph_separator(line)
|
||||
|
||||
|
||||
class TxtConverter:
|
||||
def get_argument_parser(self):
|
||||
return None
|
||||
|
@ -665,7 +672,15 @@ class TxtConverter:
|
|||
print("Converting", filename, "...", file=err)
|
||||
content = f.read()
|
||||
converter = self.create_converter(parsed_args)
|
||||
result = converter.convert(content)
|
||||
|
||||
try:
|
||||
result = converter.convert(content)
|
||||
except Exception as e:
|
||||
msg = "###########################################################################\n" \
|
||||
" ERROR: " + e.args[0] + "\n" \
|
||||
"###########################################################################\n"
|
||||
print(msg, file=err)
|
||||
result = msg
|
||||
|
||||
if write_to_files:
|
||||
output_filename = self.get_output_filename(filename)
|
||||
|
@ -674,6 +689,7 @@ class TxtConverter:
|
|||
else:
|
||||
print(result, end='', file=out)
|
||||
|
||||
|
||||
class Txt2HtmlConverter(TxtConverter):
|
||||
def get_argument_parser(self):
|
||||
parser = argparse.ArgumentParser(description='converts a text file with simple formatting & markup into HTML.\n'
|
||||
|
|
|
@ -24,6 +24,7 @@ import argparse
|
|||
from lammpsdoc import lammps_filters
|
||||
from lammpsdoc.txt2html import Markup, Formatting, TxtParser, TxtConverter
|
||||
|
||||
|
||||
class RSTMarkup(Markup):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -340,6 +341,7 @@ class RSTFormatting(Formatting):
|
|||
|
||||
return text + post
|
||||
|
||||
|
||||
class Txt2Rst(TxtParser):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -373,6 +375,11 @@ class Txt2Rst(TxtParser):
|
|||
return commands
|
||||
return super().order_commands(commands)
|
||||
|
||||
def transform_paragraphs(self, content):
|
||||
if self.format.indent_level > 0:
|
||||
raise Exception("unbalanced number of ulb,ule or olb,ole pairs!")
|
||||
return super().transform_paragraphs(content)
|
||||
|
||||
|
||||
class Txt2RstConverter(TxtConverter):
|
||||
def get_argument_parser(self):
|
||||
|
@ -389,6 +396,7 @@ class Txt2RstConverter(TxtConverter):
|
|||
filename, ext = os.path.splitext(path)
|
||||
return filename + ".rst"
|
||||
|
||||
|
||||
def main():
|
||||
app = Txt2RstConverter()
|
||||
app.run()
|
||||
|
|
Loading…
Reference in New Issue