simpleMarkup.tsx 729 B

123456789101112131415161718192021222324252627
  1. import type {Token} from 'sentry/views/starfish/utils/sqlish/types';
  2. export function simpleMarkup(tokens: Token[]): React.ReactElement[] {
  3. const accumulator: React.ReactElement[] = [];
  4. function contentize(token: Token): void {
  5. if (Array.isArray(token.content)) {
  6. token.content.forEach(contentize);
  7. return;
  8. }
  9. if (typeof token.content === 'string') {
  10. if (token.type === 'Keyword') {
  11. accumulator.push(<b>{token.content.toUpperCase()}</b>);
  12. } else if (token.type === 'Whitespace') {
  13. accumulator.push(<span> </span>);
  14. } else {
  15. accumulator.push(<span>{token.content}</span>);
  16. }
  17. }
  18. return;
  19. }
  20. tokens.forEach(contentize);
  21. return accumulator;
  22. }