MCPcopy Index your code
hub / github.com/lingodotdev/lingo.dev / resolvePathToElement

Function resolvePathToElement

packages/cli/src/cli/loaders/html.ts:168–215  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

166
167 // Resolve path to element in the DOM
168 function resolvePathToElement(path: string): Element | null {
169 const parts = path.split("/");
170 const [rootTag, ...indices] = parts;
171
172 let current: Element | null = null;
173
174 if (html) {
175 // Full HTML document with <html>, <head>, <body>
176 // Find head or body
177 if (rootTag === "head") {
178 current = domutils.findOne(
179 (elem) =>
180 elem.type === "tag" && elem.name.toLowerCase() === "head",
181 html.children,
182 true,
183 ) as Element | null;
184 } else if (rootTag === "body") {
185 current = domutils.findOne(
186 (elem) =>
187 elem.type === "tag" && elem.name.toLowerCase() === "body",
188 html.children,
189 true,
190 ) as Element | null;
191 }
192
193 if (!current) return null;
194
195 // Traverse by indices
196 return traverseByIndices(current, indices);
197 } else {
198 // HTML fragment - no <html> element
199 // Path is just numeric indices from root
200 const rootElements = dom.filter(
201 (child): child is Element => child.type === "tag",
202 );
203
204 // First part is the root index
205 const rootIndex = parseInt(rootTag, 10);
206 if (rootIndex >= rootElements.length) {
207 return null;
208 }
209
210 current = rootElements[rootIndex];
211
212 // Traverse remaining indices
213 return traverseByIndices(current, indices);
214 }
215 }
216
217 // Apply translations
218 for (const [path, value] of Object.entries(data)) {

Callers 1

pushFunction · 0.70

Calls 1

traverseByIndicesFunction · 0.70

Tested by

no test coverage detected