Skip to content

Commit 09a9c5d

Browse files
committed
docs: add content getter usage documentation
Added documentation tracking all usages of Editor.content and note.content getters in the Templating plugin. Helps with understanding attachment path handling and content access patterns.
1 parent e638e37 commit 09a9c5d

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Content Getter Usage in np.Templating
2+
3+
.contentWithAbsoluteAttachmentPaths
4+
5+
Discussion: [Discord](https://discord.com/channels/763107030223290449/1419640432681418836/1427347411923243143)
6+
7+
This document lists all places where `Editor.content` or `note.content` is used as a getter (reading the value) in the np.Templating plugin.
8+
9+
## Summary
10+
11+
- **Total Files**: 4
12+
- **Editor.content Occurrences**: 6
13+
- **note.content Occurrences**: 5
14+
- **paragraph.content Occurrences**: 2 (see separate section below)
15+
16+
---
17+
18+
## Part 1: Editor.content Usage
19+
20+
### File: `src/Templating.js`
21+
22+
#### Function: `templateInsert`
23+
**[Line 120](src/Templating.js#L120)**
24+
```javascript
25+
templateData = Editor.content
26+
```
27+
- **Purpose**: Getting current editor content when using `<current>` template
28+
- **Context**: Using the currently open note as a template
29+
- **File**: `np.Templating/src/Templating.js:120`
30+
31+
#### Function: `templateAppend`
32+
**[Line 147](src/Templating.js#L147)**
33+
```javascript
34+
const content: string = Editor.content || ''
35+
```
36+
- **Purpose**: Getting current editor content for length calculation
37+
- **Context**: Determining where to append template content
38+
- **File**: `np.Templating/src/Templating.js:147`
39+
40+
**[Line 158](src/Templating.js#L158)**
41+
```javascript
42+
templateData = Editor.content
43+
```
44+
- **Purpose**: Getting current editor content when using `<current>` template
45+
- **Context**: Using the currently open note as a template
46+
- **File**: `np.Templating/src/Templating.js:158`
47+
48+
#### Function: `templateInvoke`
49+
**[Line 196](src/Templating.js#L196)**
50+
```javascript
51+
const content: string = Editor.content || ''
52+
```
53+
- **Purpose**: Getting current editor content (though variable appears unused)
54+
- **Context**: Initial setup for template invoke
55+
- **File**: `np.Templating/src/Templating.js:196`
56+
57+
#### Function: `templateQuickNote`
58+
**[Line 419](src/Templating.js#L419)**
59+
```javascript
60+
const content: string = Editor.content || ''
61+
```
62+
- **Purpose**: Getting current editor content (though variable appears unused)
63+
- **Context**: Initial setup for quick note creation
64+
- **File**: `np.Templating/src/Templating.js:419`
65+
66+
#### Function: `templateMeetingNote`
67+
**[Line 548](src/Templating.js#L548)**
68+
```javascript
69+
const content: string = Editor.content || ''
70+
```
71+
- **Purpose**: Getting current editor content (though variable appears unused)
72+
- **Context**: Initial setup for meeting note creation
73+
- **File**: `np.Templating/src/Templating.js:548`
74+
75+
#### Function: `templateConvertNote`
76+
**[Line 844](src/Templating.js#L844)**
77+
```javascript
78+
const note = Editor.content || ''
79+
```
80+
- **Purpose**: Getting current editor content for conversion
81+
- **Context**: Converting a project note to frontmatter format
82+
- **File**: `np.Templating/src/Templating.js:844`
83+
84+
---
85+
86+
## Part 2: note.content Usage
87+
88+
### File: `src/NPTemplateRunner.js`
89+
90+
#### Function: `writeNoteContents`
91+
**[Line 272](src/NPTemplateRunner.js#L272)**
92+
```javascript
93+
`writeNoteContents replaceHeading: note.content.includes(headingParagraph.content): ${String(note.content?.includes(`# ${headingParagraph.content}`))}`,
94+
```
95+
- **Purpose**: Checking if note content includes a specific heading
96+
- **Context**: Debugging/error logging when replacing a heading
97+
- **File**: `np.Templating/src/NPTemplateRunner.js:272`
98+
99+
#### Function: `getTemplateData`
100+
**[Line 360](src/NPTemplateRunner.js#L360)**
101+
```javascript
102+
templateData = selectedTemplate ? trTemplateNote?.content || '' : ''
103+
```
104+
- **Purpose**: Getting template data from a template note
105+
- **Context**: Loading template content for processing
106+
- **File**: `np.Templating/src/NPTemplateRunner.js:360`
107+
108+
### File: `src/Templating.js`
109+
110+
#### Function: `templateInsert`
111+
**[Line 123](src/Templating.js#L123)**
112+
```javascript
113+
templateData = templateNote?.content || ''
114+
```
115+
- **Purpose**: Getting template data from a template note
116+
- **Context**: Loading template content for insertion
117+
- **File**: `np.Templating/src/Templating.js:123`
118+
119+
#### Function: `templateAppend`
120+
**[Line 161](src/Templating.js#L161)**
121+
```javascript
122+
templateData = templateNote?.content || ''
123+
```
124+
- **Purpose**: Getting template data from a template note
125+
- **Context**: Loading template content for appending
126+
- **File**: `np.Templating/src/Templating.js:161`
127+
128+
### File: `lib/support/modules/NoteModule.js`
129+
130+
#### Function: `content`
131+
**[Line 55](lib/support/modules/NoteModule.js#L55)**
132+
```javascript
133+
let content = this.getCurrentNote()?.content
134+
```
135+
- **Purpose**: Getting note content to return (optionally stripping frontmatter)
136+
- **Context**: Method to access current note's content
137+
- **File**: `np.Templating/lib/support/modules/NoteModule.js:55`
138+
139+
#### Function: `getRandomLine`
140+
**[Line 81](lib/support/modules/NoteModule.js#L81)**
141+
```javascript
142+
let fullNoteContent = note.content || ''
143+
```
144+
- **Purpose**: Getting note content to extract a random line
145+
- **Context**: Retrieving full note content for processing
146+
- **File**: `np.Templating/lib/support/modules/NoteModule.js:81`
147+
148+
---
149+
150+
## Part 3: Paragraph Content Usage (para|paragraph|p.content)
151+
152+
**Note**: These are separated out as they are a different use case than Editor/note content.
153+
154+
### File: `src/NPTemplateRunner.js`
155+
156+
#### Function: `replaceHeading`
157+
**[Line 96](src/NPTemplateRunner.js#L96)**
158+
```javascript
159+
const paraMatch = para.content.match(/^#+/)
160+
```
161+
- **Purpose**: Getting content from a paragraph to match heading level
162+
- **Context**: Finding the next heading of same or higher level
163+
- **File**: `np.Templating/src/NPTemplateRunner.js:96`
164+
165+
**[Line 272](src/NPTemplateRunner.js#L272)** (also referenced in note.content section above)
166+
```javascript
167+
`writeNoteContents replaceHeading: note.content.includes(headingParagraph.content): ${String(note.content?.includes(`# ${headingParagraph.content}`))}`,
168+
```
169+
- **Purpose**: Getting content from heading paragraph for comparison
170+
- **Context**: Debugging/error logging when replacing a heading
171+
- **File**: `np.Templating/src/NPTemplateRunner.js:272`
172+
173+
### File: `lib/support/modules/TasksModule.js`
174+
175+
#### Function: `_ensureBlockIdsForOpenTasks`
176+
**[Line 94](lib/support/modules/TasksModule.js#L94)**
177+
```javascript
178+
const openTaskParagraphs = getOpenTasksAndChildren(note.paragraphs.filter((p) => p.content.trim() !== ''))
179+
```
180+
- **Purpose**: Filtering out empty paragraphs by checking content
181+
- **Context**: Getting open tasks and ensuring they have block IDs
182+
- **File**: `np.Templating/lib/support/modules/TasksModule.js:94`
183+
184+
---
185+
186+
## Usage Patterns Summary
187+
188+
### Editor.content
189+
- **Count**: 6 occurrences (all in Templating.js)
190+
- **Common patterns**:
191+
- `Editor.content` - direct access when using `<current>` template
192+
- `Editor.content || ''` - with fallback to empty string
193+
- **Primary uses**:
194+
- Getting content when `<current>` is specified as template (2x)
195+
- Getting content length for insertion/append operations (1x)
196+
- Getting content for note conversion (1x)
197+
- Unused variable initialization (3x - lines 196, 419, 548)
198+
199+
### note.content
200+
- **Count**: 5 occurrences (3 files)
201+
- **Common patterns**:
202+
- `templateNote?.content || ''` - most common pattern for loading templates
203+
- `note.content?.includes()` - checking if content contains text
204+
- `note.content || ''` - with fallback to empty string
205+
- **Primary uses**:
206+
- Loading template content from template notes (3x)
207+
- Checking if content contains specific text (1x - debug logging)
208+
- Getting content for processing/conversion (1x)
209+
210+
### paragraph.content
211+
- **Count**: 2 occurrences (2 files)
212+
- **Common patterns**:
213+
- `para.content.match()` - pattern matching on paragraph content
214+
- `p.content.trim()` - checking for empty content
215+
- **Primary uses**:
216+
- Matching heading levels (1x)
217+
- Filtering empty paragraphs (1x)
218+
219+
---
220+
221+
## Recommendations
222+
223+
If you're planning to replace direct `.content` access with a function call or different API:
224+
225+
1. **Editor.content** (6 occurrences)
226+
- Consider if this needs special handling since it's the active editor
227+
- Note: 3 instances appear to be unused variables (lines 196, 419, 548 in Templating.js)
228+
229+
2. **note.content** (5 occurrences)
230+
- Most common pattern is `templateNote?.content || ''` for loading templates
231+
- Often used with optional chaining `?.content`
232+
- One instance is for debug logging only
233+
234+
3. **paragraph.content** (2 occurrences) - SEPARATE USE CASE
235+
- Used for filtering and matching operations
236+
- May not need to be changed if note/Editor changes are made
237+

0 commit comments

Comments
 (0)