Extract note A content from a link in note B and pastit down the link. Is that Possible

@reaty : It works perfectly now ! Thanks to the new code.
You’re kind of time (or life) saver for providing me this code (and time). Thannk you very much about.

Can I ask you one last thing ? Is there a way to choose content that I “import” ? Like “only import was is after “—”” or just after a Title ?

@holroy I was using regular obsidian links, like that → [[link]]. But it’s solved now. Thanks for your help.

If you have titles in your content notes, and they are all the same for all notes, you can change tp.file.include(link) for tp.file.include(link + "#my title"), just write your title instead of “my title”. It will paste the section between the given title and another title in your note, if there is one.

If all the titles in notes are different, it’s more complicated.

Woops ! I have seen that my edit didn’t make it through : About titles, I understand, Then no need to change anything, it awesome like that.

If you have titles in your content notes, and they are all the same for all notes, you can change tp.file.include(link) for tp.file.include(link + "#my title") , just write your title instead of “my title”. It will paste the section between the given title and another title in your note, if there is one.

I have a lot of notes with just links like that but they are all different.

I noticed a little issue : If I have 42 links, I activate the script and have only 16 notes left. Some are vanishing in the process.
I try to look for a pattern of missings links and there is none. It does something like (number = number of missing links between each note displayed ) :
3 - 8 - 2 - 0 - 0 - 1 - 1 - 1 - 3 - 1 - 2 - 3 - 1 (26 links lost on the procces out of 42)

I notice that after activating the script, some links became bold and some other don’t. I don’t know if there a reason.
But I don’t really inderstand what make them become bold. there is not some ** around or ## …

(I deleted a message because it was not accurate)

After some time, I have seen that some links are not recognized by Templater as an Obsidian link. That’s why I have some missing links.

I have to find a way to solve this issue. I will dig on it, at least, as much as I can. Currently, I don’t see any difference between a valid and invalid link.

Maybe templater doesn’t recognise some characters in notes names, or something like this. But I don’t know what can be done with it.
Did you try to open developers tools? There should be messages about wrong links. Maybe there is some pattern, like the same specific character used in them.

I’d still say that if you provided some test data, it would enable others to actually looking into your issues, instead of having us guessing on your setup and issues.

@reaty, here’s what I have on the console :

 Failed to load resource: net::ERR_CONNECTION_REFUSED 

It’s appearing like 500 times.

I have another error but I’am not sure it’s related :

app.js:1 TypeError: Cannot read properties of null (reading 'sections') at ObsidianTextEditor.acceptsTableEdit (plugin:table-editor-obsidian:23254:24) at TableEditor.cursorIsInTable (plugin:table-editor-obsidian:22350:34) at TableEditor.cursorIsInTable (plugin:table-editor-obsidian:23334:30) at eval (plugin:table-editor-obsidian:23610:28) at run (plugin:table-editor-obsidian:23584:102) at h (app.js:1:456462) at zs (app.js:1:456530) at Object.keydown (app.js:1:453996) at e.runCustomHandlers (app.js:1:378748) at n (app.js:1:377244)

And in issues : Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform

I don’t know if it’s what you need. Is it ?

@Holroy : how can I provide that ? Thanks to the console like reaty asked ?

I am not really confortable with code so, sometime, something very obvious to you might not be to me.

