Going forward!
This commit is contained in:
parent
d9e6f27979
commit
cfed4cc7de
6
TAGS.rst
6
TAGS.rst
|
@ -24,8 +24,10 @@ There are a few public members you can define as a tag:
|
|||
It is defined as ``True`` by default for all tags;
|
||||
- ``notempty``: ignore the tag when its content is empty. By default, this
|
||||
value is `False`;
|
||||
- ``superblock``: is a super-block (for blocks), adds a paragraph
|
||||
tag implicitely.
|
||||
- ``superblock``: is a super-block (for blocks) which means it adds a block
|
||||
level, and adds a paragraph tag implicitely.
|
||||
- ``inlined``: if is a block, transforms automatically the surrounding block
|
||||
into a superblock while it's there.
|
||||
|
||||
So for example, if I want to make the inline tag ``[hello]`` as an example,
|
||||
with the alternate name ``[hai]``, I'd start off by writing:
|
||||
|
|
|
@ -47,14 +47,17 @@ __test_cases = {
|
|||
'<div class="align-center"><p><i>b</i></p></div>',
|
||||
'a[i]k[center][b]b[justify]c[/center]d[/]wouhou': \
|
||||
'<p>a<i>k</i></p>' \
|
||||
'<div class="align-center"><p><i><b>b</b></i></p></div>' \
|
||||
'<div class="align-justify"><p><i><b>c</b></i></p></div>' \
|
||||
'<div class="align-center"><p><i><b>b</b></i></p>' \
|
||||
'<div class="align-justify"><p><i><b>c</b></i></p></div></div>' \
|
||||
'<p><i>d</i>wouhou</p>',
|
||||
|
||||
# Show tag for super preprocessing blocks.
|
||||
'[show]lol': '<p><span style="font-family: monospace;">lol</span></p>',
|
||||
'[quote][show][justify]hehe': \
|
||||
'<div class="citation"><p><div class="align-justify">' \
|
||||
'<p>hehe</p></div></p></div>',
|
||||
'<div class="citation"><p><span style="font-family: monospace;">' \
|
||||
'<div class="align-justify">' \
|
||||
'<p>hehe</p></div>' \
|
||||
'</span></p></div>',
|
||||
|
||||
# Titles.
|
||||
'lolk[title]smth': '<p>lolk</p>' '<h4>smth</h4>',
|
||||
|
|
|
@ -18,6 +18,7 @@ class TextoutShowTag(_TextoutBlockTag):
|
|||
|
||||
aliases = ('[show]',)
|
||||
superblock = True
|
||||
inlined = True
|
||||
generic = False
|
||||
raw = False
|
||||
|
||||
|
@ -25,9 +26,9 @@ class TextoutShowTag(_TextoutBlockTag):
|
|||
return _htmlescape(content)
|
||||
|
||||
def begin_html(self):
|
||||
return '<span style="font-family: monospace;">'
|
||||
return '<p><span style="font-family: monospace;">'
|
||||
|
||||
def end_html(self):
|
||||
return '</span>'
|
||||
return '</span></p>'
|
||||
|
||||
# End of file.
|
||||
|
|
|
@ -83,11 +83,12 @@ class _TagData:
|
|||
# Flags and properties calculated from the tag's attributes, using the
|
||||
# rules given in `TAGS.md`.
|
||||
# `ign` is whether the content should be read while the tag is opened.
|
||||
# `raw` is whether the tag's content should be read as raw.
|
||||
# `generic` is whether the tag can be terminated by the generic
|
||||
# tag ending mark [/].
|
||||
# `notempty` is whether the tag should be used with an empty
|
||||
# content or not (e.g. to avoid `<p></p>`), True if not.
|
||||
# `raw` is whether the tag's content should be read as raw.
|
||||
# `super` is whether the tag is a superblock or not.
|
||||
# `inlined` is whether the next block on the same level is turned into
|
||||
# a superblock or not.
|
||||
|
||||
self.ign = not hasattr(tag, 'preprocess') and hasattr(tag, 'content')
|
||||
|
||||
|
@ -101,6 +102,9 @@ class _TagData:
|
|||
bool(tag.superblock) if hasattr(tag, 'superblock') \
|
||||
else False
|
||||
|
||||
self.inlined = bool(tag.inlined) if self.super \
|
||||
and hasattr(tag, 'inlined') and bool(tag.inlined) else False
|
||||
|
||||
# Content processing utilities.
|
||||
# `last` is the content of the tag. A boolean indicates that we
|
||||
# only want to know if the content is empty or not, and a string
|
||||
|
@ -126,7 +130,7 @@ class _TagData:
|
|||
self.last = ""
|
||||
|
||||
def __repr__(self):
|
||||
return '<TagData>'
|
||||
return '<TagData tag=' + repr(self.tag) + '>'
|
||||
|
||||
# ---
|
||||
# Translator main class.
|
||||
|
@ -217,7 +221,8 @@ class Translator:
|
|||
|
||||
self.text_group += text
|
||||
|
||||
def flush_text(self):
|
||||
def flush_text(self, superblocks_only = False,
|
||||
next_block_is_super = False):
|
||||
""" Flush the text that has been output. """
|
||||
|
||||
# First of all, check if the text group is empty or if we want to
|
||||
|
@ -233,13 +238,16 @@ class Translator:
|
|||
text = self.text_group
|
||||
self.text_group = ""
|
||||
|
||||
self.add_text(text, process_func = lambda x: self.process_text(x))
|
||||
self.add_text(text, process_func = lambda x: self.process_text(x),
|
||||
superblocks_only = superblocks_only,
|
||||
next_block_is_super = next_block_is_super)
|
||||
|
||||
# ---
|
||||
# Code outputting utilities.
|
||||
# ---
|
||||
|
||||
def add_text(self, text, process_func = lambda x: x, start_tags = True):
|
||||
def add_text(self, text, process_func = lambda x: x, start_tags = True,
|
||||
superblocks_only = False, next_block_is_super = False):
|
||||
""" Add text to the higher blocks if available. """
|
||||
|
||||
# The last queue is composed of booleans (does the group contain
|
||||
|
@ -254,8 +262,12 @@ class Translator:
|
|||
# Check if it is a tag we want to contribute to.
|
||||
|
||||
if dat.type == dat.BLOCK:
|
||||
if dat.super or not blockfound:
|
||||
if dat.super or next_block_is_super:
|
||||
blockfound = True
|
||||
next_block_is_super = dat.inlined
|
||||
elif not superblocks_only and not blockfound:
|
||||
blockfound = True
|
||||
next_block_is_super = False
|
||||
else:
|
||||
continue
|
||||
|
||||
|
@ -290,7 +302,8 @@ class Translator:
|
|||
|
||||
self.outp.write(message)
|
||||
|
||||
def put_code(self, code, start_tags = True):
|
||||
def put_code(self, code, start_tags = True,
|
||||
superblocks_only = True, next_block_is_super = False):
|
||||
""" Put some code. """
|
||||
|
||||
# We don't want to mix text and code, so we'll flush to be sure that
|
||||
|
@ -305,7 +318,9 @@ class Translator:
|
|||
|
||||
# Add the code.
|
||||
|
||||
self.add_text(code, start_tags = start_tags)
|
||||
self.add_text(code, start_tags = start_tags,
|
||||
superblocks_only = superblocks_only,
|
||||
next_block_is_super = next_block_is_super)
|
||||
|
||||
def put_newline(self):
|
||||
""" Put a newline. """
|
||||
|
@ -373,6 +388,10 @@ class Translator:
|
|||
dat = self.queue.pop(0)
|
||||
tag = dat.tag
|
||||
|
||||
pcattrs = {'start_tags': False,
|
||||
'superblocks_only': dat.type == dat.BLOCK,
|
||||
'next_block_is_super': dat.inlined}
|
||||
|
||||
# If preprocessing has been enabled, we ought to process the content,
|
||||
# check if the tag is valid, and do everything we would have done
|
||||
# while pushing the tag if it didn't do content processing.
|
||||
|
@ -493,6 +512,7 @@ class Translator:
|
|||
block_to_end = None
|
||||
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 content processing.
|
||||
|
@ -505,12 +525,15 @@ class Translator:
|
|||
# Then put the tag in the appropriate queue.
|
||||
|
||||
if dat.type == dat.BLOCK:
|
||||
if dat.super:
|
||||
if dat.super or next_block_is_super:
|
||||
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:
|
||||
block_to_start = dat
|
||||
next_block_is_super = dat.inlined
|
||||
else:
|
||||
inlines.insert(0, dat)
|
||||
|
||||
|
@ -683,7 +706,8 @@ class Translator:
|
|||
|
||||
# Push a paragraph tag if the block is a superblock.
|
||||
|
||||
if dat.type == dat.BLOCK and dat.super and type(dat.last) == bool:
|
||||
if dat.type == dat.BLOCK and dat.super and not dat.raw \
|
||||
and not dat.inlined:
|
||||
self.push_tag(_TagData(_TextoutParagraphTag(None, None,
|
||||
self.output_type, self.tweaks), None, ''))
|
||||
|
||||
|
|
Loading…
Reference in New Issue