def testListItem(self): with self.assertRaises(exceptions.MooseDocsException) as e: token = tokens.ListItem() self.assertIn("A 'ListItem' must have a 'OrderedList' or 'UnorderedList' parent.", e.exception.message) root = tokens.OrderedList() token = tokens.ListItem(parent=root) self.assertIs(token.parent, root)
def createTokenFromSyntax(self, info, parent, obj): item = self.extension.database.get(obj.name, None) if item and hasattr(item, self.SUBCOMMAND): attr = getattr(item, self.SUBCOMMAND) self.createHeading(parent) ul = tokens.UnorderedList(parent) for filename in attr: filename = unicode(filename) li = tokens.ListItem(ul) lang = common.get_language(filename) code = tokens.Code(None, language=lang, code=common.read(filename)) floats.ModalLink(li, url=filename, bottom=True, content=code, string=u'({})'.format( os.path.relpath(filename, MooseDocs.ROOT_DIR)), title=tokens.String(None, content=filename)) return parent
def createTokenFromSyntax(self, info, parent, obj): item = self.extension.database.get(obj.name, None) attr = getattr(item, self.SUBCOMMAND, None) if item and attr: db = DatabaseListToken(parent) self.createHeading(db) ul = tokens.UnorderedList(db, class_='moose-list-{}'.format( self.SUBCOMMAND)) for filename in attr: filename = unicode(filename) li = tokens.ListItem(ul) lang = common.get_language(filename) code = tokens.Code(None, language=lang, code=common.read( os.path.join(MooseDocs.ROOT_DIR, filename))) floats.ModalLink(li, url=filename, bottom=True, content=code, string=filename, title=tokens.String(None, content=filename)) return parent
def createToken(self, info, parent): marker = info['marker'] n = len(marker) token = self.TOKEN(parent) #pylint: disable=not-callable strip_regex = re.compile(r'^ {%s}(.*?)$' % n, flags=re.MULTILINE) for item in self.ITEM_RE.finditer(info['items']): content = ' ' * n + item.group('item') indent = re.search(r'^\S', content, flags=re.MULTILINE | re.UNICODE) if indent: msg = "List item content must be indented by {} to match the list item " \ "characters of '{}', to end a list item you must use two empty lines." raise exceptions.TokenizeException(msg.format(n, marker)) content = strip_regex.sub(r'\1', content) self.reader.parse(tokens.ListItem(token), content) return token