Skip to content

Commit 6d19bb0

Browse files
committed
implemented nice links and fixed Code blocks with new lines are broken, when starting directly after another block
Fixes #172
1 parent c7722e4 commit 6d19bb0

8 files changed

Lines changed: 29 additions & 21 deletions

File tree

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
- eleminated regex-based post-processing by implementing it into PerliteParsedown, this fixed issue [#177](https://github.com/secure-77/Perlite/issues/177)
1313
- implemented support for internal Markdown Links [#170](https://github.com/secure-77/Perlite/issues/170)
1414
- implemented support for parameter based obsidian image attribute syntax to fix issue [#142](https://github.com/secure-77/Perlite/issues/142)
15-
15+
- implemented support for "nice" internal links, this way always the filename only will be displayed without the path
16+
- fixed issue [#172](https://github.com/secure-77/Perlite/issues/172)
1617

1718

1819
## 1.6

docker-compose-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- ALLOWED_FILE_LINK_TYPES=pdf,mp4
1212
- HIGHLIGHTJS_LANGS=powershell
1313
- DISABLE_POP_HOVER=true
14+
- NICE_LINKS=true
1415
- SHOW_TOC=true
1516
- SHOW_LOCAL_GRAPH=true
1617
- HOME_FILE=README

docker-compose-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- ALLOWED_FILE_LINK_TYPES=pdf,mp4
1313
- HIGHLIGHTJS_LANGS=powershell
1414
- DISABLE_POP_HOVER=false
15+
- NICE_LINKS=true
1516
- SHOW_TOC=true
1617
- SHOW_LOCAL_GRAPH=true
1718
- HOME_FILE=README

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- ALLOWED_FILE_LINK_TYPES=pdf,mp4
1313
- HIGHLIGHTJS_LANGS=powershell
1414
- DISABLE_POP_HOVER=false
15+
- NICE_LINKS=true
1516
- SHOW_TOC=true
1617
- SHOW_LOCAL_GRAPH=true
1718
- HOME_FILE=README

perlite/.src/PerliteParsedown.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,9 @@ protected function blockListContinue($Line, array $Block)
860860
}
861861

862862
if (!isset($Block['interrupted'])) {
863+
if (preg_match('/^[`~]{3,}/', $Line['text'])) {
864+
return null;
865+
}
863866
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
864867

865868
$Block['li']['text'][] = $text;
@@ -1239,12 +1242,13 @@ protected function inlineInternalLink($Excerpt)
12391242
$path = implode('/', $segments);
12401243
$linkFile = preg_replace('#^(\.\./)+#', '', $linkFile);
12411244

1242-
// use only the file name for nice links
1243-
if ($this->niceLinks == true) {
1244-
$segments = explode('/', $linkText);
1245-
$segments = array_slice($segments, count($segments) - 1, 1);
1246-
$linkText = $segments[0];
1247-
}
1245+
}
1246+
1247+
// use only the file name for nice links
1248+
if ($this->niceLinks == true) {
1249+
$segments = explode('/', $linkText);
1250+
$segments = array_slice($segments, count($segments) - 1, 1);
1251+
$linkText = $segments[0];
12481252
}
12491253

12501254

@@ -1343,13 +1347,9 @@ protected function inlineInternalEmbed($Excerpt)
13431347
return;
13441348
}
13451349

1346-
1347-
13481350
$raw = $m[1];
13491351
$parts = explode('|', $raw);
13501352

1351-
1352-
13531353
$file = $parts[0];
13541354
$mod1 = $parts[1] ?? null;
13551355
$mod2 = $parts[2] ?? null;
@@ -1416,7 +1416,6 @@ protected function inlineInternalEmbed($Excerpt)
14161416

14171417
}
14181418

1419-
14201419
protected function buildInternalImage(string $file, array $attrs, int $extent)
14211420
{
14221421
$src = rtrim($this->uriPath . $this->path, '/') . '/' . $file;
@@ -1464,7 +1463,6 @@ protected function buildInternalImage(string $file, array $attrs, int $extent)
14641463
];
14651464
}
14661465

