Skip to content

Commit 2c6afdf

Browse files
authored
Merge pull request #47 from markstory/issue-44
Fix prefix-less link generation for properties and classes
2 parents dedfb34 + 96d41f2 commit 2c6afdf

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
pip install -r requirements.txt
3030
pip install .
3131
32-
- name: Build Test
32+
- name: Build test/
3333
run: |
3434
cd test && make html SPHINXOPTS='-W'
3535

sphinxcontrib/phpdomain.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,15 @@ def process_link(self, env, refnode, has_explicit_title, title, target):
541541
if title.startswith("::"):
542542
title = title[2:]
543543
target = target.lstrip('~') # only has a meaning for the title
544-
# if the first character is a tilde, don't display the module/class
545-
# parts of the contents
546-
if title[0:1] == '~':
547-
m = re.search(r"(?:.+[:]{2}|(?:.*?\\{2})+)?(.*)\Z", title)
544+
545+
# If the first char is ~ don't display the leading namespace & class.
546+
if title.startswith('~'):
547+
m = re.search(r"(?:.+[:]{2}|(?:.*?\\{1,2})+)?(.*)\Z", title)
548548
if m:
549549
title = m.group(1)
550550

551-
if not title.startswith("$"):
552-
refnode['php:namespace'] = env.temp_data.get('php:namespace')
553-
refnode['php:class'] = env.temp_data.get('php:class')
551+
refnode['php:namespace'] = env.temp_data.get('php:namespace')
552+
refnode['php:class'] = env.temp_data.get('php:class')
554553

555554
return title, target
556555

test/test_doc.rst

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Test Case - Global symbols with no namespaces
166166

167167
:php:func:`DateTime::getLastErrors()`
168168

169-
:php:func:`~DateTime::setDate()`
169+
:php:func:`DateTime::setDate()`
170170

171171
:php:func:`DateTime::ATOM`
172172

@@ -198,11 +198,21 @@ Test Case - Global symbols with no namespaces
198198

199199
:php:func:`LogTrait::log()`
200200

201-
.. php:namespace:: LibraryName
201+
Test Case - Prefix less links
202+
-----------------------------
203+
204+
The following links should not be prefixed with a classname.
205+
206+
:php:func:`~DateTime::setDate()`
207+
208+
:php:attr:`~DateTime::$testattr`
209+
202210

203211
Namespaced elements
204212
===================
205213

214+
.. php:namespace:: LibraryName
215+
206216
.. php:function:: namespaced_function($one[, $two])
207217
208218
A function in a namespace
@@ -308,6 +318,8 @@ Namespaced elements
308318
Test Case - not including namespace
309319
-----------------------------------
310320

321+
Within a namespace context you don't need to include the namespace in links.
322+
311323
:php:ns:`LibraryName`
312324

313325
:php:func:`namespaced_function()`
@@ -316,9 +328,6 @@ Test Case - not including namespace
316328

317329
:php:class:`LibraryClass`
318330

319-
320-
:php:class:`~LibraryName\\LibraryClass`
321-
322331
:php:func:`LibraryClass::instanceMethod`
323332

324333
:php:func:`LibraryClass::staticMethod()`
@@ -353,8 +362,6 @@ Test Case - not including namespace
353362

354363
:php:interface:`LibraryInterface`
355364

356-
:php:interface:`~LibraryName\\LibraryInterface`
357-
358365
:php:func:`LibraryInterface::instanceMethod`
359366

360367
:php:exc:`NamespaceException`
@@ -365,6 +372,28 @@ Test Case - not including namespace
365372

366373
:php:func:`LibraryName\\TemplateTrait::render()`
367374

375+
Test Case - Links with prefix trimming
376+
--------------------------------------
377+
378+
All of the following links should not be prefixed with a namespace.
379+
380+
:php:interface:`~LibraryName\\LibraryInterface`
381+
382+
:php:class:`~LibraryName\\LibraryClass`
383+
384+
:php:trait:`~LibraryName\\TemplateTrait`
385+
386+
:php:exc:`~LibraryName\\NamespaceException`
387+
388+
All of the following links should not be prefixed with a classname.
389+
390+
:php:func:`~LibraryClass::instanceMethod`
391+
392+
:php:const:`~LibraryClass::TEST_CONST`
393+
394+
:php:attr:`~LibraryClass::$property`
395+
396+
368397
Test Case - global access
369398
-------------------------
370399

@@ -378,6 +407,8 @@ Test Case - global access
378407

379408
:php:attr:`LibraryName\\LibraryClass::$property`
380409

410+
:php:attr:`~LibraryName\\LibraryClass::$property` Should not be prefixed with classname.
411+
381412
:php:const:`LibraryName\\LibraryClass::TEST_CONST`
382413

383414
:php:const:`LibraryName\\NS_CONST`

0 commit comments

Comments
 (0)