MCPcopy Create free account
hub / github.com/Yorick-Ryu/deep-share / extractCellText

Function extractCellText

scripts/injectGeminiCanvasButton.js:900–977  ·  view source on GitHub ↗
(cell)

Source from the content-addressed store, hash-verified

898
899 // Helper function to extract text from a cell
900 const extractCellText = (cell) => {
901 let cellText = '';
902 const processCellNode = (n) => {
903 if (!n) return;
904
905 // Handle math formulas in cells
906 if (n.nodeType === Node.ELEMENT_NODE && n.classList) {
907 if (n.classList.contains('math-inline')) {
908 const dataMath = n.getAttribute('data-math');
909 if (dataMath) {
910 cellText += '$' + dataMath.trim() + '$';
911 return;
912 }
913 }
914 if (n.classList.contains('math-block')) {
915 const dataMath = n.getAttribute('data-math');
916 if (dataMath) {
917 cellText += '$$' + dataMath.trim() + '$$';
918 return;
919 }
920 }
921 }
922
923 // Handle strong/bold
924 if (n.tagName === 'STRONG') {
925 cellText += '**';
926 n.childNodes.forEach(processCellNode);
927 cellText += '**';
928 return;
929 }
930
931 // Handle emphasis/italic
932 if (n.tagName === 'EM') {
933 cellText += '*';
934 n.childNodes.forEach(processCellNode);
935 cellText += '*';
936 return;
937 }
938
939 // Handle inline code
940 if (n.tagName === 'CODE' && !n.closest('pre')) {
941 cellText += '`' + n.textContent + '`';
942 return;
943 }
944
945 // Handle links
946 if (n.tagName === 'A') {
947 const href = n.getAttribute('href');
948 const text = n.textContent;
949 if (href && href !== text) {
950 cellText += '[' + text + '](' + href + ')';
951 } else {
952 cellText += text;
953 }
954 return;
955 }
956
957 // Handle paragraphs in cells

Callers 1

processNodeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected