extractEmbedHeight static method

double extractEmbedHeight(
  1. String embedHtml, {
  2. required String embedUrl,
})

Reads height: …px from wrapper styles, else a type-based default.

Implementation

static double extractEmbedHeight(
  String embedHtml, {
  required String embedUrl,
}) {
  final styleHeight = RegExp(
    r'height:\s*(\d+(?:\.\d+)?)\s*px',
    caseSensitive: false,
  ).firstMatch(embedHtml);
  if (styleHeight != null) {
    return double.parse(styleHeight.group(1)!);
  }

  final attrHeight = RegExp(
    r'''height=["'](\d+(?:\.\d+)?)''',
    caseSensitive: false,
  ).firstMatch(embedHtml);
  if (attrHeight != null) {
    return double.parse(attrHeight.group(1)!);
  }

  return defaultHeightForType(_embedTypeFromUrl(embedUrl));
}