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

Function lines

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

Source from the content-addressed store, hash-verified

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

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