Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/front_matter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> example1() async {
var file = File('example/hello-world.md');
var fileContents = await file.readAsString();

Expand All @@ -14,7 +14,7 @@ void example1() async {
}

// Example 2 - Read a file and parse its contents.
void example2() async {
Future<void> example2() async {
var doc = await fm.parseFile('example/hello-world.md');

print("The author is ${doc.data['author']}");
Expand Down
11 changes: 5 additions & 6 deletions lib/src/front_matter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ Future<FrontMatterDocument> 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);
}
}
}
4 changes: 2 additions & 2 deletions lib/src/front_matter_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <izolate@gmail.com>
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
1 change: 0 additions & 1 deletion test/front_matter_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down