Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def caption(self, value):
value = value.list if isinstance(value, ListContainer) else list(value)
self._caption = ListContainer(*value, oktypes=Inline, parent=self)
self._caption.location = 'caption'
:type attributes: :class:`dict`
:Base: :class:`Block`
"""
__slots__ = ['_content', 'identifier', 'classes', 'attributes']
_children = ['content']
def __init__(self, *args, identifier='', classes=[], attributes={}):
self._set_ica(identifier, classes, attributes)
self._set_content(args, Block)
def _slots_to_json(self):
return [self._ica_to_json(), self.content.to_json()]
class Span(Inline):
"""Generic block container with attributes
:param args: contents of the div
:type args: :class:`Inline`
:param identifier: element identifier (usually unique)
:type identifier: :class:`str`
:param classes: class names of the element
:type classes: :class:`list` of :class:`str`
:param attributes: additional attributes
:type attributes: :class:`dict`
:Base: :class:`Inline`
"""
__slots__ = ['_content', 'identifier', 'classes', 'attributes']
_children = ['content']
:param args: elements that will be set with small caps
:type args: :class:`Inline`
:Base: :class:`Inline`
"""
__slots__ = ['_content']
_children = ['content']
def __init__(self, *args):
self._set_content(args, Inline)
def _slots_to_json(self):
return self.content.to_json()
class Note(Inline):
"""Footnote or endnote
:param args: elements that are part of the note
:type args: :class:`Block`
:Base: :class:`Inline`
"""
__slots__ = ['_content']
_children = ['content']
def __init__(self, *args):
self._set_content(args, Block)
def _slots_to_json(self):
return self.content.to_json()
ans['citationHash'] = self.hash
return ans
def to_json_legacy(self):
# Replace default .to_json ; we don't need _slots_to_json()
ans = OrderedDict()
ans['citationSuffix'] = self.suffix.to_json()
ans['citationNoteNum'] = self.note_num
ans['citationMode'] = encode_dict(self.mode, [])
ans['citationPrefix'] = self.prefix.to_json()
ans['citationId'] = self.id
ans['citationHash'] = self.hash
return ans
class Link(Inline):
"""
Hyperlink
:param args: text with the link description
:type args: :class:`Inline`
:param url: URL or path of the link
:type url: ``str``
:param title: Alt. title
:type title: ``str``
:param identifier: element identifier (usually unique)
:type identifier: :class:`str`
:param classes: class names of the element
:type classes: :class:`list` of :class:`str`
:param attributes: additional attributes
:type attributes: :class:`dict`
:Base: :class:`Inline`
:param format: Format of the raw text ('html', 'tex', 'latex', 'context', etc.)
:type format: ``str``
:Base: :class:`Block`
"""
__slots__ = ['text', 'format']
def __init__(self, text, format='html'):
self.text = check_type(text, str)
self.format = check_group(format, RAW_FORMATS)
def _slots_to_json(self):
return [self.format, self.text]
class Code(Inline):
"""
Inline code (literal)
:param text: literal text (preformatted text, code, etc.)
:type text: :class:`str`
:param identifier: element identifier (usually unique)
:type identifier: :class:`str`
:param classes: class names of the element
:type classes: :class:`list` of :class:`str`
:param attributes: additional attributes
:type attributes: :class:`dict`
:Base: :class:`Inline`
"""
__slots__ = ['text', 'identifier', 'classes', 'attributes']
identifier='', classes=[], attributes={}):
self._set_content(args, Inline)
self._set_ica(identifier, classes, attributes)
self.url = check_type(url, str)
self.title = check_type(title, str)
def _slots_to_json(self):
ut = [self.url, self.title]
return [self._ica_to_json(), self.content.to_json(), ut]
# ---------------------------
# Classes - Text
# ---------------------------
class Str(Inline):
"""
Text (a string)
:param text: a string of unformatted text
:type text: :class:`str`
:Base: :class:`Inline`
"""
__slots__ = ['text']
def __init__(self, text):
self.text = check_type(text, str)
def __repr__(self):
return 'Str({})'.format(self.text)
# ---------------------------
# Classes - Empty
# ---------------------------
class Null(Block):
"""Nothing
:Base: :class:`Block`
"""
__slots__ = []
def to_json(self):
return {'t': 'Null'}
class Space(Inline):
"""Inter-word space
:Base: :class:`Inline`
"""
__slots__ = []
def to_json(self):
return {'t': 'Space'}
class HorizontalRule(Block):
"""Horizontal rule
:Base: :class:`Block`
"""
__slots__ = []
:param args: sequence of blocks
:type args: :class:`Block`
:Base: :class:`Block`
"""
__slots__ = ['_content']
_children = ['content']
def __init__(self, *args):
self._set_content(args, Block)
def _slots_to_json(self):
return self.content.to_json()
class Emph(Inline):
"""Emphasized text
:param args: elements that will be emphasized
:type args: :class:`Inline`
:Base: :class:`Inline`
"""
__slots__ = ['_content']
_children = ['content']
def __init__(self, *args):
self._set_content(args, Inline)
def _slots_to_json(self):
return self.content.to_json()
def builtin2meta(val):
if isinstance(val, bool):
return MetaBool(val)
elif isinstance(val, (float, int)):
return MetaString(str(val))
elif isinstance(val, str):
return MetaString(val)
elif isinstance(val, list):
return MetaList(*[builtin2meta(x) for x in val])
elif isinstance(val, dict):
return MetaMap(*[(k, builtin2meta(v)) for k, v in val.items()])
elif isinstance(val, Block):
return MetaBlocks(val)
elif isinstance(val, Inline):
return MetaInlines(val)
else:
return val
def to_json(self):
return {'t': 'HorizontalRule'}
class SoftBreak(Inline):
"""Soft line break
:Base: :class:`Inline`
"""
__slots__ = []
def to_json(self):
return {'t': 'SoftBreak'}
class LineBreak(Inline):
"""Hard line break
:Base: :class:`Inline`
"""
__slots__ = []
def to_json(self):
return {'t': 'LineBreak'}
# ---------------------------
# Classes - Simple Containers
# ---------------------------
class Plain(Block):
"""Plain text, not a paragraph