Skip to content

Commit

Permalink
Merge pull request #1 from Henk-B/Henk-B-include-exclude
Browse files Browse the repository at this point in the history
Allow for include and exclude namespace
  • Loading branch information
Henk-B authored Sep 10, 2024
2 parents f3a7782 + 6fba8b9 commit 44e80b0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
$match = substr($match, 12, -2);

$includeNS = '';
$excludeNS = '';
if (strstr($match, "#")) {
$includeNS = substr(strstr($match, "#", false), 1);
[$includeNS, $excludeNS] = explode('!', substr(strstr($match, "#", false), 1).'!');
$match = strstr($match, "#", true);
}

return ([$match, $includeNS]);
return ([$match, $includeNS, $excludeNS]);
}

/**
Expand Down Expand Up @@ -112,22 +113,23 @@ public function render($format, Doku_Renderer $renderer, $data)

$filterNS = $data[1];
if (!empty($backlinks) && !empty($filterNS)) {
if (stripos($filterNS, "!", 0) === 0) {
$filterNS = substr($filterNS, 1);
dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS");
$backlinks = array_filter(
$backlinks,
static fn($ns) => stripos($ns, $filterNS, 0) !== 0
);
} else {
dbglog($filterNS, "backlinks: including namespace: $filterNS only");
$backlinks = array_filter(
$backlinks,
static fn($ns) => stripos($ns, (string) $filterNS, 0) === 0
);
}
dbglog($filterNS, "backlinks: including namespace: $filterNS only");
$backlinks = array_filter(
$backlinks,
static fn($ns) => stripos($ns, (string) $filterNS, 0) === 0
);
}

$excludeNS = $data[2];
if (!empty($backlinks) && !empty($excludeNS)) {
if ($excludeNS == '.')
$excludeNS = cleanID(getID());
dbglog($filterNS, "backlinks: exluding all of namespace: $excludeNS");
$backlinks = array_filter(
$backlinks,
static fn($ns) => stripos($ns, $excludeNS, 0) !== 0
);
}

dbglog($backlinks, "backlinks: all backlinks to be rendered");

if (!empty($backlinks)) {
Expand Down

0 comments on commit 44e80b0

Please sign in to comment.