summaryrefslogtreecommitdiff
path: root/packages/astro-parser/src/parse/read/style.ts
blob: f23d7b10ee715f049b8095a8be704d1e697eaba8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Parser } from '../index.js';
import { Style } from '../../interfaces.js';

interface Attribute {
  start: number;
  end: number;
  type: 'Attribute';
  name: string;
  value: {
    raw: string;
    data: string;
  }[];
}

export default function read_style(parser: Parser, start: number, attributes: Attribute[]): Style {
  const content_start = parser.index;
  const styles = parser.read_until(/<\/style>/);
  const content_end = parser.index;
  parser.eat('</style>', true);
  const end = parser.index;

  return {
    type: 'Style',
    start,
    end,
    attributes,
    content: {
      start: content_start,
      end: content_end,
      styles,
    },
  };
}

function is_ref_selector(a: any, b: any) {
  // TODO add CSS node types
  if (!b) return false;

  return a.type === 'TypeSelector' && a.name === 'ref' && b.type === 'PseudoClassSelector';
}