mrjackphil / obsidian-text-expand

A simple text expand plugin for Obsidian.md
186 stars 12 forks source link
obsidian-md obsidian-plugin

Text expand

This plugin will search files using Obsidian search functionality and then paste the result. The output can be customized using template feature.

Table of Contents

How to use

Search functionality

First line in expander code block is always a search request. You can leave it empty to use results from search panel as is.

Once searching, plugin waits some time (configurable) and extract results from search panel to template engine.

Template engines

eta template engine

You can use eta template engine for managing results.

## <%= it.current.frontmatter.title %>

<% it.files.forEach(file => { %>
   - <%= file.link %> 
<% }) %>

Use it object to access search results and fields for current file.

Path Type Description
it.current FileParameters Info about current file
it.files Array Info about files in search panel

FileParameters type has those fields.

Name Type Description Example
basename string Name of the file Obsidian
name string Full name of the file with extension Obsidian.md
content string Content of the file Obsidian\nContent of the file.
extension string Extension of the file .md
link string Wiki or MD link (depends on Obsidian's settings) [[Obsidian]]
path string Relative to vault root path to the file resources/Obsidian.md
frontmatter Object Returns all values from frontmatter { title: "Obsidian", author: MrJackphil }
stat Object File stats returned by Obsidian { ctime: 1654089929073, mtime: 1654871855121, size: 1712 }
links Array Array with links in the file
headings Array Array with headings in the file
sections Array Array with section of the file
listItems Array Array with list items of the file

sequence template engine (LEGACY)

Using template feature you can customize an output.

To create a list:

```expander
SEARCH_QUERY
- [[$filename]]
```

or to create a table:

```expander
SEARCH_QUERY
^|Filename|Content|
^|---|---|
|$filename|$lines:1|
```

Syntax looks like that:

```expander
SEARCH_QUERY
^This is a header
This line will be repeated for each file
Also, [[$filename]] <- this will be a link
>This is a footer
```

Special sequences

Regexp Description Usage example
$filename a basename of a file $filename
$link wikilink $link
$searchresult the context displayed in the Obsidian search, depending on the amount of context that is selected in the search window $searchresult
$matchline the line which contains the search query $matchline
$matchline:NUMBER the line which contains the search query and NUMBER lines after and before matched line $matchline:10
$matchline:+NUMBER the line which contains the search query and NUMBER lines after matched line $matchline:+10
$matchline:COUNT:LIMIT the line which contains the search query and NUMBER lines around and limit line by LIMIT characters $matchline:0:10
$lines the full content of the file $lines
$lines:NUMBER NUMBER lines from the file $lines:10
$ext extension of the file
$created
$size
$parent parent folder
$path path to file
$frontmatter:NAME frontmatter value from field NAME
$header:## all headers as links
$header:###HEADER headers as links $header:##Ideas
$header:"## Plugins for Obsidian"
$blocks all blocks paths from the note as links

Settings

Install

Manually