1467-
14681466
protected function buildInternalImageFromFragment(string $file, int $extent)
14691467
{
14701468
[$file, $fragment] = explode('#', $file, 2);
@@ -1506,7 +1504,6 @@ protected function buildInternalImageFromLegacy(string $raw, int $extent)
15061504
return $this->buildInternalImage($file, $attrs, $extent);
15071505
}
15081506

1509-
15101507
protected function popupIconSvg()
15111508
{
15121509
return '<svg class="popup-icon" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">

perlite/content.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function parseContent($requestFile)
6363
global $lineBreaks;
6464
global $allowedFileLinkTypes;
6565
global $htmlSafeMode;
66-
global $relPathes;
66+
global $absolutePath;
67+
global $niceLinks;
6768

6869

6970
// call menu again to refresh the array
@@ -78,15 +79,15 @@ function parseContent($requestFile)
7879

7980

8081
// Relative or absolute pathes
81-
if ($relPathes) {
82+
if ($absolutePath) {
8283
$path = $startDir;
8384
} else {
8485
$path = $startDir . $path;
8586
}
8687

8788

8889

89-
$Parsedown = new PerliteParsedown($path, $uriPath,true, $allowedFileLinkTypes);
90+
$Parsedown = new PerliteParsedown($path, $uriPath,$niceLinks, $allowedFileLinkTypes);
9091
$Parsedown->setSafeMode($htmlSafeMode);
9192
$Parsedown->setBreaksEnabled($lineBreaks);
9293
$cleanFile = '';

perlite/helper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
$hiddenFileAccess = empty(getenv('HIDDEN_FILE_ACCESS')) ? false : filter_var(getenv('HIDDEN_FILE_ACCESS'), FILTER_VALIDATE_BOOLEAN);
4141

4242
// use absolut paths instead of relative paths
43-
if (!isset($relPathes))
44-
$relPathes = empty(getenv('ABSOLUTE_PATHS')) ? false : filter_var(getenv('ABSOLUTE_PATHS'), FILTER_VALIDATE_BOOLEAN);
43+
if (!isset($absolutePath))
44+
$absolutePath = empty(getenv('ABSOLUTE_PATHS')) ? false : filter_var(getenv('ABSOLUTE_PATHS'), FILTER_VALIDATE_BOOLEAN);
4545

4646
// Meta Tags infos
4747
if (empty($siteTitle))
@@ -78,6 +78,11 @@
7878
if (!isset($lineBreaks))
7979
$lineBreaks = empty(getenv('LINE_BREAKS')) ? true : filter_var(getenv('LINE_BREAKS'), FILTER_VALIDATE_BOOLEAN);
8080

81+
// nice links
82+
if (!isset($niceLinks))
83+
$niceLinks = empty(getenv('NICE_LINKS')) ? true : filter_var(getenv('NICE_LINKS'), FILTER_VALIDATE_BOOLEAN);
84+
85+
8186
// file types
8287
if (empty($allowedFileLinkTypes))
8388
$allowedFileLinkTypes = empty(getenv('ALLOWED_FILE_LINK_TYPES')) ? ['pdf', 'mp4'] : explode(",", getenv('ALLOWED_FILE_LINK_TYPES'));

perlite/settings.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121
$showLocalGraph = "true";
2222
$font_size = "15";
2323
$hideFolders = "docs,trash";
24+
$niceLinks = true;
2425

2526

2627
// --- Advanced Settings ---
2728
$hiddenFileAccess = false;
28-
$relPathes = false;
29+
$absolutePath = false;
2930
$uriPath = "/";
3031
$htmlSafeMode = true;
3132
$useZettelkastenFilenames = false;
3233
$highlightJSLangs = ["powershell", "x86asm"];
3334
$allowedFileLinkTypes = ['pdf', 'mp4'];
34-
$tempPath = ""; // path for graph html, leave empty for automatic
35+
$tempPath = ""; // path to store the pre-rendered graph relations, leave empty for /tmp
3536

3637

3738
// --- Metadata Settings ---

0 commit comments

Comments
 (0)