pub struct Document { /* private fields */ }Expand description
A complete TaskPaper doing file represented as an ordered list of sections.
The document preserves section ordering from the original file and can track non-entry content at the top and bottom of the file for round-trip fidelity.
Implementations§
Source§impl Document
impl Document
Sourcepub fn create_file(path: &Path, default_section: &str) -> Result<()>
pub fn create_file(path: &Path, default_section: &str) -> Result<()>
Create a new doing file at path with a single default section.
If the file already exists and is non-empty, this is a no-op. Creates parent directories as needed.
Sourcepub fn add_section(&mut self, section: Section)
pub fn add_section(&mut self, section: Section)
Add a section to the document. Does nothing if a section with the same name (case-insensitive) already exists.
Sourcepub fn all_entries(&self) -> Vec<&Entry>
pub fn all_entries(&self) -> Vec<&Entry>
Return all entries across all sections.
Sourcepub fn dedup(&mut self)
pub fn dedup(&mut self)
Deduplicate entries across all sections by ID, keeping the first occurrence.
Sourcepub fn entries_in_section(&self, name: &str) -> Vec<&Entry>
pub fn entries_in_section(&self, name: &str) -> Vec<&Entry>
Return entries from a specific section by name (case-insensitive).
If name is “all” (case-insensitive), returns entries from all sections.
Sourcepub fn has_section(&self, name: &str) -> bool
pub fn has_section(&self, name: &str) -> bool
Return true if a section with the given name exists (case-insensitive).
Sourcepub fn other_content_bottom(&self) -> &[String]
pub fn other_content_bottom(&self) -> &[String]
Return non-entry content from the bottom of the file.
Sourcepub fn other_content_bottom_mut(&mut self) -> &mut Vec<String>
pub fn other_content_bottom_mut(&mut self) -> &mut Vec<String>
Return a mutable reference to non-entry content from the bottom of the file.
Sourcepub fn other_content_top(&self) -> &[String]
pub fn other_content_top(&self) -> &[String]
Return non-entry content from the top of the file.
Sourcepub fn other_content_top_mut(&mut self) -> &mut Vec<String>
pub fn other_content_top_mut(&mut self) -> &mut Vec<String>
Return a mutable reference to non-entry content from the top of the file.
Sourcepub fn remove_section(&mut self, name: &str) -> usize
pub fn remove_section(&mut self, name: &str) -> usize
Remove a section by name (case-insensitive), returning the number removed.
Sourcepub fn section_by_name(&self, name: &str) -> Option<&Section>
pub fn section_by_name(&self, name: &str) -> Option<&Section>
Look up a section by name (case-insensitive).
Sourcepub fn section_by_name_mut(&mut self, name: &str) -> Option<&mut Section>
pub fn section_by_name_mut(&mut self, name: &str) -> Option<&mut Section>
Look up a mutable section by name (case-insensitive).
Sourcepub fn sections_mut(&mut self) -> &mut Vec<Section>
pub fn sections_mut(&mut self) -> &mut Vec<Section>
Return a mutable reference to all sections.
Sourcepub fn sort_entries(&mut self, reverse: bool)
pub fn sort_entries(&mut self, reverse: bool)
Sort entries within each section by date then title, in ascending order.
If reverse is true, sort in descending order.