Linking to specific list element

What I’m trying to do

I am trying to create internal link to element of the list.
Example:

[file1.md]

This is my list
1. apples
 child section of apples
2. bananas
3. oranges
 child section of oranges

[file2.md]

this is link to third element of the list in other file!
![[file1#^oranges]]

Things I have tried

I’ve tried using blocks to link but whole list is detected as one block. Because of this i cannot link selected element of the list, only list as a whole.

I know that separating elements of the list like that:

1. first

2. second

3. third

fixes this block detection, but I am not satisfied with this solution.
Is there a way to link directly to list element?
Is there a way of separating text to block other then newline?
Is there a way of linking to selected word or line?

Thanks,
Michał

1 Like

Give this a try:

This is my list
1. apples
 child section of apples
2. bananas
3. oranges 
 child section of oranges ^oranges

***

[[Untitled#^oranges]]

CleanShot 2023-10-08 at 08.29.03

Is there way to hide the ^Oranges part in Live Preview or in Read mode?

So the example you provided is working as I needed. But when I try to use it in my main file it fails. Here is what I found:

this works good:

1. this is first
 text after enter
2. another point
  lorem ipsum
  dolor sit
  amet ^test-12
3. third example

[[test#^test-12]]

and this doesn’t:

1. this is first
 
 text after enter
2. another point
  lorem ipsum
  dolor sit
  amet ^test-12
3. third example

[[test#^test-12]]

in the second code block you can see I added enter in 1 point, it looks like it breaks it. This is why I am having this issue.
Peek 2023-10-08 03-14

Is this possibly a bug?

Thanks,
Michał

In your second example just above, if you switch to Reading view you’ll see everything from text after... isn’t in a list. That seems to be the issue.


If you try something like this. I used Shift + Enter to create the blank line, but that doesn’t seem mandatory here.

1. this is first

   text after
2. two
  lorem
  amet ^lineid1
3. three

^listid1

[[Untitled#^lineid1]]
[[Untitled#^listid1]]

This seems to work (the clip is from Live Preview).

CleanShot 2023-10-08 at 11.09.27

I’m using this CSS snippet for this purpose. You can entirely hide it by setting opacity: 0;, but I think it can be dangerous.

/* Block IDs on inactive lines */
.cm-blockid {
    opacity: 0.2;
}
/* Block IDs on active lines */
.cm-active .cm-blockid {
    opacity: 0.7;
}

This is a little bit modified version of hey_look_its_shiny’s Reddit post.

1 Like

Hi I really appreciate your help. I marked this problem as solved because your solution works for question I created. Unfortunately I still have a problem and I am totally lost, I am attaching gif and whole code section. I am not able to create working link to element for some reason without separating elements by newline.

Peek 2023-10-08 19-18

5. Tautologia - zdanie które zawsze ma wartość równoważną z 1
 prawo de Morgana -> $\sim(p\wedge q)<=> \sim p\vee \sim q$
 rozwiązanie prawa de Morgana przez tabele bitową:
 
 | p   | q   | $\sim (p \wedge q)$ | $\sim p \vee \sim q$ | <=> |
 | --- | --- | ------------------- | -------------------- | --- |
 | 1   | 0   | 1                   | 1                    | 1   |
 | 0   | 1   | 1                   | 1                    | 1   |
 | 1   | 1   | 0                   | 0                    | 1   |
 | 0   | 0   | 1                   | 1                    | 1   |
 
 jak widać wartość końcowa zdania zawsze jest równa 1 - niezależnie od wartości `p` i `q`. W ten sposób udowodniliśmy, że to zdanie to tautologia. Innym sposobem rozwiązania tautologii może być sprowadzenie do podstawowych tautologii. Poniżej parę przykładów innych tautologii:
 ![[tautologie.png]]
6. Funkcje zdaniowe - wyrażenie o zmiennej wartości
 $\large x \in R$
 $\large \Phi(x): sin(x)>0$
 $\large \Phi (\frac{\pi}{2})\Leftrightarrow1$
 $\large \Phi\left(\frac{\pi}{2}\right)\Leftrightarrow0$ ^test-1
7. Zakres zmienności
 Zakresem zmienności nazywamy zbiory z których możemy czerpać wartości dla zmiennych w funkcjach zdaniowych

![[Untitled#^test-1]]

Thanks for help,
Michał

In general things work best in Markdown (and extensions to Markdown) when you separate different things with blank lines, even when it’s not strictly required.

Normally that’s not needed with list items (they are the same, not different), but your list items have multiple lines. You may have done your multi-line list items incorrectly. Check Reading View — if you see unexpected results (like each list item being its own list) then you did the list wrong. Indent the second and further lines of each item by 1 tab or 4 spaces. If that doesn’t work, you may also need blank lines.

1 Like

As Cawlin said, Markdown works best when you separate elements with a blank line. Here your ![[tautologie.png]] image and 6. Funkcje... aren’t separated and 6/7 aren’t considered list items, but the blockID embed does work in Reading view.

Reading view:

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