mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-01 17:02:15 +00:00
feat: convert introduction.typ to README.md (#479)
* dev: supports some functions for README * feat: convert introduction.typ to README.md
This commit is contained in:
parent
bc3bd9f762
commit
acd22b71a5
8 changed files with 221 additions and 21 deletions
|
@ -5,6 +5,10 @@ use value::*;
|
|||
pub fn library() -> Scopes<Value> {
|
||||
let mut scopes = Scopes::new();
|
||||
scopes.define("link", link as RawFunc);
|
||||
scopes.define("kbd", kbd as RawFunc);
|
||||
// todo: how to import this function correctly?
|
||||
scopes.define("cross-link", cross_link as RawFunc);
|
||||
scopes.define("md-alter", md_alter as RawFunc);
|
||||
scopes.define("image", image as RawFunc);
|
||||
scopes.define("figure", figure as RawFunc);
|
||||
scopes
|
||||
|
@ -42,3 +46,31 @@ pub fn figure(mut args: Args) -> Result<Value> {
|
|||
_ => Err("figure only accepts image as body".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate a `kbd` element.
|
||||
pub fn kbd(mut args: Args) -> Result<Value> {
|
||||
let key = get_pos_named!(args, key: EcoString);
|
||||
|
||||
Ok(Value::Content(eco_format!("<kbd>{key}</kbd>")))
|
||||
}
|
||||
|
||||
/// Evaluate a `cross-link`.
|
||||
pub fn cross_link(mut args: Args) -> Result<Value> {
|
||||
let dest = get_pos_named!(args, dest: EcoString);
|
||||
let body = get_pos_named!(args, body: Content);
|
||||
|
||||
let dest = std::path::Path::new(dest.as_str()).with_extension("html");
|
||||
|
||||
Ok(Value::Content(eco_format!(
|
||||
"[{body}](https://myriad-dreamin.github.io/tinymist/{dest})",
|
||||
dest = dest.to_string_lossy()
|
||||
)))
|
||||
}
|
||||
|
||||
/// Evaluate a markdown alteration.
|
||||
pub fn md_alter(mut args: Args) -> Result<Value> {
|
||||
let _left = get_pos_named!(args, left: Content);
|
||||
let right = get_pos_named!(args, right: LazyContent);
|
||||
|
||||
Ok(Value::Content(right.0))
|
||||
}
|
||||
|
|
|
@ -27,6 +27,14 @@ impl fmt::Display for Content {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct LazyContent(pub EcoString);
|
||||
|
||||
impl fmt::Display for LazyContent {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Args<'a> {
|
||||
pub vm: &'a mut TypliteWorker,
|
||||
pub args: ast::Args<'a>,
|
||||
|
@ -154,3 +162,14 @@ impl<'a> Eval<'a> for Content {
|
|||
Ok(Self(vm.convert(node)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Eval<'a> for LazyContent {
|
||||
fn eval(node: &'a SyntaxNode, vm: &mut TypliteWorker) -> Result<Self> {
|
||||
let node = match node.cast() {
|
||||
Some(s @ ast::Closure { .. }) => s.body().to_untyped(),
|
||||
None => node,
|
||||
};
|
||||
|
||||
Ok(Self(vm.convert(node)?))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue