(source)
| 956 | } |
| 957 | |
| 958 | function extractPreviews(source) { |
| 959 | const previews = []; |
| 960 | let searchFrom = 0; |
| 961 | while (true) { |
| 962 | const macroIndex = source.indexOf("#Preview", searchFrom); |
| 963 | if (macroIndex < 0) { |
| 964 | break; |
| 965 | } |
| 966 | let cursor = macroIndex + "#Preview".length; |
| 967 | cursor = skipWhitespace(source, cursor); |
| 968 | let name = ""; |
| 969 | if (source[cursor] === "(") { |
| 970 | const parens = readBalanced(source, cursor, "(", ")"); |
| 971 | name = firstStringLiteral(parens.text) ?? ""; |
| 972 | cursor = skipWhitespace(source, parens.end + 1); |
| 973 | } |
| 974 | if (source[cursor] !== "{") { |
| 975 | searchFrom = cursor + 1; |
| 976 | continue; |
| 977 | } |
| 978 | const body = readBalanced(source, cursor, "{", "}"); |
| 979 | previews.push({ |
| 980 | body: body.text.trim(), |
| 981 | index: previews.length, |
| 982 | name, |
| 983 | range: [macroIndex, body.end + 1], |
| 984 | }); |
| 985 | searchFrom = body.end + 1; |
| 986 | } |
| 987 | return previews; |
| 988 | } |
| 989 | |
| 990 | function selectPreview(previews, selector) { |
| 991 | if (selector == null || selector === "") { |
no test coverage detected