From c0bb0fa6e2210b90a7b78b9ab07a7695f7a32cab Mon Sep 17 00:00:00 2001 From: augustuswm Date: Mon, 5 Feb 2024 10:52:39 -0600 Subject: [PATCH] Work on more author fallback parsing --- rfd-processor/src/content/asciidoc.rs | 37 ++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/rfd-processor/src/content/asciidoc.rs b/rfd-processor/src/content/asciidoc.rs index d64ed6ac..0f0d4b7f 100644 --- a/rfd-processor/src/content/asciidoc.rs +++ b/rfd-processor/src/content/asciidoc.rs @@ -206,7 +206,22 @@ impl<'a> RfdAttributes for RfdAsciidoc<'a> { if first_line == "{authors}" { self.attr("authors") } else { - Some(first_line) + + // Given that we are in a fallback case we need to be slightly picky on what + // lines we allow. We require that the line at least include a *@*.* word to + // try and filter out lines that are not actually author lines + let author_fallback_pattern = Regex::new(r"^.*?([\S]+@[\S]+.[\S]+).*?$").unwrap(); + let fallback_matches = author_fallback_pattern.is_match(first_line); + + if fallback_matches { + Some(first_line) + } else { + + // If none of our attempts have found an author, we drop back to the + // attribute lookup. Eventually all of this logic should be removed and only + // the attribute version should be supported + self.attr("authors") + } } }) }) @@ -297,6 +312,26 @@ sdf"#; assert_eq!(expected, authors); } + #[test] + fn test_get_asciidoc_attribute_authors_without_marker() { + let content = r#":showtitle: +:toc: left +:numbered: +:icons: font +:state: published +:revremark: State: {state} | {discussion} +:authors: firstname + += RFD 123 Test Rfd + +dsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdfdsfsdf +"#; + let rfd = RfdContent::new_asciidoc(content); + let authors = rfd.get_authors().unwrap(); + let expected = r#"firstname "#.to_string(); + assert_eq!(expected, authors); + } + #[test] fn test_get_asciidoc_attribute_authors_with_markdown_sections() { let content = r#"