#!/usr/bin/env python

"""
B.5 Macros for text

"""

from plasTeX import Command, Environment, sourceChildren

class frenchspacing(Command):
    unicode = u''

class nonfrenchspacing(Command):
    unicode = u''

class normalbaselines(Command):
    unicode = u''

class lq(Command):
    unicode = unichr(8216)

class rq(Command):
    unicode = unichr(8217)

class lbrack(Command):
    unicode = u'['

class rbrack(Command):
    unicode = u']'

class space(Command):
    unicode = u' '

class empty(Command):
    unicode = u''

class null(Command):
    unicode = u''

class bgroup(Command):

    def invoke(self, tex):
        self.ownerDocument.context.push()

    def digest(self, tokens):
        # Absorb the tokens that belong to us
        for item in tokens:
            if item.nodeType == Command.ELEMENT_NODE:
                if item.level < self.ENDSECTIONS_LEVEL:
                    tokens.push(item)
                    break
                if isinstance(item, (egroup,endgroup)):
                    break
                if item.contextDepth < self.contextDepth:
                    tokens.push(item)
                    break
                item.parentNode = self
                item.digest(tokens)
            self.appendChild(item)
        self.paragraphs(force=False)

    @property
    def source(self):
        if self.hasChildNodes():
            return '{%s}' % sourceChildren(self)
        return '{'