Example #1
0
 def set_numbering(self):
     """
     Sets the numbering status to the heading node.
     """
     if 'numbering' in self._options:
         if self._options['numbering'] == 'off':
             self.numbering = False
         elif self._options['numbering'] == 'on':
             self.numbering = True
         else:
             NodeStore.error("Invalid value '{}' for attribute 'numbering'. Allowed values are 'on' and 'off'.".
                             format(self._options['numbering']), self)
Example #2
0
 def set_numbering(self) -> None:
     """
     Sets the numbering status to the heading node.
     """
     if 'numbering' in self._options:
         if self._options['numbering'] == 'off':
             self.numbering = False
         elif self._options['numbering'] == 'on':
             self.numbering = True
         else:
             NodeStore.error(
                 "Invalid value '{}' for attribute 'numbering'. Allowed values are 'on' and 'off'."
                 .format(self._options['numbering']), self)
Example #3
0
    def __check_document_info(info_node_current, info_node_new):
        """
        Checks if a document info node has been set already. If so, an error will be logged.

        :param int|None info_node_current: The current document info node (i.e. a property of the document).
        :param sdoc.sdoc2.node.Node.Node info_node_new: The (new) document info node.
        """
        if info_node_current:
            node = in_scope(info_node_current)
            position = node.position
            out_scope(node)

            NodeStore.error("Document info {0} can be specified only once. Previous definition at {1}.".format(
                info_node_new.name, str(position)), info_node_new)
    def generate(self, node, file):
        """
        Generates the HTML code for an icon node.

        :param sdoc.sdoc2.node.IconNode.IconNode node: The icon node.
        :param file file: The output file.
        """
        attributes = IconNode.get_definition(node.argument)

        if attributes:
            img_element = Html.generate_void_element('img', attributes)
            file.write(img_element)
        else:
            NodeStore.error("There is no definition for icon with name '{}'".format(node.argument), node)
Example #5
0
    def generate(self, node: IconNode, file: Any) -> None:
        """
        Generates the HTML code for an icon node.

        :param IconNode node: The icon node.
        :param any file: The output file.
        """
        attributes = IconNode.get_definition(node.argument)

        if attributes:
            img_element = Html.generate_void_element('img', attributes)
            file.write(img_element)
        else:
            NodeStore.error(
                "There is no definition for icon with name '{}'".format(
                    node.argument), node)
Example #6
0
    def __check_document_info(info_node_current: Optional[int],
                              info_node_new: Node) -> None:
        """
        Checks if a document info node has been set already. If so, an error will be logged.

        :param int|None info_node_current: The current document info node (i.e. a property of the document).
        :param Node info_node_new: The (new) document info node.
        """
        if info_node_current:
            node = in_scope(info_node_current)
            position = node.position
            out_scope(node)

            NodeStore.error(
                "Document info {0} can be specified only once. Previous definition at {1}."
                .format(info_node_new.name, str(position)), info_node_new)
Example #7
0
    def __init__(self):
        """
        Object constructor.
        """
        # Create node store.
        sdoc.sdoc2.node_store = NodeStore()

        # Import all node modules.
        self.importing('/node/')
        self.importing('/decorator/html/')
Example #8
0
    def _generate_table_cell(align: Optional[str], cell: Any) -> str:
        """
        Returns the 'column' with HTML data.

        :param str|None align:
        :param any cell: The column in a table.
        """
        attributes = {}

        if align:
            attributes['style'] = "text-align: {0}".format(align)

        if isinstance(cell, str):
            data = cell
            is_html = False
        else:
            # Generates html in nested node ('cell') with specified formatter.
            formatter = NodeStore.get_formatter('html', cell.get_command())
            data = formatter.get_html(cell)
            is_html = True

        return Html.generate_element('td', attributes, data, is_html)
    def _generate_table_cell(align, col):
        """
        Returns the 'column' with HTML data.

        :param mixed col: The column in a table.

        :rtype: str
        """
        attributes = {}

        if align:
            attributes['style'] = "text-align: {0}".format(align)

        if isinstance(col, str):
            data = col
            is_html = False
        else:
            # Generates html in nested node ('col') with specified formatter.
            formatter = NodeStore.get_formatter('html', col.get_command())
            data = formatter.get_html(col)
            is_html = True

        return Html.generate_element('td', attributes, data, is_html)
