@@ -16,7 +16,12 @@ class ContentTextParser {
1616 * ]
1717 */
1818 public static $ contentLinks = [];
19+
20+ /**
21+ * ./Master/Contents
22+ */
1923 public static $ currentRootDirectory ='' ;
24+ public static $ currentDirectory ='' ;
2025 public static $ isInitialized = false ;
2126
2227 public static function Init () {
@@ -31,7 +36,8 @@ public static function Init() {
3136
3237 public static function Parse ($ text , $ contentPath , &$ context ) {
3338 if (!static ::$ isInitialized ) static ::Init ();
34- static ::$ currentRootDirectory = substr (GetTopDirectory ($ contentPath ), 1 );
39+ static ::$ currentRootDirectory = ContentsDatabaseManager::GetRootContentsFolder ($ contentPath );
40+ static ::$ currentDirectory = dirname ($ contentPath );
3541 return OutlineText \Parser::Parse ($ text , $ context );
3642 }
3743
@@ -42,7 +48,17 @@ public static function CreateContext($contentPath) {
4248 }
4349
4450 public static function ParseContentLink ($ matches , $ context ) {
45- $ contentPath = URI2Path (static ::$ currentRootDirectory . '/ ' . $ matches [1 ][0 ]);
51+ $ path = $ matches [1 ][0 ];
52+ $ contentPath = '' ;
53+ if (strpos ($ path , '/ ' ) === 0 ){
54+ // To navigate from the root directory
55+ $ contentPath = static ::$ currentRootDirectory . $ path ;
56+ }
57+ else {
58+ // To navigate from the current directory
59+ $ contentPath = static ::$ currentDirectory . '/ ' . $ path ;
60+ }
61+ Debug::Log ($ contentPath );
4662 $ content = new Content ();
4763 if (!$ content ->SetContent ($ contentPath )) {
4864 // if not exists, return the text that matched the full pattern.
@@ -54,9 +70,9 @@ public static function ParseContentLink($matches, $context) {
5470 $ title = '' ;
5571 $ parent = $ content ->Parent ();
5672 if ($ parent !== false ) {
57- $ title .= $ parent ->title . '- ' ;
73+ $ title .= NotBlankText ([ $ parent ->title , basename ( $ parent -> path )]) . '- ' ;
5874 }
59- $ title .= $ content ->title ;
75+ $ title .= NotBlankText ([ $ content ->title , basename ( $ content -> path )]) ;
6076 $ href = CreateContentHREF ($ content ->path );
6177 return '<a href=" ' . $ href .'"> ' . $ title . '</a> ' ;
6278 }
0 commit comments