From a39707b18a498fa3519c3772ef5f80cdbd8d3af6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:33:09 +0300 Subject: fix: single-quoted values may also contain newlines Sponsored-by: author --- src/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/token.rs b/src/token.rs index 76cd7b4..83e6c41 100644 --- a/src/token.rs +++ b/src/token.rs @@ -35,7 +35,7 @@ impl Default for TokenPatterns { plain: Regex::new(r#"(?P[^\[]+)"#).unwrap(), word: Regex::new(r#"[-._/[:alpha:][:digit:]]+"#).unwrap(), spaces: Regex::new(r#"([[:space:]]|\n)+"#).unwrap(), - single_quoted: Regex::new(r#""(?P.*?)""#).unwrap(), + single_quoted: Regex::new(r#""(?P(.|\n)*?)""#).unwrap(), triple_quoted: Regex::new(r#""""(?P(.|\n)*?)""""#).unwrap(), } } -- cgit v1.2.1 From ea1a5a1e9c837816a0c89793e13f032f2cba50e1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:28:58 +0300 Subject: feat: add placeholder for the inline directive Sponsored-by: author --- src/directive/inline.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/directive/mod.rs | 9 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/directive/inline.rs diff --git a/src/directive/inline.rs b/src/directive/inline.rs new file mode 100644 index 0000000..efaf7ee --- /dev/null +++ b/src/directive/inline.rs @@ -0,0 +1,38 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Inline {} + +impl Inline { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &[ + "actions", + "archive", + "description", + "feedlimit", + "feeds", + "feedshow", + "limit", + "sort", + "template", + "trail", + ]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for Inline { + fn from(_p: ParsedDirective) -> Self { + Inline::new() + } +} diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 38fb0d3..a97f3a5 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -14,6 +14,7 @@ pub enum Directive { Meta(Meta), Img(Img), + Inline(Inline), Tag(Tag), } @@ -46,6 +47,10 @@ impl TryFrom for Directive { Self::check_args(&p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?; Directive::Img(Img::from(p)) } + "inline" => { + Self::check_args(&p, Inline::REQUIRED, Inline::ALLOWED, Inline::ALLOW_ANY_UNNAMED)?; + Directive::Inline(Inline::from(p)) + } "meta" => { Self::check_args(&p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?; Directive::Meta(Meta::from(p)) @@ -101,6 +106,7 @@ impl Directive { panic!("directive {:?} may only be used in parsing tests", self) } Self::Img(x) => x.process(site, meta), + Self::Inline(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), } @@ -113,5 +119,8 @@ use meta::Meta; mod img; pub use img::Img; +mod inline; +pub use inline::Inline; + mod tag; use tag::Tag; -- cgit v1.2.1 From 51f773726a9b6640e21c0601e61700603c18d462 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:38:24 +0300 Subject: feat: placeholder directive pagestats Sponsored-by: author --- src/directive/mod.rs | 9 +++++++++ src/directive/pagestats.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/directive/pagestats.rs diff --git a/src/directive/mod.rs b/src/directive/mod.rs index a97f3a5..59c352c 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -15,6 +15,7 @@ pub enum Directive { Meta(Meta), Img(Img), Inline(Inline), + PageStats(PageStats), Tag(Tag), } @@ -55,6 +56,10 @@ impl TryFrom for Directive { Self::check_args(&p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?; Directive::Meta(Meta::from(p)) } + "pagestats" => { + Self::check_args(&p, PageStats::REQUIRED, PageStats::ALLOWED, PageStats::ALLOW_ANY_UNNAMED)?; + Directive::PageStats(PageStats::from(p)) + } "tag" => { Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; Directive::Tag(Tag::from(p)) @@ -108,6 +113,7 @@ impl Directive { Self::Img(x) => x.process(site, meta), Self::Inline(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), + Self::PageStats(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), } } @@ -122,5 +128,8 @@ pub use img::Img; mod inline; pub use inline::Inline; +mod pagestats; +pub use pagestats::PageStats; + mod tag; use tag::Tag; diff --git a/src/directive/pagestats.rs b/src/directive/pagestats.rs new file mode 100644 index 0000000..1a6f811 --- /dev/null +++ b/src/directive/pagestats.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct PageStats {} + +impl PageStats { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &["style"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for PageStats { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} -- cgit v1.2.1 From 4d20badb243c2ae57b8b54d0c5e025b43957dd8f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:44:40 +0300 Subject: feat: placeholder for toc directive Sponsored-by: author --- src/directive/mod.rs | 9 +++++++++ src/directive/toc.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/directive/toc.rs diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 59c352c..0767c9d 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -17,6 +17,7 @@ pub enum Directive { Inline(Inline), PageStats(PageStats), Tag(Tag), + Toc(Toc), } impl TryFrom for Directive { @@ -64,6 +65,10 @@ impl TryFrom for Directive { Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; Directive::Tag(Tag::from(p)) } + "toc" => { + Self::check_args(&p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?; + Directive::Toc(Toc::from(p)) + } _ => return Err(SiteError::UnknownDirective(p.name().into())), }; Ok(d) @@ -115,6 +120,7 @@ impl Directive { Self::Meta(x) => x.process(site, meta), Self::PageStats(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), + Self::Toc(x) => x.process(site, meta), } } } @@ -133,3 +139,6 @@ pub use pagestats::PageStats; mod tag; use tag::Tag; + +mod toc; +use toc::Toc; diff --git a/src/directive/toc.rs b/src/directive/toc.rs new file mode 100644 index 0000000..6db46d2 --- /dev/null +++ b/src/directive/toc.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Toc {} + +impl Toc { + pub const REQUIRED: &'static [&'static str] = &[]; + pub const ALLOWED: &'static [&'static str] = &["levels"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for Toc { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} -- cgit v1.2.1 From 186176b499dd7d1db6089bf8f666e3770162d782 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:53:02 +0300 Subject: feat: placeholder for brokenlinks directive Sponsored-by: author --- src/directive/brokenlinks.rs | 27 +++++++++++++++++++++++++++ src/directive/mod.rs | 26 +++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/directive/brokenlinks.rs diff --git a/src/directive/brokenlinks.rs b/src/directive/brokenlinks.rs new file mode 100644 index 0000000..c6364a4 --- /dev/null +++ b/src/directive/brokenlinks.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct BrokenLinks {} + +impl BrokenLinks { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &[]; + pub const ALLOW_ANY_UNNAMED: bool = false; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for BrokenLinks { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 0767c9d..16d55c1 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -12,9 +12,10 @@ pub enum Directive { QuotedArg, MultilineArg, - Meta(Meta), + BrokenLinks(BrokenLinks), Img(Img), Inline(Inline), + Meta(Meta), PageStats(PageStats), Tag(Tag), Toc(Toc), @@ -45,12 +46,22 @@ impl TryFrom for Directive { Self::check_args(&p, &["yo"], &["then", "else"], false)?; Directive::MultilineArg } + + "brokenlinks" => { + Self::check_args(&p, BrokenLinks::REQUIRED, BrokenLinks::ALLOWED, BrokenLinks::ALLOW_ANY_UNNAMED)?; + Directive::BrokenLinks(BrokenLinks::from(p)) + } "img" => { Self::check_args(&p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?; Directive::Img(Img::from(p)) } "inline" => { - Self::check_args(&p, Inline::REQUIRED, Inline::ALLOWED, Inline::ALLOW_ANY_UNNAMED)?; + Self::check_args( + &p, + Inline::REQUIRED, + Inline::ALLOWED, + Inline::ALLOW_ANY_UNNAMED, + )?; Directive::Inline(Inline::from(p)) } "meta" => { @@ -58,7 +69,12 @@ impl TryFrom for Directive { Directive::Meta(Meta::from(p)) } "pagestats" => { - Self::check_args(&p, PageStats::REQUIRED, PageStats::ALLOWED, PageStats::ALLOW_ANY_UNNAMED)?; + Self::check_args( + &p, + PageStats::REQUIRED, + PageStats::ALLOWED, + PageStats::ALLOW_ANY_UNNAMED, + )?; Directive::PageStats(PageStats::from(p)) } "tag" => { @@ -115,6 +131,7 @@ impl Directive { | Self::MultilineArg => { panic!("directive {:?} may only be used in parsing tests", self) } + Self::BrokenLinks(x) => x.process(site, meta), Self::Img(x) => x.process(site, meta), Self::Inline(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), @@ -125,6 +142,9 @@ impl Directive { } } +mod brokenlinks; +use brokenlinks::BrokenLinks; + mod meta; use meta::Meta; -- cgit v1.2.1 From 10c90f514772cc21abf58aa2ea03f2d8f86bdaca Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 5 Aug 2022 22:56:39 +0300 Subject: feat: img directive alt parameter Sponsored-by: author --- src/directive/img.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directive/img.rs b/src/directive/img.rs index e10851e..9210892 100644 --- a/src/directive/img.rs +++ b/src/directive/img.rs @@ -12,7 +12,7 @@ pub struct Img { impl Img { pub const REQUIRED: &'static [&'static str] = &[]; - pub const ALLOWED: &'static [&'static str] = &["class"]; + pub const ALLOWED: &'static [&'static str] = &["alt", "class"]; pub const ALLOW_ANY_UNNAMED: bool = true; pub fn new(src: String) -> Self { -- cgit v1.2.1 From 60a74ba1166ca1166c20b7f82f4a2e818f06f72d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 6 Aug 2022 07:32:33 +0300 Subject: feat: add placeholder for directive shortcut Sponsored-by: author --- src/directive/mod.rs | 9 +++++++++ src/directive/shortcut.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/directive/shortcut.rs diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 16d55c1..ee96bfc 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -17,6 +17,7 @@ pub enum Directive { Inline(Inline), Meta(Meta), PageStats(PageStats), + Shortcut(Shortcut), Tag(Tag), Toc(Toc), } @@ -77,6 +78,10 @@ impl TryFrom for Directive { )?; Directive::PageStats(PageStats::from(p)) } + "shortcut" => { + Self::check_args(&p, Shortcut::REQUIRED, Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED)?; + Directive::Shortcut(Shortcut::from(p)) + } "tag" => { Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; Directive::Tag(Tag::from(p)) @@ -136,6 +141,7 @@ impl Directive { Self::Inline(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), Self::PageStats(x) => x.process(site, meta), + Self::Shortcut(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), Self::Toc(x) => x.process(site, meta), } @@ -157,6 +163,9 @@ pub use inline::Inline; mod pagestats; pub use pagestats::PageStats; +mod shortcut; +pub use shortcut::Shortcut; + mod tag; use tag::Tag; diff --git a/src/directive/shortcut.rs b/src/directive/shortcut.rs new file mode 100644 index 0000000..03fd648 --- /dev/null +++ b/src/directive/shortcut.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Shortcut {} + +impl Shortcut { + pub const REQUIRED: &'static [&'static str] = &["desc", "name", "url"]; + pub const ALLOWED: &'static [&'static str] = &[]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result { + Ok("FIXME:inline".into()) + } +} + +impl From for Shortcut { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} -- cgit v1.2.1 From 862525b459be669e7c5faf40cbdd8406dde1baf9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 6 Aug 2022 07:38:15 +0300 Subject: feat: allo img directive to have the link parameter Sponsored-by: author --- src/directive/img.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directive/img.rs b/src/directive/img.rs index 9210892..dea2625 100644 --- a/src/directive/img.rs +++ b/src/directive/img.rs @@ -12,7 +12,7 @@ pub struct Img { impl Img { pub const REQUIRED: &'static [&'static str] = &[]; - pub const ALLOWED: &'static [&'static str] = &["alt", "class"]; + pub const ALLOWED: &'static [&'static str] = &["alt", "class", "link"]; pub const ALLOW_ANY_UNNAMED: bool = true; pub fn new(src: String) -> Self { -- cgit v1.2.1 From be85bae2e516ce3b2b7874e94e5bb4fea6c30754 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 6 Aug 2022 07:38:24 +0300 Subject: fix: allow "words" to include colons Sponsored-by: author --- src/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/token.rs b/src/token.rs index 83e6c41..5109ce1 100644 --- a/src/token.rs +++ b/src/token.rs @@ -33,7 +33,7 @@ impl Default for TokenPatterns { fn default() -> Self { Self { plain: Regex::new(r#"(?P[^\[]+)"#).unwrap(), - word: Regex::new(r#"[-._/[:alpha:][:digit:]]+"#).unwrap(), + word: Regex::new(r#"[-.:_/[:alpha:][:digit:]]+"#).unwrap(), spaces: Regex::new(r#"([[:space:]]|\n)+"#).unwrap(), single_quoted: Regex::new(r#""(?P(.|\n)*?)""#).unwrap(), triple_quoted: Regex::new(r#""""(?P(.|\n)*?)""""#).unwrap(), -- cgit v1.2.1