Example #10
0
                sdoc.sdoc2.node_store.store_node(text_node)
                text_ids.append(text_node.id)

                end_paragraph_node = sdoc.sdoc2.node_store.create_inline_node('end_paragraph')
                text_ids.append(end_paragraph_node.id)

            # Checking where we need to add paragraph.
            if text_ids:
                if list_of_texts[-1]:
                    text_ids.pop()

        return text_ids

    # ------------------------------------------------------------------------------------------------------------------
    def prune_whitespace(self, leading: bool = False, trailing: bool = False):
        """
        Method for removing whitespace in text.

        :param bool leading: if True, remove whitespaces from start.
        :param bool trailing: if True, remove whitespaces from end.
        """
        if leading:
            self._argument = self._argument.lstrip()
        if trailing:
            self._argument = self._argument.rstrip()
        self._argument = re.sub(r'\s+', ' ', self._argument)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('TEXT', TextNode)
Example #11
0
    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def generate_toc(self) -> None:
        """
        Generates the table of contents.
        """
        self._options['ids'] = []

        for node in node_store.nodes.values():
            if not isinstance(node, ParagraphNode) and isinstance(node, HeadingNode):
                node.set_toc_id()

                data = {'id':        node.get_option_value('id'),
                        'arg':       node.argument,
                        'level':     node.get_hierarchy_level(),
                        'number':    node.get_option_value('number'),
                        'numbering': node.numbering}

                self._options['ids'].append(data)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('toc', TocNode)
Example #12
0
class HyperlinkHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for hyperlinks.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node: HyperlinkNode, file: Any) -> None:
        """
        Generates the HTML code for a hyperlink node.

        :param HyperlinkNode node: The hyperlink node.
        :param any file: The output file.
        """
        file.write(HyperlinkHtmlFormatter.get_html(node))

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_html(node: HyperlinkNode) -> str:
        """
        Returns string with generated HTML tag.

        :param HyperlinkNode node: The hyperlink node.
        """
        return Html.generate_element('a', node.get_html_attributes(),
                                     node.argument)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('hyperlink', 'html', HyperlinkHtmlFormatter)
Example #13
0
    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('hyperlink', HyperlinkNode)
Example #14
0
        return 'part'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level=-1):
        """
        Returns 0.

        :rtype: int
        """
        return 0

    # ------------------------------------------------------------------------------------------------------------------
    def number(self, enumerable_numbers):
        """
        Sets number of heading nodes.

        :param dict[str,sdoc.sdoc2.helper.Enumerable.Enumerable] enumerable_numbers:
        """
        if 'part' not in enumerable_numbers:
            enumerable_numbers['part'] = Enumerable()

        enumerable_numbers['part'].generate_numeration(self.get_hierarchy_level())
        enumerable_numbers['part'].increment_last_level()
        enumerable_numbers['part'].remove_starting_zeros()

        super().number(enumerable_numbers)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('part', PartNode)
Example #15
0
    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self):
        """
        Returns True.

        :rtype: bool
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('ref', ReferenceNode)
Example #16
0
        """
        return 'part'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 0.
        """
        return 0

    # ------------------------------------------------------------------------------------------------------------------
    def number(self, enumerable_numbers: Dict[str, Any]) -> None:
        """
        Sets number of heading nodes.

        :param dict[str,any] enumerable_numbers:
        """
        if 'part' not in enumerable_numbers:
            enumerable_numbers['part'] = Enumerable()

        enumerable_numbers['part'].generate_numeration(
            self.get_hierarchy_level())
        enumerable_numbers['part'].increment_last_level()
        enumerable_numbers['part'].remove_starting_zeros()

        super().number(enumerable_numbers)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('part', PartNode)
Example #17
0
 def _create_node_store(self) -> None:
     """
     Creates the node store (for storing nodes).
     """
     sdoc2.node_store = NodeStore(self._io)
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def write_into_file(node, file):
        """
        Writes data into opened file.

        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
        :param file file: The output file.
        """
        file.write(ReferenceHtmlFormatter.get_html(node))

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_html(node):
        """
        Returns string with generated HTML tag.

        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.

        :rtype: str
        """
        attributes = {'class': node.get_option_value('class'),
                      'href':  node.get_option_value('href'),
                      'title': node.get_option_value('title')}

        return Html.generate_element('a', attributes, str(node.text))


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('ref', 'html', ReferenceHtmlFormatter)
Copyright 2016 Set Based IT Consultancy

Licence MIT
"""
# ----------------------------------------------------------------------------------------------------------------------
from sdoc.sdoc2.NodeStore import NodeStore
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter


class ParagraphHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for paragraph.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node, file):
        """
        Generates the HTML code for a paragraph node.

        :param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node.
        :param file file: The output file.
        """
        file.write('<p>')
        HtmlFormatter.generate(self, node, file)
        file.write('</p>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('paragraph', 'html', ParagraphHtmlFormatter)
Example #20
0
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. br.
        """
        return 'br'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self) -> bool:
        """
        Returns True.
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('br', LineBreakNode)
Example #21
0
    def set_toc_id(self) -> None:
        """
        Don't do anything. Because we needn't this behaviour here.
        """
        pass

    # ------------------------------------------------------------------------------------------------------------------
    def prune_whitespace(self) -> None:
        """
        Removes spaces from end of a paragraph.
        """
        first = self.child_nodes[0]
        last = self.child_nodes[-1]

        for node_id in self.child_nodes:
            node = in_scope(node_id)

            if isinstance(node, TextNode):
                if node.id == first:
                    node.prune_whitespace(leading=True)
                if node.id == last:
                    node.prune_whitespace(trailing=True)
                if node.id != last and node.id != first:
                    node.prune_whitespace()

            out_scope(node)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('paragraph', ParagraphNode)
Example #22
0
Copyright 2016 Set Based IT Consultancy

Licence MIT
"""
# ----------------------------------------------------------------------------------------------------------------------
from sdoc.helper.Html import Html
from sdoc.sdoc2.NodeStore import NodeStore
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter


class TextHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for text.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node, file):
        """
        Generates the HTML code for a text node.

        :param sdoc.sdoc2.node.TextNode.TextNode node: The text node.
        :param file file: The output file.
        """
        file.write(Html.escape(node.argument))

        HtmlFormatter.generate(self, node, file)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('TEXT', 'html', TextHtmlFormatter)
Example #23
0
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def level_up(numbers):
        """
        Increments the level of hierarchy.

        :param dict[str,str] numbers: The number of last node.
        """
        if 'item' in numbers:
            numbers['item'] += '.0'
        else:
            numbers['item'] = '0'

    # ------------------------------------------------------------------------------------------------------------------
    def number(self, numbers):
        """
        Passing over all child nodes, for numeration.

        :param dict[str,str] numbers: The number of last node.
        """
        self.level_up(numbers)

        super().number(numbers)

        numbers['item'] = self.level_down(numbers['item'])


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_block_command('itemize', ItemizeNode)
Example #24
0
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. hyperlink.
        """
        return 'hyperlink'

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('hyperlink', HyperlinkNode)
Example #25
0
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def __check_document_info(info_node_current, info_node_new):
        """
        Checks if a document info node has been set already. If so, an error will be logged.

        :param int|None info_node_current: The current document info node (i.e. a property of the document).
        :param sdoc.sdoc2.node.Node.Node info_node_new: The (new) document info node.
        """
        if info_node_current:
            node = in_scope(info_node_current)
            position = node.position
            out_scope(node)

            NodeStore.error("Document info {0} can be specified only once. Previous definition at {1}.".format(
                info_node_new.name, str(position)), info_node_new)

    # ------------------------------------------------------------------------------------------------------------------
    def __remove_document_info_nodes(self):
        """
        Removes the nodes with document info from the list of child nodes.
        """
        obsolete_node_ids = [self.date_node_id, self.title_node_id, self.version_node_id]
        obsolete_node_ids = [node_id for node_id in obsolete_node_ids if node_id is not None]
        self._remove_child_nodes(obsolete_node_ids)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_block_command('document', DocumentNode)
Example #26
0
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def add_definition(name: str, attributes: Dict[str, str]):
        """
        Adds the definition of an icon to the icon definitions.

        :param str name: The name of a reference to icon definition.
        :param dict[str,str] attributes: The attributes.
        """
        IconNode._definitions[name] = attributes

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_definition(name: str) -> Optional[Dict[str, str]]:
        """
        Returns the attributes of a definition, if name of definition is exists.

        :param str name: The name of a definition

        :rtype: dict[str,str]|None
        """
        if name in IconNode._definitions:
            return IconNode._definitions[name]
        else:
            return None


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('icon', IconNode)
Example #27
0
from typing import Any

from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
from sdoc.sdoc2.node.ItemizeNode import ItemizeNode
from sdoc.sdoc2.NodeStore import NodeStore


class ItemizeHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for itemize.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node: ItemizeNode, file: Any) -> None:
        """
        Generates the HTML code for an itemize node.

        :param ItemizeNode node: The itemize node.
        :param any file: The output file.
        """
        file.write('<ul>')
        HtmlFormatter.generate(self, node, file)
        file.write('</ul>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('itemize', 'html', ItemizeHtmlFormatter)
Example #28
0
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. title.
        """
        return 'title'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 0.
        """
        return 0

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('title', TitleNode)
Example #29
0
        Object constructor.

        :param None|cleo.styles.output_style.OutputStyle io: The IO object.
        :param dict[str,str] options: The options of this section.
        :param str argument: The title of this section.
        """
        super().__init__(io, 'sub2section', options, argument)

    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self):
        """
        Returns the command of this node, i.e. sub2section.

        :rtype: str
        """
        return 'sub2section'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level=-1):
        """
        Returns 4.

        :rtype: int
        """
        return 4


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('sub2section', Sub2SectionNode)
NodeStore.register_inline_command('subsubsection', Sub2SectionNode)
Example #30
0
    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self):
        """
        Returns the command of this node, i.e. caption.

        :rtype: str
        """
        return 'caption'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('caption', CaptionNode)
Example #31
0
    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('date', DateNode)
Example #32
0
    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('version', VersionNode)
Example #33
0
    def set_toc_id(self):
        """
        Don't do anything. Because we needn't this behaviour here.
        """
        pass

    # ------------------------------------------------------------------------------------------------------------------
    def prune_whitespace(self):
        """
        Removes spaces from end of a paragraph.
        """
        first = self.child_nodes[0]
        last = self.child_nodes[-1]

        for node_id in self.child_nodes:
            node = in_scope(node_id)

            if isinstance(node, TextNode):
                if node.id == first:
                    node.prune_whitespace(leading=True)
                if node.id == last:
                    node.prune_whitespace(trailing=True)
                if node.id != last and node.id != first:
                    node.prune_whitespace()

            out_scope(node)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('paragraph', ParagraphNode)
Example #34
0
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 0.
        """
        return 0

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self) -> bool:
        """
        Returns True.
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('date', DateNode)
Example #35
0
        """
        return 'icondef'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def prepare_content_tree(self) -> None:
        """
        Prepares this node for further processing.
        """
        reference_name = self.argument
        attributes = self._options

        IconNode.add_definition(reference_name, attributes)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('icondef', IconDefNode)
