MCPcopy Create free account
hub / github.com/adobe/react-spectrum / lines

Function lines

packages/dev/s2-docs/src/Code.tsx:195–274  ·  view source on GitHub ↗
(node: HastNode)

Source from the content-addressed store, hash-verified

193);
194
195function lines(node: HastNode) {
196 let resultLines: HastNode[] = [];
197 let currentLine: (HastNode | HastTextNode)[] = [];
198 // let properties: Record<string, string> = {};
199 let grouping: HastNode | null = null;
200 let skip = false;
201 let endLine = () => {
202 if (skip) {
203 skip = false;
204 currentLine = [];
205 return;
206 }
207 let childNode = {
208 type: 'element',
209 tagName: 'div',
210 children: [{...node, children: currentLine}]
211 } as HastNode;
212 if (grouping) {
213 grouping.children.push(childNode);
214 } else {
215 resultLines.push(childNode);
216 }
217 currentLine = [];
218 };
219
220 for (let child of node.children) {
221 if (child.type === 'text' && 'value' in child) {
222 let parts = child.value.split('\n');
223 for (let part of parts.slice(0, -1)) {
224 if (part.length) {
225 currentLine.push({type: 'text', value: part});
226 }
227 endLine();
228 }
229 let last = parts.at(-1);
230 if (last?.length) {
231 currentLine.push({type: 'text', value: last});
232 }
233 continue;
234 } else if ('properties' in child && child.properties?.className === 'comment') {
235 let comment = text(child);
236 let begin = comment.match(/^(?:\/\/\/|\/\*)- begin (.+) -(?:\/\/\/|\*\/)$/);
237 if (begin) {
238 grouping = {
239 type: 'element',
240 tagName: begin[1],
241 children: []
242 } as any;
243 currentLine = [];
244 skip = true;
245 continue;
246 } else if (grouping && (comment.startsWith('///- end ') || comment.startsWith('/*- end '))) {
247 resultLines.push(grouping);
248 grouping = null;
249 currentLine = [];
250 skip = true;
251 continue;
252 }

Callers 1

Code.tsxFile · 0.85

Calls 5

endLineFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.80
textFunction · 0.70
atMethod · 0.65

Tested by

no test coverage detected