Instead of making a screenshot, you can just copy the text from the source mode, and insert it into a forum post, where you enter three backticks, ```, on the line in front and the line after the pasted text.

This will allow us to detect if there is something strange in your markup.

Ok, thanks, I Will do that.

So here’s an example of the links (not everything, it would be too much) :

[[Cerveau à l’origine du bien-être et de la souffrance.]]

[[La quête du bonheur pour soi même est vouée à l’échec]]

[[Le but de la méditation est de se transformer en une meilleure version de soi-même]]

[[L’esprit est un ensemble dynamique composé de succession d’instants de conscience]]

[[La méditation est un moyen d’analyser et comprendre la réalité]]

[[Pour méditer on observe les pensées, on passe à travers et on analyse la conscience.]] ‘’’

They are all made the same way.

Is that what you expected ? Do you need something else ?

I provided the error code before, is that helping ?

Thanks again for your help, much appreciated

1 Like

I don’t see in your console output what I was looking for. There should be messages like: “Invalid link: ‘[[Link]]’” in the very end. Don’t you get anything like this, after you trying to use the template?

I have change a little bit my way of generating my list of links and now I don’t have error anymore.

But it doesn’t work for all the links. So I guess it might have an error but according to the console, there’s nothing else.

I discovered Text Expand and Dataview (I use this one to generate my link list). Wouldn’t that be easier with an add-on like that ?

Are you using dataview or dataviewjs to produce the links in the first place? If the latter, then why don’t use that to also include the content of the files using something like await dv.io.load() directly instead of doing this as a secondary step?

Here is another version attempting to pull the content from the various links. This is slightly safer than previous versions since it checks for the full link, and allows for some text in front and after.

So save the following into a template file:

const content = tp.file.selection()
const lines = content.split("\n")
const LINK_RE = /\[\[.*\]\]/

for (const line of lines) {
  tR += line + "\n"
  const link = line.match(LINK_RE)
  if ( link ) {
    try {
      const linkContent = await tp.file.include( link[0] )
      tR += linkContent + "\n"
    } catch (error) {
      console.log(`Templater error for link: ${ link }:\n`, error)
      tR += "==No content found==\n"

And to run you either choose a hotkey for the template, or use the insert templater modal command, but before you insert the template be sure to select all the links you want to replace with a link and the content.

The previous versions, which doesn’t have this requirement will insert all the links from the current document at the point of the cursor when inserting the template, and leave other parts (aka all the links) untouched. This would appear to be some faulty links, but in fact it’s a faulty design choice since inserting a template by default will either be inserted at the cursor location, or replace the selected text with the output of the template.

To reiterate, after the inital setup of the template code into a template file of your choice, and potentially adding a hotkey of your choice, do the following:

  • Select all the lines containing links. This could very well be the entire file selected by doing Cmd A (or Ctrl A on windows)
  • Insert/run the template on the selected text, and it’ll get replaced by links following by the content of that link, if it has any
  • In addition, this version will produce an error message on the console if something fails, and add ==No content found== after the link in question

Hello Holroy,

Thanks for that code !

It looks to work perfectly well ! And it doesn’t forget any links, that’s even better. (@reaty : I really valuate your work as well !)

But it works only if I don’t generate links thanks to dataview. And if I want to copy/past links generated by Dataview, links are like that [link] and not like that [[link]]. So it’s a mess to deal with it …

The thing is that at the beginning of this topic, I didn’t use Dataview.

Now, It helps me organized my note automatically. On notes, I have on top, something like :
MoC : [[PSYCHOLOGY]]. So, when there’s a new note, there’s an automatic link on the page PSYCHOLOGY that link to my note. That’s an awesome add-on.

So now, Where would I put await dv.io.load() on your code to make it works with links generated by Dataview ?

Again : Thanks for the code (and your patience) !

Humm I am not sure if it would be possible to use your code on links generated by dataview.
When I select the content, click on the templater button, content is not selected anymore.


If the links are generated by dataview, you could potentially let that query also insert the content.

Do note, that will then become a dynamic query/page with the collation of everything, and not a static.

You can’t use/ run the template on top of the result from a query. At least not without some changes…

Yep, That’s my point.

I will find a way to make my links static. Otherwise it will be a mess.

Again, Thanks for your help !

1 Like

I have seen you help someone doing something very similar here : Can the notes filtered by dataview be set to automatically add a link to the current note? - #8 by holroy

Would you mind help me convert the wikilinks generated by dataview in obsidian links ?

I hope I am not asking to much. If it’s too long, I would understand.

Here’s a prompt I use to generate my links :


Thanks a lot for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.