Debian Codegraph @

example/org/20250912150340-hyperorg_design_concept.org

raw
1 # SPDX-FileCopyrightText: © 2024 Christian BUHTZ <[email protected]>
2 #
3 # SPDX-License-Identifier: CC0-1.0
4 #
5 # This file is part of the program "Hyperorg". Unlike the program, this file is
6 # licensed under Creative Commons Zero v1 (CC0-1.0). See folder LICENSES or go
7 # to <https://creativecommons.org/publicdomain/zero/1.0/>
8 :PROPERTIES:
9 :ID: 8cc00b3a-255e-456f-9e12-95c21de00b36
10 :END:
11 #+title: Hyperorg Design Concept
12 #+date: [2025-09-12 15:03]
13 * Introduction
14 This documents describe the design concept behind [[id:d0a0d7c9-8aa2-4377-b20b-ab54c93b49d6][Hyperorg]]. It contains
15 technical details and reasonate some design decisions. These are not hard
16 rules and there is always the opportunity to modify the concept for good
17 reasons.
18
19 Hyperorg...
20 - ... tries to mimik the behavior of ~org-roam-export-to-html~.
21 - ... do not copy the exact HTML output of ~org-roam-export-to-html~.
22 - ... should not break when encountering unsupported or unknown org-syntax.
23
24 * Basics
25 ** Org document
26 An org document consists of a header and a body. The header with its
27 =PROPERTIES= drawer is handled by the extern =orgparse= package. The body is
28 handled by Hyperorg itself.
29
30 ** Elements and Runs
31 From top to bottom the body of an org file contains /elements/
32 (=elements.py=). Imagine it like a stack on a vertical axis. Each /element/ can
33 contain several /runs/ (~class Run~). They are organized side by side in an
34 horizontal axis. Everything that needs to have its own line and generates a
35 /newline/ is an /element/. See file =textruns.py= and =elements.py= for insights.
36
37 Technically each /element/ class is also a /run/ (direct or indirect derived from
38 ~class Run~). The distinguishing between /run/ and /element/ happens on a concept
39 level but not in the itself, despite it affects the organization of code and
40 files.
41
42 A paragraph (~class Paragraph~) for example is an /element/. The text contained in
43 a /paragraph/ is organized into /runs/. The most simplest run is just a string
44 (~class str~). In case the text has bold markup it will be represented by a
45 /markup/ run (~class Markup~).
46
47 *** Example
48 #+begin_src org
49 This is a raw paragraph
50 with two lines.
51
52 The second paragraph contain *bold text* as an example.
53 #+end_src
54
55 The first paragraph will result in an ~class Paragraph~ instance containing the
56 text =This is a raw paragraph with two lines.= as a simple string. Note that
57 there is no newline character.
58
59 The second is a ~Paragraph~ with a list of three /runs/: The string "The second
60 paragraph contain ". As second a /markup/ run (~class Markup~) of type =IMPORTANT=
61 (result in *bold* rendering). As third, again a string /run/ with "as an example.".
62
63
64 ** Nested Runs
65 An example for nested runs is a link with a label.
66
67 #+begin_src org
68 very *cool and /free/*
69 #+end_src
70
71 This is ~Paragraph~ with two elements: The ~str~ "very " and a ~Markup~ (type
72 =IMPORTANT=) with "cool and free". But that ~Markup~ contain two entries itself:
73 The string "cool and " and another ~Markup~ (type =EMPHASIZED=) holding the string
74 "free".
75
76 * The code base
77 - /Runs/ are defined in =textruns.py=.
78 - /Elements/ are defined in =elements.py=.
79 - Parsing and creating /elements/ happens in
80 ~parser.py::OrgContentParser.result()~.
81 - Parsing and creating /runs/ happens in =textruns.py=.
82
83 ** The parsing process
84 This section describe the parsing process and its steps. Not all details and
85 cases are covered. The goal is just to give an idea about the parsing workflow.
86
87 1. The raw org-file is read by `orgparser` (an external package) first. That
88 component does parse the meta data (e.g. `PROPERTIES` drawer) of the org
89 file and additionally provide the org-files body as a simple list of lines.
90 Location in code is ~reader.py::Reader.read_org_files()~. Org files (and org
91 sections with their own =ORGID=) are described as /nodes/. So final result of
92 the parsing process will be a list of ~Node~ (see file =content.py=)
93 instances. The ~Reader~ will create a ~Node~ instance for each org file.
94 2. The ~Node~ instance itself will handle the parsing of the content in its body
95 (see ~content.py::Node.parse_lines()~). It calls
96 ~parser.py::OrgContentParser.result()~ for help in this process.
97 3. The ~OrgContentParser~ iterates over each line of the body and create /elements/
98 (e.g. ~Paragraph~, ~Figure~, ...) of it. But the inner content of an /element/ is
99 not parsed in this location.
100 4. Parsing of the inner content of an /element/, like a ~Pargraph~ with its markup
101 or inline images, is handled by the /element/ itself. Because an /element/
102 consists of several /runs/ that parsing is handled in =textruns.py=.