diff --git a/example/front_matter.dart b/example/front_matter.dart index 1ba1455..835a5b2 100644 --- a/example/front_matter.dart +++ b/example/front_matter.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:front_matter/front_matter.dart' as fm; // Example 1 - Parse a string. -void example1() async { +Future example1() async { var file = File('example/hello-world.md'); var fileContents = await file.readAsString(); @@ -14,7 +14,7 @@ void example1() async { } // Example 2 - Read a file and parse its contents. -void example2() async { +Future example2() async { var doc = await fm.parseFile('example/hello-world.md'); print("The author is ${doc.data['author']}"); diff --git a/lib/src/front_matter.dart b/lib/src/front_matter.dart index 75678ff..9c008bb 100644 --- a/lib/src/front_matter.dart +++ b/lib/src/front_matter.dart @@ -27,11 +27,10 @@ Future parseFile(String path, return parser(text, delimiter: delimiter); } catch (e) { // Handle downstream errors, or throw one if file is not readable as text. - switch (e.message) { - case invalidYamlError: - rethrow; - default: - throw FrontMatterException(fileTypeError); - } + if (e is FrontMatterException && e.message == invalidYamlError) { + rethrow; + } else { + throw FrontMatterException(fileTypeError); + } } } diff --git a/lib/src/front_matter_document.dart b/lib/src/front_matter_document.dart index b509a94..976c8d6 100644 --- a/lib/src/front_matter_document.dart +++ b/lib/src/front_matter_document.dart @@ -6,10 +6,10 @@ class FrontMatterDocument { String value; /// The parsed [content] from the [value]. - String content; + String? content; /// The parsed YAML front matter as a [YamlMap]. - YamlMap data; + YamlMap data = YamlMap(); FrontMatterDocument(this.value); diff --git a/lib/src/parser.dart b/lib/src/parser.dart index 694c6bf..5bd9eaf 100644 --- a/lib/src/parser.dart +++ b/lib/src/parser.dart @@ -8,7 +8,7 @@ import 'front_matter_exception.dart'; /// `data` [YamlMap], and the remaining `content` [String]. /// /// Throws a [FrontMatterException] if front matter contains invalid YAML. -FrontMatterDocument parser(String text, {String delimiter}) { +FrontMatterDocument parser(String text, {required String delimiter}) { var doc = FrontMatterDocument(text); // Remove any leading whitespace. diff --git a/pubspec.yaml b/pubspec.yaml index cc2e0a5..57fc3ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,11 @@ name: front_matter version: 1.1.0 description: A front matter parser that extracts YAML metadata from the start of a file or string. -author: izolate homepage: https://github.com/izolate/front-matter documentation: https://github.com/izolate/front-matter/blob/master/README.md environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: - yaml: ^2.1.15 + yaml: ^3.1.2 dev_dependencies: - test: ^1.6.2 + test: ^1.21.6 diff --git a/test/front_matter_test.dart b/test/front_matter_test.dart index e2bd7f2..8cccd25 100644 --- a/test/front_matter_test.dart +++ b/test/front_matter_test.dart @@ -1,6 +1,5 @@ import 'package:test/test.dart'; import 'package:front_matter/front_matter.dart' as fm; -import 'package:front_matter/src/front_matter.dart'; import 'package:front_matter/src/front_matter_document.dart'; import 'package:front_matter/src/front_matter_exception.dart';