Browse Source

Merge pull request #22 from reillysiemens/lazy_front-matter_regex

Use lazy front-matter regex
index-subcmd
Vincent Prouillet GitHub 7 years ago
parent
commit
0dcc7846e4
2 changed files with 15 additions and 1 deletions
  1. +1
    -1
      src/front_matter.rs
  2. +14
    -0
      tests/front_matter.rs

+ 1
- 1
src/front_matter.rs View File

@@ -11,7 +11,7 @@ use errors::{Result, ResultExt};


lazy_static! {
static ref PAGE_RE: Regex = Regex::new(r"^\n?\+\+\+\n((?s).*(?-s))\+\+\+\n?((?s).*(?-s))$").unwrap();
static ref PAGE_RE: Regex = Regex::new(r"^\n?\+\+\+\n((?s).*?(?-s))\+\+\+\n?((?s).*(?-s))$").unwrap();
}




+ 14
- 0
tests/front_matter.rs View File

@@ -184,6 +184,20 @@ date = "2002/10/12"
assert_eq!(front_matter.title, "Title");
}

#[test]
fn test_can_split_content_lazily() {
let content = r#"
+++
title = "Title"
description = "hey there"
date = "2002-10-02T15:00:00Z"
+++
+++"#;
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
assert_eq!(content, "+++");
assert_eq!(front_matter.title, "Title");
}

#[test]
fn test_error_if_cannot_locate_frontmatter() {
let content = r#"


Loading…
Cancel
Save