### 차레 - TOC [[Notion]]이나 [[Anytype]]에는 문서의 머릿글을 뽑아내어 차례(table of contents)를 만들어주는 기능이 있다. [[Obsidian]]에서는 이개 가능할까? 일단은 가능하다! [[Obsidian 사용자 모임]]의 [깬아이](https://cafe.naver.com/ca-fe/cafes/30537448/articles/5595?page=1&boardtype=L&referrerAllArticles=true&oldPath=%2FArticleRead.nhn%3Fclubid%3D30537448%26page%3D1%26boardtype%3DL%26articleid%3D5595%26referrerAllArticles%3Dtrue#) 님이 정보를 주셨다. ### Table of Contents 플러그인 사용 - [Table of Contents](https://github.com/hipstersmoothie/obsidian-plugin-toc) [[Plugin|플러그인]]을 사용하는 방법. - 설치와 사용이 쉽고 안정적이다. - 차례를 작성할 당시의 파일 구조만 반영되고, 이후 파일 편집의 결과는 반영되지 않음. (정적 처리) - 머릿글의 제목이나 구조가 바뀌면 차례 파일을 다시 만들어 주어야 함. ### Dataview 플러그인 사용 - [[DataView]] [[Plugin|플러그인]]이 제공하는 [[JavaScript]] 기능을 이용하는 방법. - 한 번 등록해 놓으면 파일의 변화에 따라 동적으로 차례를 생성함. - [[DataView]] 플러그인을 설치해야 함. - [[Obsidian Publish]]에서는 차례가 표시되지 않음. - 다음의 코드를 `toc.js`로 저장하여 [[보관소]]의 최상단에 위치해야 함. ```js // Set this to 1 if you want to include level 1 headers, // or set it to 2 if you want to ignore level 1 headers const startAtLevel = 2 const content = await dv.io.load(dv.current().file.path) const toc = content.match(new RegExp(`^#{${startAtLevel},} \\S.*`, 'mg')) .map(heading => { const [_, level, text] = heading.match(/^(#+) (.+)$/) const link = dv.current().file.path + '#' + text return '\t'.repeat(level.length - startAtLevel) + `1. [[${link}|${text}]]` }) dv.header(2, 'Table of contents') dv.paragraph(toc.join('\n')) ``` - 자료 출처: [Type [toc] for a ToC](https://forum.obsidian.md/t/type-toc-for-a-toc/3941/17)