File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,6 +203,16 @@ export class ListItem {
203203 return this . file . cachedMetadata ?. links ?? [ ] ;
204204 }
205205
206+ /**
207+ * Return a list of links in the task or list item's line.
208+ *
209+ * The data contest is documented here:
210+ * https://docs.obsidian.md/Reference/TypeScript+API/LinkCache
211+ */
212+ public get links ( ) : LinkCache [ ] {
213+ return this . linksInFileBody . filter ( ( link ) => link . position . start . line === this . lineNumber ) ;
214+ }
215+
206216 /**
207217 * Return the name of the file containing this object, with the .md extension removed.
208218 */
Original file line number Diff line number Diff line change @@ -212,6 +212,13 @@ describe('links', () => {
212212
213213 expect ( tasks [ 0 ] . linksInFileBody . length ) . toEqual ( 3 ) ;
214214 } ) ;
215+
216+ it ( 'should return all links in the task line' , ( ) => {
217+ const tasks = readTasksFromSimulatedFile ( links_everywhere ) ;
218+
219+ expect ( tasks [ 0 ] . links . length ) . toEqual ( 1 ) ;
220+ expect ( tasks [ 0 ] . links [ 0 ] . original ) . toEqual ( '[[link_in_task_wikilink]]' ) ;
221+ } ) ;
215222} ) ;
216223
217224describe ( 'identicalTo' , ( ) => {
You can’t perform that action at this time.
0 commit comments