summaryrefslogtreecommitdiff
path: root/packages/astro-parser/src/parse/read/style.ts
blob: 05fb4141d0567de00f5be33ef7af4e67b5a3299f (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';
}