-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
108 lines (94 loc) · 2.63 KB
/
__init__.py
File metadata and controls
108 lines (94 loc) · 2.63 KB
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
"""
Logseq Content Builders - DSL for Programmatic Content Generation
This module provides a fluent interface for building Logseq content programmatically,
eliminating the need for string templates and providing type-safe content construction.
It also includes parsing functionality to convert existing Logseq content back into
builder objects, creating a unified read/write system.
Example Usage:
>>> from logseq_py.builders import PageBuilder, TaskBuilder, CodeBlockBuilder
>>>
>>> # Creating new content
>>> page = (PageBuilder("My Demo Page")
... .property("author", "John Doe")
... .property("created", "2025-01-08")
... .heading(1, "Welcome to My Demo")
... .text("This page demonstrates programmatic content creation.")
... .add(TaskBuilder().todo().priority("A").text("Complete the demo"))
... .add(CodeBlockBuilder("python")
... .line("def hello_world():")
... .line(" print('Hello, Logseq!')"))
... .build())
>>>
>>> # Reading existing content as builders
>>> from logseq_py.builders import BuilderBasedLoader
>>> loader = BuilderBasedLoader("/path/to/logseq")
>>> page_builder = loader.load_page_as_builder("My Page")
>>> modified_content = loader.modify_page_content("My Page",
... lambda p: p.add(TaskBuilder().todo().text("New task")))
"""
from pathlib import Path
from .core import (
ContentBuilder,
BlockBuilder,
LogseqBuilder
)
from .content_types import (
TextBuilder,
HeadingBuilder,
ListBuilder,
TaskBuilder,
CodeBlockBuilder,
MathBuilder,
QuoteBuilder,
TableBuilder,
MediaBuilder,
DiagramBuilder,
DrawingBuilder
)
from .page_builders import (
PageBuilder,
PropertyBuilder,
TemplateBuilder
)
from .advanced_builders import (
QueryBuilder,
JournalBuilder,
WorkflowBuilder,
DemoBuilder
)
from .parser import (
BuilderParser,
ContentReconstructor,
BuilderBasedLoader
)
__all__ = [
# Core builders
'ContentBuilder',
'BlockBuilder',
'LogseqBuilder',
# Content type builders
'TextBuilder',
'HeadingBuilder',
'ListBuilder',
'TaskBuilder',
'CodeBlockBuilder',
'MathBuilder',
'QuoteBuilder',
'TableBuilder',
'MediaBuilder',
'DiagramBuilder',
'DrawingBuilder',
# Page builders
'PageBuilder',
'PropertyBuilder',
'TemplateBuilder',
# Advanced builders
'QueryBuilder',
'JournalBuilder',
'WorkflowBuilder',
'DemoBuilder',
# Parser and reconstruction
'BuilderParser',
'ContentReconstructor',
'BuilderBasedLoader'
]