Skip to content

Commit

Permalink
No longer matching links or multiple wikilinks on the same line
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpeach committed Nov 2, 2024
1 parent 2fc20d4 commit 56a5029
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Config {
#[builder(default=r"___".to_owned())]
pub boundary_pattern: String,
/// See [`self::cli::Config::wikilink_pattern`]
#[builder(default=r"#?\[\[(.*?)]]|#([A-Za-z0-9_]+)".to_owned())]
#[builder(default=r"\[\[([A-Za-z0-9_/\- ]+)]]|(?:(\s|^))#([A-Za-z0-9_]+)".to_owned())]
pub wikilink_pattern: String,
/// See [`self::cli::Config::filename_spacing_pattern`]
#[builder(default=r"-|_|\s".to_owned())]
Expand Down
1 change: 1 addition & 0 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(super) struct Config {
pub boundary_pattern: Option<String>,

/// Regex pattern for wikilinks
/// Capture group 0 is skipped to enable lookbehind
#[clap(short = 'w', long = "wikilink")]
pub wikilink_pattern: Option<String>,

Expand Down
8 changes: 7 additions & 1 deletion src/file/content/wikilink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ impl Wikilink {
regex::Regex::new(wikilink_pattern).map_err(RegexError::CompileError)?;
for mat in wikilink_pattern.captures_iter(contents) {
let capture0 = mat.get(0).expect("0 always exists");
let Ok(alias) = mat.iter().skip(1).flatten().exactly_one() else {
let Ok(alias) = mat
.iter()
.skip(1)
.flatten()
.filter(|x| !x.as_str().trim().is_empty())
.exactly_one()
else {
return Err(RegexError::CaptureError {
pattern: wikilink_pattern.to_string(),
mat: mat.get(0).expect("0 always exists").as_str().to_string(),
Expand Down

0 comments on commit 56a5029

Please sign in to comment.