Started implementing lists with required attributes, doesn't work yet…
This commit is contained in:
parent
d39a356194
commit
d1c6d09fc1
|
@ -14,12 +14,6 @@ documentation accessible on `the official website`_.
|
|||
What is left to do
|
||||
------------------
|
||||
|
||||
- Implement the ``not_within_itself`` attribute (for ``[*]``).
|
||||
- Implement the ``allowed_tags`` attribute to only allow a set of tags within
|
||||
itself.
|
||||
- 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?
|
||||
- Manage lightscript (or even markdown?) as output languages;
|
||||
- Check where the errors are to display them to the user:
|
||||
|
|
|
@ -31,6 +31,8 @@ There are a few public members you can define as a tag:
|
|||
- ``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.
|
||||
- ``allowed_tags``: allowed tags right beneath the current one.
|
||||
- ``no_text``: disable raw text within the tag.
|
||||
- ``expect_child``: make that all content below (without depth) that isn't
|
||||
within the specified tags is ignored.
|
||||
|
||||
|
|
|
@ -62,15 +62,28 @@ class _TagData:
|
|||
else self.INLINE
|
||||
self.full = full
|
||||
|
||||
# Tag stack behaviour.
|
||||
# `nwi` is whether the tag can be in itself directly or not (see
|
||||
# the `not_within_itself` property in the docs).
|
||||
# `allowed` is the tags that are allowed amongst the children tags.
|
||||
|
||||
self.nwi = bool(tag.not_within_itself) \
|
||||
if hasattr(tag, 'not_within_itself') else False
|
||||
self.allowed = list(tag.allowed_tags) \
|
||||
if hasattr(tag, 'allowed_tags') else None
|
||||
|
||||
# Tag beginning displaying.
|
||||
# `notempty` is the moment when (and if) to start displaying the
|
||||
# tag's code and content.
|
||||
# `started` is whether the tag's beginning has been processed,
|
||||
# i.e. if the content is no longer processed.
|
||||
# `notext` is whether text within the tag directly is printed or not.
|
||||
|
||||
self.notempty = bool(tag.notempty) if hasattr(tag, 'notempty') \
|
||||
else False
|
||||
self.started = False
|
||||
self.notext = bool(tag.no_text) if hasattr(tag, 'no_text') \
|
||||
else False
|
||||
|
||||
# `base` is the actual tag object returned by `get_tag()`.
|
||||
|
||||
|
@ -231,9 +244,10 @@ class Translator:
|
|||
""" Output some text. """
|
||||
|
||||
# If we want to ignore the content (because it is not used
|
||||
# nor output), let the text fall into the void.
|
||||
# nor output or the current tag doesn't allow text), let the
|
||||
# text fall into the void.
|
||||
|
||||
if self.cign > 0:
|
||||
if self.cign > 0 or (self.queue and self.queue[0].notext):
|
||||
return
|
||||
|
||||
# Add to the text group, which will be processed when `flush_text()`
|
||||
|
@ -774,6 +788,33 @@ class Translator:
|
|||
self.put_text(tagdata.full)
|
||||
continue
|
||||
|
||||
# Check if is an allowed tag.
|
||||
|
||||
if dat.type == dat.BLOCK:
|
||||
try:
|
||||
sb = next(d for d in self.queue if d.super)
|
||||
except StopIteration:
|
||||
alw = None
|
||||
else:
|
||||
alw = sb.allowed
|
||||
else:
|
||||
try:
|
||||
pr = self.queue[0]
|
||||
except IndexError:
|
||||
alw = None
|
||||
else:
|
||||
alw = pr.allowed
|
||||
|
||||
if alw is not None and not type(dat.base) in alw:
|
||||
self.put_text(tagdata.full)
|
||||
continue
|
||||
|
||||
# Check if it is within itself and it can't.
|
||||
|
||||
if dat.nwi and self.queue \
|
||||
and type(dat.base) is type(self.queue[0].base):
|
||||
self.pop_tag()
|
||||
|
||||
# And don't forget to push the tag (through its data).
|
||||
|
||||
self.push_tag(dat)
|
||||
|
|
|
@ -59,8 +59,8 @@ class ListTag(_BlockTag):
|
|||
aliases = ('[list]', '[ul]', '[ol]')
|
||||
notempty = True
|
||||
superblock = True
|
||||
allowed_tags = (_ListElement,)
|
||||
only_allowed_tags = True
|
||||
allowed_tags = (ListElementTag,)
|
||||
no_text = True
|
||||
|
||||
def prepare(self, name, value):
|
||||
us = _ul_lst_names
|
||||
|
|
|
@ -16,6 +16,7 @@ from ._Code import *
|
|||
from ._Image import *
|
||||
from ._Label import *
|
||||
from ._Link import *
|
||||
from ._List import *
|
||||
from ._Progress import *
|
||||
from ._Quote import *
|
||||
from ._Rot import *
|
||||
|
|
Loading…
Reference in New Issue