Skip to content

adder

This module contains the classes that represent adders.

Adders are used to add content to Obsidian notes.

Adder(fields: list[AdderField] = [])

Adder class.

Parameters:

  • fields (list[AdderField], default: [] ) –

    The fields of the adder.

Source code in pyobsidian/adder.py
302
303
def __init__(self: Self, fields: list[AdderField] = []) -> None:
    self.__fields = fields

add_field(field: AdderField) -> Adder

Add a new adder field to the adder.

Parameters:

Returns:

  • Adder

    The new adder.

Source code in pyobsidian/adder.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
def add_field(self: Self, field: AdderField) -> Adder:
    """Add a new adder field to the adder.

    Parameters
    ----------
    field : AdderField
        The field to be added.

    Returns
    -------
    Adder
        The new adder.
    """
    cur_fields = self.fields
    new_fields = cur_fields + [field]
    new_adder = Adder(new_fields)
    return new_adder

AdderField(key: AdderKey, value: AdderValue, where: AdderFieldWhere) dataclass

Class that represents an adder field.

AdderRegistry

Adder registry.

Consolidates AdderWhere along with its possible formatters. T

add_formatter(by: str, where: str, formatter: Formatter) -> dict[tuple[str, str], Formatter] classmethod

Add a new adder formatter to Adder class.

Parameters:

  • by (str) –

    The key of the formatter.

  • where (str) –

    The where of the formatter.

  • formatter (Formatter) –

    The formatter to be added.

Returns:

  • dict[tuple[str, str], Formatter]

    The updated formatters.

Source code in pyobsidian/adder.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
@classmethod
def add_formatter(
    cls: Type, 
    by: str, 
    where: str, 
    formatter: Formatter
) -> dict[tuple[str, str], Formatter]:
    """Add a new adder formatter to Adder class.

    Parameters
    ----------
    by : str
        The key of the formatter.
    where : str
        The where of the formatter.
    formatter : Formatter
        The formatter to be added.

    Returns
    -------
    dict[tuple[str, str], Formatter]
        The updated formatters.
    """
    cls.formatters[(by, where)] = formatter
    return cls.formatters

add_registry(key: str, where: AdderWhere) -> dict[str, AdderWhere] classmethod

Add a new where to the registry.

Parameters:

  • key (str) –

    The key of the where.

  • where (AdderWhere) –

    The where to add.

Source code in pyobsidian/adder.py
227
228
229
230
231
232
233
234
235
236
237
238
239
@classmethod
def add_registry(cls: Type, key: str, where: AdderWhere) -> dict[str, AdderWhere]:
    """Add a new where to the registry.

    Parameters
    ----------
    key : str
        The key of the where.
    where : AdderWhere
        The where to add.
    """
    cls.where[key] = where
    return cls.where

get_formatter(by: str, where: AdderFieldWhere) -> Optional[Formatter] classmethod

Get the adder formatter.

Parameters:

  • by (str) –

    The key of the formatter.

  • where (AdderFieldWhere) –

    The where of the formatter.

Returns:

Source code in pyobsidian/adder.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
@classmethod
def get_formatter(
    cls: Type, 
    by: str, 
    where: AdderFieldWhere
) -> Optional[Formatter]:
    """Get the adder formatter.

    Parameters
    ----------
    by : str
        The key of the formatter.
    where : AdderFieldWhere
        The where of the formatter.

    Returns
    -------
    Optional[Formatter]
        The formatter.
    """
    if isinstance(where, tuple):
        return cls.formatters.get((by, where[0]))
    return cls.formatters.get((by, where))

get_where(key: str | tuple) -> Optional[AdderWhere] classmethod

Get the adder where.

Parameters:

  • key (str) –

    The key of the where.

Source code in pyobsidian/adder.py
214
215
216
217
218
219
220
221
222
223
224
225
@classmethod
def get_where(cls: Type, key: str | tuple) -> Optional[AdderWhere]:
    """Get the adder where.

    Parameters
    ----------
    key : str
        The key of the where.
    """
    if isinstance(key, tuple):
        return cls.where.get(key[0])
    return cls.where.get(key)

AdderWhere

Bases: Protocol

Interface for adder where.

exec(note: Note, field: AdderField) -> Optional[str]

Execute the adder where.

Parameters:

  • note (Note) –

    The note to add the content to.

  • field (AdderField) –

    The field to add the content to.

Returns:

  • Optional[str]

    The content to add to the note.

Source code in pyobsidian/adder.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def exec(
    self: Self, 
    note: Note,
    field: AdderField
) -> Optional[str]:
    """Execute the adder where.

    Parameters
    ----------
    note : Note
        The note to add the content to.
    field : AdderField
        The field to add the content to.

    Returns
    -------
    Optional[str]
        The content to add to the note.
    """
    ...

AdderWhereInline

Bases: AdderWhere

Class that represents an adder where inline.

AdderWhereOpMkHeader

Bases: AdderWhere

Class that represents an adder where op mk header.

AdderWhereYaml

Bases: AdderWhere

Class that represents an adder where yaml.