@@ -63,6 +63,7 @@ def convert_wikilinks(
6363 * ,
6464 include_project : bool = True ,
6565 ambiguous_aliases : frozenset [str ] = frozenset (),
66+ permalinks : dict [str , str ] | None = None ,
6667) -> str :
6768 """Use MarkdownIt's code/escape/link rules while retaining untouched source bytes."""
6869 body = body .replace ("\r \n " , "\n " ).replace ("\r " , "\n " )
@@ -114,6 +115,16 @@ def wikilink(state: StateInline, silent: bool) -> bool:
114115 resolved = targets .get (relative .lstrip ("/" ))
115116 if resolved is None :
116117 resolved = targets .get (relative .lstrip ("/" ) + ".md" )
118+ if resolved is None and permalinks :
119+ # Semantic addresses precede title/path aliases, even when they look like filenames.
120+ for candidate in build_permalink_resolution_candidates (
121+ target , project , include_project
122+ ):
123+ if target in ambiguous_aliases and candidate != target :
124+ break
125+ if candidate in permalinks :
126+ resolved = permalinks [candidate ]
127+ break
117128 if resolved is None :
118129 for candidate in build_permalink_resolution_candidates (
119130 target , project , include_project
@@ -195,6 +206,7 @@ def wikilink(state: StateInline, silent: bool) -> bool:
195206def render_bundle (snapshot : ExportSnapshot ) -> tuple [ExportFile , ...]:
196207 """Preserve frontmatter and prose; attach only semantics lost by link conversion."""
197208 targets : dict [str , str ] = {}
209+ permalinks : dict [str , str ] = {}
198210 ambiguous : set [str ] = set ()
199211 documents : dict [str , Document ] = {}
200212 titles : dict [str , str ] = {}
@@ -220,7 +232,7 @@ def render_bundle(snapshot: ExportSnapshot) -> tuple[ExportFile, ...]:
220232 aliases = {file .path , str (PurePosixPath (file .path ).with_suffix ("" )), title }
221233 permalink = normalize_frontmatter_value (source_metadata .get ("permalink" ))
222234 if isinstance (permalink , str ) and permalink :
223- aliases . add ( permalink )
235+ permalinks [ permalink ] = file . path
224236 for alias in aliases :
225237 if alias in targets and targets [alias ] != file .path :
226238 ambiguous .add (alias )
@@ -268,6 +280,7 @@ def render_bundle(snapshot: ExportSnapshot) -> tuple[ExportFile, ...]:
268280 snapshot .project ,
269281 include_project = snapshot .permalinks_include_project ,
270282 ambiguous_aliases = frozenset (ambiguous ),
283+ permalinks = permalinks ,
271284 )
272285 content = "---\n " + yaml .safe_dump (metadata , allow_unicode = True , sort_keys = False )
273286 content += "---\n " + body
0 commit comments