Example #36
0
    """

    # ------------------------------------------------------------------------------------------------------------------
    def __init__(self, io: OutputStyle, options: Dict[str, str], argument: str):
        """
        Object constructor.

        :param OutputStyle io: The IO object.
        :param dict[str,str] options: The options of this section.
        :param str argument: The title of this section.
        """
        super().__init__(io, 'section', options, argument)

    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. section.
        """
        return 'section'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 2.
        """
        return 2


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('section', SectionNode)
Example #37
0
    # ------------------------------------------------------------------------------------------------------------------
    def __init__(self, io: OutputStyle, options: Dict[str, str], argument: str):
        """
        Object constructor.

        :param OutputStyle io: The IO object.
        :param dict[str,str] options: The options of this section.
        :param str argument: The title of this section.
        """
        super().__init__(io, 'subsection', options, argument)

    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. subsection.
        """
        return 'subsection'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 3.
        """
        return 3


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('sub1section', Sub1SectionNode)
NodeStore.register_inline_command('subsection', Sub1SectionNode)
Example #38
0
                TocHtmlFormatter.write_elements(item, file)

            elif not depth:
                TocHtmlFormatter.write_elements(item, file)

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def write_elements(item, file):
        """
        Write the containing elements.

        :param dict[str,str] item: The item which we outputs.
        :param file file: The output file.
        """
        class_attr = 'level{}'.format(item['level'])
        file.write(Html.generate_tag('li', {'class': class_attr}))

        file.write(Html.generate_tag('a', {'href': '#{}'.format(item['id'])}))

        number = item['number'] if item['numbering'] else None
        if number:
            file.write(Html.generate_element('span', {}, str(number)))

        file.write(' {}'.format(item['arg']))
        file.write('</a>')
        file.write('</li>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('toc', 'html', TocHtmlFormatter)
    HtmlFormatter for generating HTML code for smile.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node, file):
        """
        Generates the HTML code for a smile node.

        :param sdoc.sdoc2.node.SmileNode.SmileNode node: The smile node.
        :param file file: The output file.
        """
        file.write(SmileHtmlFormatter.get_html(node))

        HtmlFormatter.generate(self, node, file)

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_html(node):
        """
        Returns string with generated HTML tag.

        :param sdoc.sdoc2.node.SmileNode.SmileNode node: The smile node.

        :rtype: str
        """
        return Html.generate_element('b', {}, 'SMILE')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('smile', 'html', SmileHtmlFormatter)
Example #40
0
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def strip_start_point(number):
        """
        Removes start point if it in the number.

        :param str number: The number of last node.

        :rtype: str
        """
        return number.lstrip('.')

    # ------------------------------------------------------------------------------------------------------------------
    def number(self, numbers):
        """
        Sets number for item nodes.

        :param dict[str,str] numbers: The number of last node.
        """
        numbers['item'] = self.strip_start_point(numbers['item'])
        numbers['item'] = self._increment_last_level(numbers['item'])

        self._options['number'] = numbers['item']

        super().number(numbers)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('item', ItemNode)
Example #41
0
from typing import Any

from sdoc.helper.Html import Html
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
from sdoc.sdoc2.node.TitleNode import TitleNode
from sdoc.sdoc2.NodeStore import NodeStore


class TitleHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for title of SDoc document.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node: TitleNode, file: Any) -> None:
        """
        Generates HTML code for a title node.

        :param TitleNode node: The title node.
        :param any file: The output file.
        """
        html_code = Html.generate_element('span', {}, node.argument)

        file.write(html_code)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('title', 'html', TitleHtmlFormatter)
Example #42
0
from typing import Any

from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
from sdoc.sdoc2.node.LabelNode import LabelNode
from sdoc.sdoc2.NodeStore import NodeStore


class LabelHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for labels.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node: LabelNode, file: Any) -> None:
        """
        Generates the HTML code for a label node.

        :param LabelNode node: The label node.
        :param any file: The output file.
        """
        HtmlFormatter.generate(self, node, file)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('label', 'html', LabelHtmlFormatter)
class HyperlinkHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for hyperlinks.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node, file):
        """
        Generates the HTML code for a hyperlink node.

        :param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
        :param file file: The output file.
        """
        file.write(HyperlinkHtmlFormatter.get_html(node))

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_html(node):
        """
        Returns string with generated HTML tag.

        :param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.

        :rtype: str
        """
        return Html.generate_element('a', node.get_html_attributes(), node.argument)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('hyperlink', 'html', HyperlinkHtmlFormatter)
Example #44
0
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def generate_toc(self):
        """
        Generates the table of contents.
        """
        self._options['ids'] = []

        for node in node_store.nodes.values():
            if not isinstance(node, ParagraphNode) and isinstance(node, HeadingNode):
                node.set_toc_id()

                data = {'id':        node.get_option_value('id'),
                        'arg':       node.argument,
                        'level':     node.get_hierarchy_level(),
                        'number':    node.get_option_value('number'),
                        'numbering': node.numbering}

                self._options['ids'].append(data)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('toc', TocNode)
Example #45
0
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. reference.
        """
        return 'ref'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self) -> bool:
        """
        Returns True.
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('ref', ReferenceNode)
Example #46
0
        Checks if a document info node has been set already. If so, an error will be logged.

        :param int|None info_node_current: The current document info node (i.e. a property of the document).
        :param Node info_node_new: The (new) document info node.
        """
        if info_node_current:
            node = in_scope(info_node_current)
            position = node.position
            out_scope(node)

            NodeStore.error(
                "Document info {0} can be specified only once. Previous definition at {1}."
                .format(info_node_new.name, str(position)), info_node_new)

    # ------------------------------------------------------------------------------------------------------------------
    def __remove_document_info_nodes(self):
        """
        Removes the nodes with document info from the list of child nodes.
        """
        obsolete_node_ids = [
            self.date_node_id, self.title_node_id, self.version_node_id
        ]
        obsolete_node_ids = [
            node_id for node_id in obsolete_node_ids if node_id is not None
        ]
        self._remove_child_nodes(obsolete_node_ids)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_block_command('document', DocumentNode)
