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

Hi guys,

I can’t manage to find a solution to my problem. I tryed on the r/obsidianMD on Reddit but it wasn’t successful.

In order to make some decks on Anki, I need one file with all my notes. I managed to get a note with all the links inside.

Now, I need to get the content, just below the link. Here’s an example :

From :

[[Link 1 to Note A]]

[[Link 2 to Note B]]

[[Link 3 to Note C]]

I would like that :

[[Link 1 to Note A]]

Content Note A

[[Link 2 to Note B]]

Content Note B

[[Link 3 to Note C]]

Content Note C

Is there a way to do that ?

Just one thing : i don’t want to display, i want to be able to modify the content. so, something like ![[Link]] doesn’t fit.

Hope someone can help me on that.

Thanks for your help !

Well, you can first create embeds, then turn into the reading mode and copy-paste all content an onse. The only downside is that you can lose some formatting.

Otherwise it is possible to write a script for templater to do this.

Assuming you have only links in your note, separated by line breaks, you can try this template (insert it afrer your link list):

let content = tp.file.content
let links = content.split("\n")
let result = ""

for (let link of links){
  if (link[0] == "[") {
    result += link + "\n"
    result += await tp.file.include(link) + "\n"
%><%*tR += result%>

It will probably not work properly if you have any other content in your note.

Do you expect to edit the original content of a note, and it to be reflected in the (collated) copy? Or vice versa, that you edit in the collated version, and changes should be brought back to the original?

Hello guys,

Thanks for the time you use to help me. I Appreciate it.

@reaty - So if I understand well, I just have to paste your code in my note, at the end, after the link list ?

I am not really familiar with coding and with obsidian neither by the way.

When i did it, a window opened and close 1 second after. Then nothing happens.

I guess something went wrong with the code, Here’s a screenshot :

Capture d’écran 2023-04-21 091800

I guess, the “[” is the issue here. If i change the [ by a simple letter, it looks to work better, the content doesn’t stay orange.

!here’s an example with an X instead of [ :

Capture d’écran 2023-04-21 092549

How can I use the “[” to make Obsidian understand that it’s like another letter ?

@holroy. No, I don’t. I want to edit the content imported without modify the original note.

Oh, no you are not supposed to paste the code into your note! You are supposed to insert it via the templater plugin. Did you never use it before?

Okay, first of all, create a folder in your vault, name it “templates”, then in this folder create note called “Convert links”. Put my code into this note. Don’t change anything in the code.

Then go to the Obsidian settings > Community plugins, enable plugins here, then press the “Browse” button and type “Templater”. You will find the Templater plugin, install it and turn it on. Open plugin’s settings and in the field “Template folder location” write “template” (the name of your templates folder).

Then go to your note with links, put the cursor at the very end of it, after all links. At this point you are supposed to have a templater button on the ribbon, it has these symbols: “<%”. Press it and choose your “Convert links” template.

Waw ! I feel dumb and thankful at the same time, haha !

I followed the process as recommended, but I still have an error :

“Templater error invalid file format, provide an obsidian link between quotes”

Is that because I use [[link]] and not [link] ?

Just by curiosity, I tried to add another “[” in the if line. When I click the <% button, nothing happens, no error message.

Just one detail, I still have the code above my note that contain only links, other pages are free from this code :
Capture d’écran 2023-04-21 150219

I hope you can help me with that … :slightly_smiling_face:

If you added code to the note with links, delete it. You don’t need it here. The code goes only to the file in template folder.

This error means that some of your links are incorrect. All the links must be in wiki-link format and look like “[[Link]]”. Try to check, maybe some link have a symbol missing.

I’am really sorry, I don’t see any error on my links, I double checked and they all link well to the note.

Could it be because there a line break between each link ?

Basicly,the file looks like this :

I tryed with and without space between links. (no space on the screenshot)

Does it works on your side ?

Could you show the source of those links? Are any using aliases? Are there any other characters on the various lines?

Hmm, I don’t know, it works for me (with line breaks or without them).
All the links lead to the normal markdown notes, right?

Try to use this code instead:

let content = tp.file.content
let links = content.split("\n")
let result = ""

for (let link of links){
  if (link[0] == "[") {
    try {
      let linkContent = await tp.file.include(link)
      result += link + "\n"
      result += linkContent + "\n"
     } catch (error) {
        console.log("Incorrect link: " + link)
%><%*tR += result%>

If it still does not work, open developer tools (press Ctrl+Shift+I), there should be message about what links are wrong.

@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.