mod after;
mod before;
mod bottom;
mod head;
mod link;
mod parser;
mod raw;
mod share;
mod tail;
mod within;
pub use after::After;
pub use before::Before;
pub use bottom::Bottom;
pub use equt_md::{Alignment, CodeBlockKind, CowStr, Event, LinkType, Options, Tag};
pub use equt_md_error as error;
pub use equt_md_frontmatter as frontmatter;
pub use error::Result;
pub use head::Head;
pub use link::Link;
pub use parser::Parser;
pub use raw::Raw;
pub use tail::Tail;
pub use within::Within;
pub use share::Share;
#[macro_use]
extern crate derive_new;
use equt_md_frontmatter::FrontMatter;
use std::cell::{Ref, RefCell};
use std::rc::Rc;
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub trait MarkdownExt<T>: Iterator<Item = T> + Sized {
fn frontmatter(&mut self) -> &mut Share<RefCell<Option<FrontMatter>>>;
fn inspect_frontmatter(mut self, frontmatter: &mut Option<FrontMatter>) -> Raw<Self, T> {
let curr = Rc::try_unwrap(self.frontmatter().transfer().unwrap())
.unwrap()
.into_inner();
*frontmatter = curr.clone();
Raw::new(Rc::new(RefCell::new(curr)).into(), self)
}
fn after<P, F, S, G>(mut self, after: P, f: F) -> After<Self, S, G, F, P, T>
where
P: Fn(&T) -> bool,
S: Iterator<Item = T>,
G: IntoIterator<Item = T, IntoIter = S>,
F: Fn(Ref<Option<FrontMatter>>) -> G,
{
After::new(
self.frontmatter().transfer().unwrap().into(),
self,
after,
f,
)
}
fn before<P, F, S, G>(mut self, before: P, f: F) -> Before<Self, S, G, F, P, T>
where
P: Fn(&T) -> bool,
S: Iterator<Item = T>,
G: IntoIterator<Item = T, IntoIter = S>,
F: Fn(Ref<Option<FrontMatter>>) -> G,
{
Before::new(
self.frontmatter().transfer().unwrap().into(),
self,
before,
f,
)
}
fn link<E>(mut self, mut other: E) -> Link<Self, E>
where
E: MarkdownExt<T>,
{
let right = other.frontmatter();
let left = self.frontmatter();
let strong = if right.upgrade().unwrap().borrow().is_some() {
*left = right.downgrade().into();
right.transfer().unwrap()
} else {
*right = left.downgrade().into();
left.transfer().unwrap()
};
Link::new(strong.into(), self, other)
}
fn iter<I>(self, iter: I) -> Link<Self, Raw<I, T>>
where
I: Iterator<Item = T>,
{
self.link(Raw::new(Rc::new(RefCell::new(None)).into(), iter))
}
fn head<F, G, H>(mut self, f: F) -> Head<Self, H, F, G, T>
where
H: Iterator<Item = T>,
G: IntoIterator<Item = T, IntoIter = H>,
F: Fn(Ref<Option<FrontMatter>>) -> G,
{
Head::new(self.frontmatter().transfer().unwrap().into(), self, f)
}
fn tail<F, G, H>(mut self, f: F) -> Tail<Self, H, F, G, T>
where
H: Iterator<Item = T>,
G: IntoIterator<Item = T, IntoIter = H>,
F: Fn(Ref<Option<FrontMatter>>) -> G,
{
Tail::new(self.frontmatter().transfer().unwrap().into(), self, f)
}
fn within<P, Q, F>(mut self, start: P, end: Q, f: F) -> Within<Self, P, Q, F, T>
where
P: Fn(&T) -> bool,
Q: Fn(&T) -> bool,
F: Fn(Ref<Option<FrontMatter>>, T) -> Option<T>,
{
Within::new(
self.frontmatter().transfer().unwrap().into(),
self,
start,
end,
f,
)
}
}