"""
SDoc

Copyright 2016 Set Based IT Consultancy

Licence MIT
"""
# ----------------------------------------------------------------------------------------------------------------------
from sdoc.sdoc2.NodeStore import NodeStore
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter


class IconDefHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter stub for definition of the Icon.
    """

# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('icondef', 'html', IconDefHtmlFormatter)
Example #48
0
    def is_block_command(self):
        """
        Returns False.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self):
        """
        Returns True.

        :rtype: bool
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_phrasing(self):
        """
        Returns True.

        :rtype: bool
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_block_command('unknown', UnknownNode)
NodeStore.register_inline_command('unknown', UnknownNode)
Example #49
0
                alignments.append('center')
            elif hyphens.startswith(':'):
                alignments.append('left')
            elif hyphens.endswith(':'):
                alignments.append('right')
            else:
                alignments.append('')

        return alignments

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def prune_whitespace(row):
        """
        Strips whitespaces from the text of an each cell.

        :param list[str] row: The row with text of an each cell.
        :rtype: list[str]
        """
        clear_row = []
        for item in row:
            clear_text = item.strip()
            clear_text = re.sub(r'\s+', ' ', clear_text)
            clear_row.append(clear_text)

        return clear_row


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_block_command('table', TableNode)
Example #50
0
        Returns the command of this node, i.e. end_paragraph.

        :rtype: str
        """
        return 'end_paragraph'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def prepare_content_tree(self) -> None:
        """
        Not implemented for end paragraph nodes.
        """
        raise RuntimeError()


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('end_paragraph', EndParagraphNode)
Example #51
0
        :param sdoc.sdoc2.node.DocumentNode.DocumentNode node: The document node.
        :param file file: The output file.
        """
        file.write('<div class="sdoc-document-title-outer">')
        if node.title_node_id:
            title_node = in_scope(node.title_node_id)
            file.write(Html.generate_element('h1', {}, title_node.argument))
            out_scope(title_node)

        file.write('<div class="sdoc-document-title-inner">')

        if node.date_node_id:
            date_node = in_scope(node.date_node_id)
            if date_node.argument:
                file.write(Html.generate_element('span', {'class': 'sdoc-document-date'}, date_node.argument))
            out_scope(date_node)

        if node.version_node_id:
            version_node = in_scope(node.version_node_id)
            if version_node.argument:
                file.write(Html.generate_element('span', {'class': 'sdoc-document-version'}, version_node.argument))
            out_scope(version_node)

        file.write('</div>')
        file.write('</div>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter)
Example #52
0
            title_node = in_scope(node.title_node_id)
            file.write(Html.generate_element('h1', {}, title_node.argument))
            out_scope(title_node)

        file.write('<div class="sdoc-document-title-inner">')

        if node.date_node_id:
            date_node = in_scope(node.date_node_id)
            if date_node.argument:
                file.write(
                    Html.generate_element('span',
                                          {'class': 'sdoc-document-date'},
                                          date_node.argument))
            out_scope(date_node)

        if node.version_node_id:
            version_node = in_scope(node.version_node_id)
            if version_node.argument:
                file.write(
                    Html.generate_element('span',
                                          {'class': 'sdoc-document-version'},
                                          version_node.argument))
            out_scope(version_node)

        file.write('</div>')
        file.write('</div>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter)
Example #53
0
from typing import Any

from sdoc.helper.Html import Html
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
from sdoc.sdoc2.node.DateNode import DateNode
from sdoc.sdoc2.NodeStore import NodeStore


class DateHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter for generating HTML code for date of SDoc document.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def generate(self, node: DateNode, file: Any) -> None:
        """
        Generates HTML code for a date node.

        :param DateNode node: The date node.
        :param any file: The output file.
        """
        html = Html.generate_element('span', {}, node.argument)

        file.write(html)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('date', 'html', DateHtmlFormatter)
Example #54
0
        :param OutputStyle io: The IO object.
        :param dict[str,str] options: The options of this label.
        :param str argument: The title of this label.
        """
        super().__init__(io, 'label', options, argument)

    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. label.
        """
        return 'label'

    # ------------------------------------------------------------------------------------------------------------------
    def is_block_command(self) -> bool:
        """
        Returns False.
        """
        return False

    # ------------------------------------------------------------------------------------------------------------------
    def is_inline_command(self) -> bool:
        """
        Returns True.
        """
        return True


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('label', LabelNode)
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def write_into_file(node, file):
        """
        Writes data into opened HTML file.

        :param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node.
        :param file file: The output file.
        """
        # Creating dicts with attributes for each type of element.
        figure_attributes = {'id': node.get_option_value('id')}

        img_attributes = {'src':    node.get_option_value('src'),
                          'width':  node.get_option_value('width'),
                          'height': node.get_option_value('height'),
                          'alt':    node.caption}

        # Creating elements.
        file.write(Html.generate_tag('figure', figure_attributes))

        file.write(Html.generate_void_element('img', img_attributes))

        FigureHtmlFormatter._write_caption(node, file)

        file.write('</figure>')


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('figure', 'html', FigureHtmlFormatter)
Example #56
0
        Generates the HTML code for an unknown node.

        :param sdoc.sdoc2.node.Node.Node node: The unknown node.
        :param file file: The output file.
        """
        self.write_into_file(node)

    # ------------------------------------------------------------------------------------------------------------------
    def generate_chapter(self, node, file):
        """
        Generates the HTML code for an unknown node.

        :param sdoc.sdoc2.node.Node.Node node: The unknown node.
        :param file file: The output file.
        """
        if file:
            self.write_into_file(node)

    # ------------------------------------------------------------------------------------------------------------------
    def write_into_file(self, node):
        """
        Writes into opened file.

        :param sdoc.sdoc2.node.Node.Node node: The unknown node.
        """
        self.error('Unknown SDoc2 command {0}'.format(node.name), node)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('unknown', 'html', UnknownHtmlFormatter)
Example #57
0
    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def add_definition(name, attributes):
        """
        Adds the definition of an icon to the icon definitions.

        :param str name: The name of a reference to icon definition.
        :param dict[str,dict[str,str]] attributes: The attributes.
        """
        IconNode._definitions[name] = attributes

    # ------------------------------------------------------------------------------------------------------------------
    @staticmethod
    def get_definition(name):
        """
        Returns the attributes of a definition, if name of definition is exists.

        :param str name: The name of a definition

        :rtype: dict[str,str]|None
        """
        if name in IconNode._definitions:
            return IconNode._definitions[name]
        else:
            return None


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('icon', IconNode)
Example #58
0
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
from sdoc.sdoc2.NodeStore import NodeStore


class CaptionHtmlFormatter(HtmlFormatter):
    """
    HtmlFormatter stub generating HTML code for captions.
    """


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('caption', 'html', CaptionHtmlFormatter)
Example #59
0
                sdoc.sdoc2.node_store.store_node(text_node)
                text_ids.append(text_node.id)

                end_paragraph_node = sdoc.sdoc2.node_store.create_inline_node('end_paragraph')
                text_ids.append(end_paragraph_node.id)

            # Checking where we need to add paragraph.
            if text_ids:
                if list_of_texts[-1]:
                    text_ids.pop()

        return text_ids

    # ------------------------------------------------------------------------------------------------------------------
    def prune_whitespace(self, leading=False, trailing=False):
        """
        Method for removing whitespace in text.

        :param bool leading: if True, remove whitespaces from start.
        :param bool trailing: if True, remove whitespaces from end.
        """
        if leading:
            self._argument = self._argument.lstrip()
        if trailing:
            self._argument = self._argument.rstrip()
        self._argument = re.sub(r'\s+', ' ', self._argument)


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('TEXT', TextNode)
Example #60
0
    # ------------------------------------------------------------------------------------------------------------------
    def __init__(self, io: OutputStyle, options: Dict[str, str],
                 argument: str):
        """
        Object constructor.

        :param OutputStyle io: The IO object.
        :param dict[str,str] options: The options of this chapter.
        :param str argument: The title of this chapter.
        """
        super().__init__(io, 'chapter', options, argument)

    # ------------------------------------------------------------------------------------------------------------------
    def get_command(self) -> str:
        """
        Returns the command of this node, i.e. chapter.
        """
        return 'chapter'

    # ------------------------------------------------------------------------------------------------------------------
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
        """
        Returns 1.
        """
        return 1


# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('chapter', ChapterNode)