mirror of https://github.com/kdl-org/kdl-rs.git
feat(clear_fmt): add methods to clear formatting and reset it to default
This commit is contained in:
parent
fc1d0fd24b
commit
892bf06e69
|
|
@ -168,6 +168,13 @@ impl KdlDocument {
|
||||||
self.trailing = Some(trailing.into());
|
self.trailing = Some(trailing.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clears leading and trailing text (whitespace, comments). `KdlNode`s in
|
||||||
|
/// this document will be unaffected.
|
||||||
|
pub fn clear_fmt(&mut self) {
|
||||||
|
self.leading = None;
|
||||||
|
self.trailing = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Auto-formats this Document.
|
/// Auto-formats this Document.
|
||||||
///
|
///
|
||||||
/// Note: This currently removes comments as well.
|
/// Note: This currently removes comments as well.
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,13 @@ impl KdlEntry {
|
||||||
self.trailing = Some(trailing.into());
|
self.trailing = Some(trailing.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clears leading and trailing text (whitespace, comments), as well as
|
||||||
|
/// resetting this entry's value to its default representation.
|
||||||
|
pub fn clear_fmt(&mut self) {
|
||||||
|
self.leading = None;
|
||||||
|
self.trailing = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the custom string representation for this KdlEntry's [`KdlValue`].
|
/// Gets the custom string representation for this KdlEntry's [`KdlValue`].
|
||||||
pub fn value_repr(&self) -> Option<&str> {
|
pub fn value_repr(&self) -> Option<&str> {
|
||||||
self.value_repr.as_deref()
|
self.value_repr.as_deref()
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,13 @@ impl KdlIdentifier {
|
||||||
self.repr = Some(repr.into());
|
self.repr = Some(repr.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resets this identifier to its default representation. It will attempt
|
||||||
|
/// to make it an unquoted identifier, and fall back to a string
|
||||||
|
/// representation if that would be invalid.
|
||||||
|
pub fn clear_fmt(&mut self) {
|
||||||
|
self.repr = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Auto-formats this identifier.
|
/// Auto-formats this identifier.
|
||||||
pub fn fmt(&mut self) {
|
pub fn fmt(&mut self) {
|
||||||
self.repr = None;
|
self.repr = None;
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,15 @@ impl KdlNode {
|
||||||
self.trailing = Some(trailing.into());
|
self.trailing = Some(trailing.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clears leading and trailing text (whitespace, comments), as well as
|
||||||
|
/// the space before the children block, if any. Individual entries and
|
||||||
|
/// their formatting will be preserved.
|
||||||
|
pub fn clear_fmt(&mut self) {
|
||||||
|
self.leading = None;
|
||||||
|
self.trailing = None;
|
||||||
|
self.before_children = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetches an entry by key. Number keys will look up arguments, strings
|
/// Fetches an entry by key. Number keys will look up arguments, strings
|
||||||
/// will look up properties.
|
/// will look up properties.
|
||||||
pub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlEntry> {
|
pub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlEntry> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue