Skip to content

Presets ​

Presets are reusable dynamic or static content snippets that can be used in templates and notes. Reference them using the {{identifier}} format.

Use Cases ​

  • Automatically insert current date/time
  • Define frequently used text snippets
  • Create dynamic content with parameters
  • Set cursor focus position in templates

Open Presets Management ​

Click the Presets icon in the sidebar to enter the presets management page.

Preset Types ​

Static Presets ​

Fixed text content that directly replaces with the set value when inserted.

Example:

  • Identifier: signature
  • Value: —— John Doe

Using {{signature}} will be replaced with —— John Doe

Dynamic Presets ​

Use JavaScript code to dynamically generate content, with parameter support.

Example:

  • Identifier: date
  • Code:
javascript
function(context, params = { format: 'YYYY/MM/DD' }) {
  return context.dayjs().format(params.format);
}

Built-in Presets ​

The system provides the following built-in presets:

IdentifierDescriptionDefault Output
timeCurrent time14:30:00
dateCurrent date2025/01/20
datetimeFull date and time2025/01/20 14:30:00
focusCursor focus positionNo output, cursor positions here

Using Presets ​

In the Editor ​

  1. Type {{ to trigger the preset selector
  2. Type the identifier to search
  3. Select a preset and press Enter to insert

In Templates ​

Use {{ in the template editor to trigger the selector. Inserted presets will be automatically replaced when the template is applied.

Parameter Usage ​

Dynamic presets support parameters to customize output format.

Parameter Format ​

Parameters use JSON object format, passed via | separator: {{identifier|{"key": "value"}}}

Usage Examples ​

Custom Date Format ​

Default {{date}} output: 2025/01/20

With params {{date|{"format": "YYYY-MM-DD"}}}, output: 2025-01-20

With params {{date|{"format": "MMM DD, YYYY"}}}, output: Jan 20, 2025

Custom Time Format ​

Default {{time}} output: 14:30:00

With params {{time|{"format": "HH:mm"}}}, output: 14:30

With params {{time|{"format": "h:mm A"}}}, output: 2:30 PM

Custom DateTime Format ​

Default {{datetime}} output: 2025/01/20 14:30:00

With params {{datetime|{"format": "MMMM DD, YYYY at HH:mm"}}}, output: January 20, 2025 at 14:30

Date Format Reference ​

TokenDescriptionExample
YYYY4-digit year2025
YY2-digit year25
MMMMFull month nameJanuary
MMMAbbreviated monthJan
MM2-digit month01
MMonth1
DD2-digit day20
DDay20
HH24-hour hour14
hh12-hour hour (padded)02
h12-hour hour2
mmMinutes30
ssSeconds00
AAM/PMPM
aam/pmpm
ddddFull weekdayMonday
dddAbbreviated weekdayMon

Creating Custom Presets ​

  1. Click the New button in the top toolbar
  2. Fill in:
    • Identifier: Supports Chinese, English, numbers, underscores, e.g., my_preset (identifiers can be duplicated, but using unique identifiers is recommended for clarity)
    • Description: Optional, explains the preset's purpose
    • Type: Static or Dynamic
    • Value: For static type, enter fixed text; for dynamic type, enter JavaScript function
  3. Click Save

Dynamic Preset Code Specification ​

javascript
function(context, params = { /* default params */ }) {
  // context provides:
  // - context.dayjs: dayjs library for date/time handling
  // - context.focus(): call to position cursor here
  
  // params is the user-provided parameter object
  
  return 'returned text content';
}

Available Globals and Methods:

  • Basic types: Array, Boolean, Date, JSON, Math, Number, Object, String, RegExp
  • Utility methods: parseInt, parseFloat, isNaN, isFinite, encodeURI, encodeURIComponent, decodeURI, decodeURIComponent
  • Date handling: dayjs (full dayjs library with the following plugins loaded)
    • utc - UTC time support
    • timezone - Timezone support
    • weekOfYear - Week of year
    • dayOfYear - Day of year
    • isoWeek - ISO week standard
    • isSameOrBefore - Date comparison
    • isSameOrAfter - Date comparison
    • isBetween - Date range check
    • duration - Duration calculation
    • relativeTime - Relative time (e.g., "3 days ago")
    • customParseFormat - Custom parse format
    • advancedFormat - Advanced formatting options
  • Network requests: fetch (supports async network requests)

Security Restrictions:

  • Code executes in a sandboxed environment with no access to file system, Electron APIs, or other system features
  • Execution timeout limit: 5 seconds
  • Prohibited: require, import, eval, window, document, localStorage, etc.

Example: Date Range ​

Generate a date range string, useful for meeting notes or project planning.

javascript
function(context, params = { startDate: '', days: 7, format: 'YYYY-MM-DD' }) {
  const { dayjs } = context;
  const start = params.startDate ? dayjs(params.startDate) : dayjs();
  const end = start.add(params.days, 'day');
  return `${start.format(params.format)} ~ ${end.format(params.format)}`;
}

Usage:

  • {{dateRange}} → 2025-01-20 ~ 2025-01-27 (from today, 7 days by default)
  • {{dateRange|{"days": 30}}} → 2025-01-20 ~ 2025-02-19 (30 days)
  • {{dateRange|{"startDate": "2025-02-01", "days": 14}}} → 2025-02-01 ~ 2025-02-15 (custom start date)
  • {{dateRange|{"days": 7, "format": "MMM DD"}}} → Jan 20 ~ Jan 27

Example: Day of Week ​

Get the day of week for a specified date, with long/short format support.

javascript
function(context, params = { date: '', format: 'long' }) {
  const { dayjs } = context;
  const targetDate = params.date ? dayjs(params.date) : dayjs();
  const weekdays = {
    long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  };
  return weekdays[params.format][targetDate.day()];
}

Usage:

  • {{weekday}} → Monday (current date)
  • {{weekday|{"date": "2025-01-01"}}} → Wednesday (specified date)
  • {{weekday|{"date": "2025-01-20", "format": "short"}}} → Mon (short format)