File: node_h.py

package info (click to toggle)
md-toc 9.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,192 kB
  • sloc: python: 7,901; sh: 942; makefile: 21
file content (134 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# node_h.py
#
# Copyright (C) 2017-2023 Franco Masotti (see /README.md)
#
# This file is part of md-toc.
#
# md-toc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# md-toc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with md-toc.  If not, see <http://www.gnu.org/licenses/>.
#
r"""A cmark implementation file."""

from dataclasses import dataclass

from .cmark_h import _cmarkCmarkMem, _cmarkCmarkNodeType

# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst


# Slots have less overhead but have been introduced in Python 3.10.
# @dataclass(slots=True)
@dataclass
class _cmarkCmarkList:
    marker_offset: int = -1
    padding: int = -1
    start: int = -1
    list_type: int = -1
    delimiter: int = -1
    bullet_char: int = -1
    tight: bool = False


@dataclass
class _cmarkCmarkCode:
    info: str = -1
    fence_length: int = -1
    fence_offset: int = -1
    fence_char: int = -1
    fenced: int = -1


@dataclass
class _cmarkCmarkHeading:
    level: int = -1
    setext: bool = False


@dataclass
class _cmarkCmarkLink:
    url: str = ''
    title: str = ''


@dataclass
class _cmarkCmarkCustom:
    on_enter: str = ''
    on_exit: str = ''


class _cmarkCmarkNode:
    __slots__ = [
        'mem',
        'next',
        'prev',
        'parent',
        'first_child',
        'last_child',
        'user_data',
        'data',
        'length',
        'start_line',
        'start_column',
        'end_line',
        'end_column',
        'internal_offset',
        'type',
        'flags',
        'as_list',
        'as_code',
        'as_heading',
        'as_link',
        'as_custom',
        'as_html_block_type',
        'numdelims',
    ]

    def __init__(self):
        self.mem: _cmarkCmarkMem = None

        self.next: _cmarkCmarkNode = None
        self.prev: _cmarkCmarkNode = None
        self.parent: _cmarkCmarkNode = None
        self.first_child: _cmarkCmarkNode = None
        self.last_child: _cmarkCmarkNode = None

        self.user_data = None

        self.data: str = None
        self.length: int = 0

        self.start_line: int = 0
        self.start_column: int = 0
        self.end_line: int = 0
        self.end_column: int = 0
        self.internal_offset: int = 0
        self.type: int = 0
        self.flags: int = 0

        # "as" union.
        self.as_list: _cmarkCmarkList = _cmarkCmarkList()
        self.as_code: _cmarkCmarkCode = _cmarkCmarkCode()
        self.as_heading: _cmarkCmarkHeading = _cmarkCmarkHeading()
        self.as_link: _cmarkCmarkLink = _cmarkCmarkLink()
        self.as_custom: _cmarkCmarkCustom = _cmarkCmarkCustom()
        self.as_html_block_type: int = 0

        # Add a new variable.
        self.numdelims: int = 0


if __name__ == '__main__':
    pass