mrjackphil / obsidian-text-expand

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

Request: sequence to return a certain number of characters #64

Closed sonsche closed 2 years ago

sonsche commented 2 years ago

The sequence $lines:## returns too much text for me, since I am searching in big text blocks without line breaks. Too much text seems to break the table syntax. And it often only returns “—” .

Could a sequence be added that only returns a certain number of characters before and after the search term? It would really save me a LOT of time copying and pasting text snippets.

Edit for more info:

Because the notes I search in are longform text and have few linebreaks, $lines:1 will give me a lot of text that seems to break the table formatting, or it will return no text at all, just "---" :

1.) too much text Obs_expand_too much text

2.) no text (and file 151_c23 does not contain the search term) Obs_expand_no text

Would it be possible to have a sequence $characters:10 to just show a custom number of characters for context, like in the original Obsidian search, like this?

Obs_search output

Thank you very much for your work!!

mrjackphil commented 2 years ago

Update plugin to 0.10.1 and try $characters:50.

sonsche commented 2 years ago

Thank you for updating it! Unfortunately, now it returns the FIRST 50 characters of the file, not before and after the search term :/

So I mostly get metadata: Obs_expand_first characters

mrjackphil commented 2 years ago

@sonsche Try $matchline

sonsche commented 2 years ago

Still not working... Like this?

wahrheit
^|Filename|Content|
^|---|---|
|[[$filename]]|$matchline $characters:50|

The search term is highlighted now though :) Obs_expand_matchline

mrjackphil commented 2 years ago

@sonsche Can you provide a little .zip with minimal reproducible issue? $matchline returns the paragraph which might be not enough for your use case.

You can remove $characters:50 when you use $matchline

mrjackphil commented 2 years ago

I'll keep this issue opened until we can handle this issue.

sonsche commented 2 years ago

Here are a few pages where I've tested $characters:50, $lines:2 and $matchline. I tried it out in a new vault without any plugins and unfortunately no luck. And the $lines:2 output also changed a lot since the update, now giving out lines from the top of the file with metadata.

expand test.zip

Thank you again for taking the time!

mrjackphil commented 2 years ago

@sonsche Just pushed 0.10.7 which has some limit functionality for $matchline.

Syntax works like that: $matchline:2:100 which means:

image

It's very dirty. I should rethink the way this plugin was implemented. I didn't think what someone will use this plugin.

sonsche commented 2 years ago

I am realizing that it might have been a naive to assume that it would be possible to "just print" the context that the original search is showing. Although I admit that my use case might be a bit specific...

The good news: the table looks great now! The bad news: the results don't always show the search result, but probably the beginning of file which is the beginning of the "line". And strangely, the highlight is not visible in the active note, but shows up if I print to PDF --- but that seems to be a separate problem with the table formatting.

matchline:1:200 works, matchline:2:100 not so much

expand_matchline 1-200 .pdf expand_matchline 2-100 .pdf expand_matchline 0-100 .pdf

mrjackphil commented 2 years ago

@sonsche

0.10.8 just landed. Try:

wahrheit
^|Filename|Content|
^|---|---|
|$link|$searchresult|

So added the new sequence $searchresult.

sonsche commented 2 years ago

Brilliant, I can work with this! The table formatting is still wonky (probably nothing to do with the expander), so I will just create a regular list. I can get a week's work done in a day! <3 Thank you so much!