Corrected bugs with superblocks and raw management.
This commit is contained in:
parent
516726c447
commit
2ba11bc6f6
16
Makefile
16
Makefile
|
@ -2,24 +2,24 @@
|
|||
ST := pipenv run ./setup.py
|
||||
DNAME := dist/$(shell $(ST) --name)-$(shell $(ST) --version).tar.gz
|
||||
|
||||
test tests: -prepare
|
||||
prepare:
|
||||
@pipenv install --dev
|
||||
|
||||
test tests:
|
||||
@$(ST) test
|
||||
|
||||
docs: -prepare
|
||||
docs:
|
||||
@$(ST) build_sphinx
|
||||
|
||||
checkdocs: -prepare
|
||||
checkdocs:
|
||||
@$(ST) checkdocs
|
||||
|
||||
dist: $(DNAME)
|
||||
$(DNAME): -prepare
|
||||
$(DNAME):
|
||||
@$(ST) sdist
|
||||
|
||||
upload: $(DNAME)
|
||||
@twine upload $(DNAME)
|
||||
|
||||
-prepare:
|
||||
@pipenv install --dev
|
||||
|
||||
.PHONY: -prepare test tests dist docs
|
||||
.PHONY: test tests dist docs
|
||||
# End of file.
|
||||
|
|
|
@ -20,7 +20,7 @@ What is left to do
|
|||
- Implement the ``only_allowed_tags`` attribute (for ``[list] blah [*]`` to
|
||||
ignore ``blah`` and anything outside of ``[*]`` tags which is in
|
||||
``allow_tags``).
|
||||
- Add an ``[imgurl]`` tag.
|
||||
- Add an ``[imgurl]`` tag?
|
||||
- Manage lightscript (or even markdown?) as output languages;
|
||||
- Check where the errors are to display them to the user:
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ There are a few public members you can define as a tag:
|
|||
level, and adds a paragraph tag implicitely.
|
||||
- ``inlined``: if is a block, transforms automatically the surrounding block
|
||||
into a superblock while it's there.
|
||||
- ``procvalue`` : process the value as normal text before passing it.
|
||||
- ``not_within_itself`` : make that if a tag is opened within itself (depth
|
||||
- ``procvalue``: process the value as normal text before passing it.
|
||||
- ``not_within_itself``: make that if a tag is opened within itself (depth
|
||||
included), the tag above and all tags below are closed first.
|
||||
- ``expect_child`` : make that all content below (without depth) that isn't
|
||||
- ``expect_child``: make that all content below (without depth) that isn't
|
||||
within the specified tags is ignored.
|
||||
|
||||
So for example, if I want to make the inline tag ``[hello]`` as an example,
|
||||
|
|
|
@ -31,8 +31,9 @@ def tohtml(message, options = _default_options, **tweaks):
|
|||
""" Converts textout BBcode to HTML.
|
||||
Receives a string, returns a string. """
|
||||
|
||||
return _Translator(_StringIO(message), _StringIO(), 'html', \
|
||||
tweaks, options).process().getvalue()
|
||||
t = _Translator(_StringIO(message), _StringIO(), 'html', \
|
||||
tweaks, options)
|
||||
return t.process().getvalue()
|
||||
|
||||
def tolightscript(message, options = _default_options, **tweaks):
|
||||
""" Converts textout BBcode to Lightscript.
|
||||
|
|
|
@ -117,9 +117,15 @@ class TextoutTag:
|
|||
""" Preprocess using the two methods. """
|
||||
|
||||
ct = self.__preprocess0(content)
|
||||
if ct != None: content = ct; del ct
|
||||
if ct != None:
|
||||
content = ct
|
||||
del ct
|
||||
|
||||
ct = self.__preprocess1(content)
|
||||
if ct != None: content = ct; del ct
|
||||
if ct != None:
|
||||
content = ct
|
||||
del ct
|
||||
|
||||
return content
|
||||
|
||||
def __preprocess_and_prepare(self, content):
|
||||
|
@ -241,6 +247,9 @@ class TextoutOptions:
|
|||
for mod in modules:
|
||||
self.add(mod)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}()"
|
||||
|
||||
def add(self, element):
|
||||
""" Add an option. """
|
||||
|
||||
|
|
|
@ -26,18 +26,21 @@ class _TweaksDictionary:
|
|||
tweak keyword, e.g. `label_prefix`, `LABELPREFIX` and
|
||||
`__LaBeL___PRE_FIX__`. """
|
||||
|
||||
def __normalize(self, name):
|
||||
return ''.join(c for c in name if c in _string.ascii_letters).lower()
|
||||
|
||||
def __init__(self, base):
|
||||
self.__elts = {}
|
||||
|
||||
for kw in base:
|
||||
self.__elts[self.__normalize(kw)] = base[kw]
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}({repr(self.__elts)})"
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.__elts[key]
|
||||
|
||||
def __normalize(self, name):
|
||||
return ''.join(c for c in name if c in _string.ascii_letters).lower()
|
||||
|
||||
# ---
|
||||
# Tag data utility.
|
||||
# ---
|
||||
|
@ -184,6 +187,16 @@ class Translator:
|
|||
|
||||
self.inline_mode = bool(self.tweak("inline", False))
|
||||
|
||||
def __repr__(self):
|
||||
p = []
|
||||
p.append(f"inp = {repr(self.inp)}")
|
||||
p.append(f"outp = {repr(self.outp)}")
|
||||
p.append(f"output_type = {repr(self.output_type)}")
|
||||
p.append(f"tweaks = {repr(self.tweaks)}")
|
||||
p.append(f"options = {repr(self.options)}")
|
||||
|
||||
return f"{self.__class__.__name__}({', '.join(p)})"
|
||||
|
||||
def tweak(self, key, default = None):
|
||||
""" Get a tweak from the tweaks dictionary. """
|
||||
|
||||
|
@ -546,23 +559,27 @@ class Translator:
|
|||
inlines = []
|
||||
|
||||
next_block_is_super = False
|
||||
for dat in self.queue:
|
||||
# Check if the tag hasn't already been started or doesn't call
|
||||
for idx, dat in enumerate(self.queue):
|
||||
# Check that the tag hasn't already been started or doesn't call
|
||||
# for content processing.
|
||||
|
||||
if type(dat.last) != bool:
|
||||
if idx > 0 and type(dat.last) != bool:
|
||||
break
|
||||
|
||||
# Then put the tag in the appropriate queue.
|
||||
|
||||
if dat.type == dat.BLOCK:
|
||||
if dat.super or next_block_is_super:
|
||||
if block_to_start is not None and \
|
||||
dat.super or next_block_is_super:
|
||||
# The block is to be considered as the block to start.
|
||||
# Sometimes the block to start is the latest superblock!
|
||||
|
||||
superblocks.insert(0, dat)
|
||||
next_block_is_super = dat.inlined
|
||||
elif dat.started:
|
||||
block_to_end = dat
|
||||
next_block_is_super = dat.inlined
|
||||
elif block_to_end == None and block_to_start == None:
|
||||
elif block_to_end is None and block_to_start is None:
|
||||
block_to_start = dat
|
||||
next_block_is_super = dat.inlined
|
||||
else:
|
||||
|
@ -577,13 +594,14 @@ class Translator:
|
|||
# Put the tag ends for the blocks to end.
|
||||
# If there are some, we ought to close the inline tags first.
|
||||
|
||||
if block_to_end != None:
|
||||
if block_to_end is not None:
|
||||
for dat in inlines[::-1] + [block_to_end]:
|
||||
if not dat.started:
|
||||
continue
|
||||
|
||||
if hasattr(dat.tag, 'end'):
|
||||
self.put_code(dat.tag.end(), start_tags = False)
|
||||
self.put_code(dat.tag.end(), start_tags = False,
|
||||
skip_first = True)
|
||||
dat.started = False
|
||||
dat.reset()
|
||||
|
||||
|
@ -779,4 +797,10 @@ class Translator:
|
|||
|
||||
return self.outp
|
||||
|
||||
def reopen(self, inp, outp):
|
||||
""" Open another instance of this translator for sub-translators. """
|
||||
|
||||
return Translator(inp, outp, self.output_type, self.tweaks,
|
||||
self.options)
|
||||
|
||||
# End of file.
|
||||
|
|
Loading…
Reference in New Issue