feat: FixedWidth::value & Comment::value
This commit is contained in:
parent
7d4b176975
commit
868cd9ab10
6 changed files with 163 additions and 46 deletions
20
src/ast/fixed_width.rs
Normal file
20
src/ast/fixed_width.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use crate::SyntaxKind;
|
||||
|
||||
use super::{filter_token, FixedWidth};
|
||||
|
||||
impl FixedWidth {
|
||||
/// Contents without colons prefix
|
||||
///
|
||||
/// ```rust
|
||||
/// use orgize::{ast::FixedWidth, Org};
|
||||
///
|
||||
/// let fixed = Org::parse(": A\n:\n: B\n: C").first_node::<FixedWidth>().unwrap();
|
||||
/// assert_eq!(fixed.value(), "A\n\nB\nC");
|
||||
/// ```
|
||||
pub fn value(&self) -> String {
|
||||
self.syntax
|
||||
.children_with_tokens()
|
||||
.filter_map(filter_token(SyntaxKind::TEXT))
|
||||
.fold(String::new(), |acc, text| acc + &text)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue