From b01ab48bc9b48108466c9273ef42556cc27c8057 Mon Sep 17 00:00:00 2001 From: "cledson.junior" Date: Thu, 21 Nov 2024 15:44:34 -0300 Subject: [PATCH] fix-first-where-style --- lib/src/kml_reader.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/src/kml_reader.dart b/lib/src/kml_reader.dart index 30fdf62..c30107f 100644 --- a/lib/src/kml_reader.dart +++ b/lib/src/kml_reader.dart @@ -140,6 +140,13 @@ class KmlReader { return metadata; } + String _convertHtmlToText(String input) { + input = input.replaceAll(RegExp(r'', caseSensitive: false), '\n'); + + final htmlTagRegex = RegExp(r'<[^>]*>'); + return input.replaceAll(htmlTagRegex, '').trim(); + } + Future _readPlacemark( StreamIterator iterator, String tagName, GeoXml geoXml) async { final item = GeoObject(); @@ -162,7 +169,8 @@ class KmlReader { item.name = await _readString(iterator, val.name); break; case KmlTag.desc: - item.desc = await _readString(iterator, val.name); + final rawDesc = await _readString(iterator, val.name); + item.desc = rawDesc != null ? _convertHtmlToText(rawDesc) : null; break; case GpxTag.desc: item.desc = await _readString(iterator, val.name); @@ -229,8 +237,10 @@ class KmlReader { styleUrl = styleUrl.substring(1); } - style = geoXml.styles - .firstWhere((element) => element.id == styleUrl); + style = geoXml.styles.firstWhere( + (element) => element.id == styleUrl, + orElse: GeoStyle.new, + ); } break; }