mirror of
https://github.com/TxtDot/dalet-rs.git
synced 2024-11-05 17:33:58 +03:00
feat: meta tag, resolve title
This commit is contained in:
parent
4e320d9a44
commit
f3231b52c4
8 changed files with 52 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -151,7 +151,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "dalet"
|
||||
version = "1.0.0-pre.12"
|
||||
version = "1.0.0-pre.13"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "dalet"
|
||||
version = "1.0.0-pre.12"
|
||||
version = "1.0.0-pre.13"
|
||||
edition = "2021"
|
||||
authors = ["artegoser"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -73,10 +73,11 @@ pub enum DlTid {
|
|||
Sup,
|
||||
Sub,
|
||||
Disc,
|
||||
Bl,
|
||||
Block,
|
||||
Carousel,
|
||||
Code,
|
||||
Pre,
|
||||
Meta,
|
||||
}
|
||||
|
||||
pub trait IsNull {
|
||||
|
|
|
@ -37,10 +37,11 @@ impl TryFrom<DlTag> for Tag {
|
|||
DlTid::Sup => Sup(tag.body.try_into()?),
|
||||
DlTid::Sub => Sub(tag.body.try_into()?),
|
||||
DlTid::Disc => Disc(tag.body.try_into()?),
|
||||
DlTid::Bl => Bl(tag.body.try_into()?, tag.argument.try_into()?),
|
||||
DlTid::Block => Block(tag.body.try_into()?, tag.argument.try_into()?),
|
||||
DlTid::Carousel => Carousel(tag.body.try_into()?),
|
||||
DlTid::Code => Code(tag.body.try_into()?, tag.argument.try_into()?),
|
||||
DlTid::Pre => Pre(tag.body.try_into()?),
|
||||
DlTid::Meta => Meta(tag.body.try_into()?, tag.argument.try_into()?),
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
mod from_daletl;
|
||||
mod is_null_daletl;
|
||||
mod resolve_title;
|
||||
mod to_daletl;
|
||||
|
|
37
src/traits/resolve_title.rs
Normal file
37
src/traits/resolve_title.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use crate::typed::{
|
||||
Hl, NNBody, Page, ResolveTitle,
|
||||
Tag::{self, Block, Meta, H},
|
||||
};
|
||||
|
||||
impl ResolveTitle for Page {
|
||||
fn resolve_title(&self) -> Option<&String> {
|
||||
resolve_from_tags(&self.data)
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_from_tags(tags: &Vec<Tag>) -> Option<&String> {
|
||||
for tag in tags {
|
||||
match tag {
|
||||
H(title, level) => {
|
||||
if *level == Hl::One {
|
||||
return Some(title);
|
||||
}
|
||||
}
|
||||
|
||||
Meta(body, key) => {
|
||||
if key == "title" {
|
||||
return Some(body);
|
||||
}
|
||||
}
|
||||
|
||||
Block(body, _) => match body {
|
||||
NNBody::Tags(tags) => return resolve_from_tags(tags),
|
||||
_ => {}
|
||||
},
|
||||
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
None
|
||||
}
|
|
@ -32,10 +32,11 @@ impl From<Tag> for DlTag {
|
|||
Tag::Sup(b) => dlt_new(DlTid::Sup, b.into(), NA),
|
||||
Tag::Sub(b) => dlt_new(DlTid::Sub, b.into(), NA),
|
||||
Tag::Disc(b) => dlt_new(DlTid::Disc, b.into(), NA),
|
||||
Tag::Bl(b, a) => dlt_new(DlTid::Bl, b.into(), a.into()),
|
||||
Tag::Block(b, a) => dlt_new(DlTid::Block, b.into(), a.into()),
|
||||
Tag::Carousel(b) => dlt_new(DlTid::Carousel, b.into(), NA),
|
||||
Tag::Code(b, a) => dlt_new(DlTid::Code, b.into(), a.into()),
|
||||
Tag::Pre(b) => dlt_new(DlTid::Pre, b.into(), NA),
|
||||
Tag::Meta(b, a) => dlt_new(DlTid::Meta, b.into(), a.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,11 @@ pub enum Tag {
|
|||
Sup(TBody),
|
||||
Sub(TBody),
|
||||
Disc(NNBody),
|
||||
Bl(NNBody, AlignArg),
|
||||
Block(NNBody, AlignArg),
|
||||
Carousel(Vec<Tag>),
|
||||
Code(TBody, TNArg),
|
||||
Pre(TBody),
|
||||
Meta(TBody, TArg),
|
||||
}
|
||||
|
||||
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -106,3 +107,7 @@ pub enum Hl {
|
|||
Five,
|
||||
Six,
|
||||
}
|
||||
|
||||
pub trait ResolveTitle {
|
||||
fn resolve_title(&self) -> Option<&String>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue