aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/ao_object_setter.d
blob: cbb4edc4947d716c97ae8d0b5bb4ec8ac8feff21 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/+
  object setter
  ao_object_setter.d
+/
template ObjectSetter() {
  /+ structs +/
  struct HeadingAttrib {
    string lev                = "9";
    int lev_markup_number     = 9;
    int lev_collapsed_number  = 9;
  }
  struct ParaAttrib {
    int indent_start          = 0;
    int indent_rest           = 0;
    bool bullet               = false;
  }
  struct BlockAttrib {
    string syntax                 = "";
  }
  struct Comment {
    // no .attrib and no .obj_cite_number
  }
  struct Node {
    int ocn                    = 0;
    int parent_lev             = 0;
    int parent_ocn             = 0;
    string node                = "";
  }
  struct ObjComposite {
    // size_t id;
    string use                 = "";
    string of                  = "";
    string is_a                = "";
    string object              = "";
    string obj_cite_number     = "";  // not used for calculations? output only? else int
    string[] anchor_tags       = [];
    HeadingAttrib heading_attrib;
    ParaAttrib para_attrib;
    BlockAttrib block_attrib;
    Node node_structure;
  }
  struct ObjCompositeArr {
    ObjComposite[] oca;
  }
  /+ structs setter +/
  struct ObjectAbstractSet {
    import std.conv : to;
    auto contents_comment(in string object) {
      ObjComposite object_set;
      object_set.use                  = "comment";
      object_set.of                   = "comment";
      object_set.is_a                 = "comment";
      object_set.object               = object;
      return object_set;
    }
    auto contents_heading(
      in string object,
      in string attrib,
      in int obj_cite_number,
      in string[] tags,
      in string lev,
      in int lev_markup_number,
      in int lev_collapsed_number,
    ) {
      ObjComposite object_set;
      object_set.use                                 = "content";
      object_set.of                                  = "para";
      object_set.is_a                                = "heading";
      object_set.object                              = object;
      object_set.obj_cite_number                     = (obj_cite_number==0) ? "" : to!string(obj_cite_number);
      object_set.anchor_tags                         ~= tags;
      object_set.heading_attrib.lev                  = lev;
      object_set.heading_attrib.lev_markup_number    = lev_markup_number;
      object_set.heading_attrib.lev_collapsed_number = lev_collapsed_number;
      // object_set.node_structure.node               = node;
      return object_set;
    }
    auto contents_para(
      in string is_a,
      in string object,
      in string attrib,
      in int obj_cite_number,
      in string[string] indent,
      in bool bullet
    ) {
      ObjComposite object_set;
      object_set.use                      = "content";
      object_set.of                       = "para";
      object_set.is_a                     = "para";
      object_set.object                   = object.strip;
      object_set.obj_cite_number          = (obj_cite_number==0) ? "" : to!string(obj_cite_number);
      object_set.para_attrib.indent_start = 0; // indent["hang_position"];
      object_set.para_attrib.indent_rest  = 0; // indent["base_position"];
      object_set.para_attrib.bullet       = false;
      // object_set.node_structure.node               = node;
      return object_set;
    }
    auto contents_endnote(
      in string object,
    ) {
      auto m = (matchFirst(object, rgx.note_ref));
      string notenumber = to!string(m.captures[1]);
      string anchor_tag = "note_" ~ notenumber;
      ObjComposite object_set;
      object_set.use                      = "content";
      object_set.of                       = "para";
      object_set.is_a                     = "endnote";
      object_set.object                   = object.strip;
      object_set.obj_cite_number          = "";
      object_set.para_attrib.indent_start = 0;
      object_set.para_attrib.indent_rest  = 0;
      object_set.para_attrib.bullet       = false;
      return object_set;
    }
    auto contents_block(
      in string type,
      in string object,
      in string attrib,
      in int obj_cite_number
    ) {
      ObjComposite object_set;
      object_set.use                 = "content";
      object_set.of                  = "block";
      object_set.is_a                = type;
      object_set.object              = object;
      object_set.obj_cite_number     = (obj_cite_number==0) ? "" : to!string(obj_cite_number);
      // object_set.node_structure.node               = node;
      return object_set;
    }
    auto contents_block_code(
      in string type,
      in string object,
      in string attrib_language_syntax,
      in int obj_cite_number
    ) {
      ObjComposite object_set;
      object_set.use                 = "content";
      object_set.of                  = "block";
      object_set.is_a                = type;
      object_set.block_attrib.syntax = attrib_language_syntax;
      object_set.object              = object;
      object_set.obj_cite_number     = (obj_cite_number==0) ? "" : to!string(obj_cite_number);
      // object_set.node_structure.node               = node;
      return object_set;
    }
    auto contents_block_obj_cite_number_string(
      in string type,
      in string object,
      in string obj_cite_number,
      in string node
    ) {
      ObjComposite object_set;
      object_set.use                               = "content";
      object_set.of                                = "block";
      object_set.is_a                              = type;
      object_set.object                            = object;
      object_set.obj_cite_number                   = obj_cite_number;
      object_set.node_structure.node               = node;
      return object_set;
    }
  }
}