From 4b94dc60d2e3177504621fcca590a82bfcdd6f74 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Dec 2023 19:49:12 -0500 Subject: [PATCH] Fix handling of documents containing only whitespace. --- org_mode_samples/document/empty.org | 0 org_mode_samples/document/only_line_breaks.org | 4 ++++ .../document_post_blank.org => document/post_blank.org} | 0 src/parser/document.rs | 5 +++-- src/types/document.rs | 4 ++-- 5 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 org_mode_samples/document/empty.org create mode 100644 org_mode_samples/document/only_line_breaks.org rename org_mode_samples/{sections_and_headings/document_post_blank.org => document/post_blank.org} (100%) diff --git a/org_mode_samples/document/empty.org b/org_mode_samples/document/empty.org new file mode 100644 index 00000000..e69de29b diff --git a/org_mode_samples/document/only_line_breaks.org b/org_mode_samples/document/only_line_breaks.org new file mode 100644 index 00000000..fd40910d --- /dev/null +++ b/org_mode_samples/document/only_line_breaks.org @@ -0,0 +1,4 @@ + + + + diff --git a/org_mode_samples/sections_and_headings/document_post_blank.org b/org_mode_samples/document/post_blank.org similarity index 100% rename from org_mode_samples/sections_and_headings/document_post_blank.org rename to org_mode_samples/document/post_blank.org diff --git a/src/parser/document.rs b/src/parser/document.rs index 65aabc38..8c783ccb 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -3,6 +3,7 @@ use std::path::Path; use nom::combinator::all_consuming; use nom::combinator::opt; use nom::multi::many0; +use nom::InputTake; use super::headline::heading; use super::in_buffer_settings::apply_in_buffer_settings; @@ -195,9 +196,9 @@ fn _document<'b, 'g, 'r, 's>( zeroth_section, children, contents: if contents.len() > 0 { - Some(Into::<&str>::into(contents)) + Into::<&str>::into(contents) } else { - None + Into::<&str>::into(remaining.take(0)) }, }, )) diff --git a/src/types/document.rs b/src/types/document.rs index e39e19cb..e9269409 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -17,7 +17,7 @@ pub struct Document<'s> { pub path: Option, pub zeroth_section: Option>, pub children: Vec>, - pub contents: Option<&'s str>, + pub contents: &'s str, } #[derive(Debug)] @@ -64,7 +64,7 @@ impl<'s> StandardProperties<'s> for Document<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - self.contents + Some(self.contents) } fn get_post_blank(&self) -> PostBlank {