@@ -88,53 +88,7 @@ const TableOfContents: React.FC<TableOfContentsProps> = ({
8888 ( e : React . MouseEvent < HTMLAnchorElement > | Event , id : string ) => {
8989 e . preventDefault ( )
9090
91- // 다단계 요소 찾기 시스템
92- let element = document . getElementById ( id )
93-
94- if ( ! element ) {
95- // URL 인코딩된 ID로도 시도
96- try {
97- const encodedId = encodeURIComponent ( id )
98- element = document . getElementById ( encodedId )
99- } catch ( error ) {
100- // 인코딩 실패 시 무시
101- }
102- }
103-
104- if ( ! element ) {
105- // querySelector로 attribute selector 사용
106- element = document . querySelector ( `[id="${ id } "]` )
107- }
108-
109- if ( ! element ) {
110- // 대소문자 무시하고 ID로 찾기
111- const headings = document . querySelectorAll (
112- "h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]"
113- )
114- element =
115- ( Array . from ( headings ) . find (
116- h => h . id . toLowerCase ( ) === id . toLowerCase ( )
117- ) as HTMLElement ) || null
118- }
119-
120- if ( ! element ) {
121- // 텍스트 기반으로 헤딩 찾기
122- const headings = document . querySelectorAll ( "h1, h2, h3, h4, h5, h6" )
123- const coreKeyword = id . split ( "-" ) [ 0 ] ?. toLowerCase ( ) || ""
124-
125- element =
126- ( Array . from ( headings ) . find ( h => {
127- const text = h . textContent ?. trim ( ) . toLowerCase ( ) || ""
128-
129- if ( text === id . toLowerCase ( ) ) return true
130- if ( text . startsWith ( coreKeyword ) ) return true
131-
132- const cleanText = text . replace ( / [ ( ) ] / g, "" ) . trim ( )
133- if ( cleanText . includes ( coreKeyword ) ) return true
134-
135- return false
136- } ) as HTMLElement ) || null
137- }
91+ const element = document . getElementById ( id )
13892
13993 if ( element ) {
14094 const offsetTop = element . offsetTop - 100
0 commit comments