-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add Meta-information markup
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#meta-information-markup resolves #847
- Loading branch information
Showing
14 changed files
with
246 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/guides-restructured-text/src/RestructuredText/Directives/SectionauthorDirective.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Directives; | ||
|
||
use phpDocumentor\Guides\Nodes\AuthorNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; | ||
use phpDocumentor\Guides\RestructuredText\Parser\Directive; | ||
use Psr\Log\LoggerInterface; | ||
|
||
use function preg_match; | ||
|
||
final class SectionauthorDirective extends BaseDirective | ||
{ | ||
public const NAME_EMAIL_REGEX = '/^(?P<name>[\w\s]+)(?: <(?P<email>[^>]+)>)?$/'; | ||
|
||
public function __construct( | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'sectionauthor'; | ||
} | ||
|
||
/** | ||
* When the default domain contains a class directive, this directive will be shadowed. Therefore, Sphinx re-exports it as rst-class. | ||
* | ||
* See https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rstclass | ||
* | ||
* @return string[] | ||
*/ | ||
public function getAliases(): array | ||
{ | ||
return ['codeauthor']; | ||
} | ||
|
||
/** {@inheritDoc} | ||
* | ||
* @param Directive $directive | ||
*/ | ||
public function process( | ||
BlockContext $blockContext, | ||
Directive $directive, | ||
): Node|null { | ||
$input = $directive->getData(); | ||
$directiveName = $directive->getName(); | ||
if ($input === '') { | ||
$this->logger->warning('`.. ' . $directiveName . ' ::` directive could not be parsed: `' . $input . '`', $blockContext->getLoggerInformation()); | ||
|
||
return null; | ||
} | ||
|
||
if (!preg_match(self::NAME_EMAIL_REGEX, $input, $matches)) { | ||
$this->logger->warning('Content of `.. ' . $directiveName . ':: name <email>` must specify a name and can also specify an email', $blockContext->getLoggerInformation()); | ||
|
||
return null; | ||
} | ||
|
||
$name = $matches['name']; | ||
$email = $matches['email'] ?? null; | ||
$context = match ($directiveName) { | ||
'sectionauthor' => AuthorNode::CONTEXT_SECTION, | ||
default => AuthorNode::CONTEXT_CODE, | ||
}; | ||
|
||
return new AuthorNode($name, [], $context, $email); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/guides/resources/template/html/body/author.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<address itemprop="author" itemscope itemtype="http://schema.org/Person"> | ||
<p>Author: <span itemprop="name">{node.value}</span></p> | ||
<p>Email: <a href="mailto:{node.email}"><span itemprop="email">{node.email}</span></a></p> | ||
</address> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\Nodes; | ||
|
||
use function filter_var; | ||
|
||
use const FILTER_VALIDATE_EMAIL; | ||
|
||
/** | ||
* The author element holds the name of the author of a document, section or code-block | ||
* | ||
* @extends AbstractNode<string> | ||
*/ | ||
final class AuthorNode extends AbstractNode | ||
{ | ||
public const CONTEXT_DOCUMENT = 'document'; | ||
public const CONTEXT_SECTION = 'section'; | ||
public const CONTEXT_CODE = 'code'; | ||
|
||
/** @param Node[] $children */ | ||
public function __construct( | ||
string $value, | ||
private readonly array $children, | ||
private readonly string $context = self::CONTEXT_DOCUMENT, | ||
private string|null $email = null, | ||
) { | ||
$this->value = $value; | ||
if (filter_var($email ?? '', FILTER_VALIDATE_EMAIL)) { | ||
return; | ||
} | ||
|
||
$this->email = null; | ||
} | ||
|
||
/** @return Node[] */ | ||
public function getChildren(): array | ||
{ | ||
return $this->children; | ||
} | ||
|
||
public function getEmail(): string|null | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function getContext(): string | ||
{ | ||
return $this->context; | ||
} | ||
} |
65 changes: 34 additions & 31 deletions
65
tests/Integration/tests/body-elements/line-blocks/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
<!-- content start --> | ||
<div class="section" id="line-blocks"> | ||
<h1>Line Blocks</h1> | ||
<h1>Line Blocks</h1> | ||
|
||
<div class="line-block"> | ||
<div class="line"> | ||
Line blocks are useful for addresses, | ||
</div> | ||
<div class="line"> | ||
verse, and adornment-free lists. | ||
</div> | ||
<div class="line"> | ||
<br> | ||
</div> | ||
<div class="line"> | ||
Each new line begins with a | ||
</div> | ||
<div class="line"> | ||
vertical bar ("|"). | ||
</div> | ||
<div class="line-block"> | ||
<div class="line"> | ||
Line breaks and initial indents | ||
</div> | ||
<div class="line"> | ||
are preserved. | ||
</div> | ||
</div> | ||
<div class="line"> | ||
Continuation lines are wrapped | ||
portions of long lines; they begin | ||
with spaces in place of vertical bars. | ||
</div> | ||
</div> | ||
<p>This is normal text</p> | ||
<div class="line"> | ||
Line blocks are useful for addresses, | ||
</div> | ||
<div class="line"> | ||
verse, and adornment-free lists. | ||
</div> | ||
<div class="line"> | ||
<br> | ||
</div> | ||
<div class="line"> | ||
Each new line begins with a | ||
</div> | ||
<div class="line"> | ||
vertical bar ("|"). | ||
</div> | ||
<div class="line-block"> | ||
<div class="line"> | ||
Line breaks and initial indents | ||
</div> | ||
<div class="line"> | ||
are preserved. | ||
</div> | ||
|
||
</div> | ||
<div class="line"> | ||
Continuation lines are wrapped | ||
portions of long lines; they begin | ||
with spaces in place of vertical bars. | ||
</div> | ||
|
||
</div> | ||
|
||
<p>This is normal text</p> | ||
</div> | ||
|
||
<!-- content end --> |
33 changes: 33 additions & 0 deletions
33
tests/Integration/tests/directives/sectionauthor/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- content start --> | ||
<div class="section" id="document-title"> | ||
<h1>Document Title</h1> | ||
|
||
<div class="section" id="some-section"> | ||
<h2>Some Section</h2> | ||
|
||
<address itemprop="author" itemscope itemtype="http://schema.org/Person"> | ||
<p>Author: <span itemprop="name">{node.value}</span></p> | ||
<p>Email: <a href="mailto:{node.email}"><span itemprop="email">{node.email}</span></a></p> | ||
</address> | ||
|
||
</div> | ||
|
||
<div class="section" id="some-other-section"> | ||
<h2>Some other section</h2> | ||
|
||
<address itemprop="author" itemscope itemtype="http://schema.org/Person"> | ||
<p>Author: <span itemprop="name">{node.value}</span></p> | ||
<p>Email: <a href="mailto:{node.email}"><span itemprop="email">{node.email}</span></a></p> | ||
</address> | ||
|
||
<address itemprop="author" itemscope itemtype="http://schema.org/Person"> | ||
<p>Author: <span itemprop="name">{node.value}</span></p> | ||
<p>Email: <a href="mailto:{node.email}"><span itemprop="email">{node.email}</span></a></p> | ||
</address> | ||
|
||
<pre><code class="language-rst">Lorem *Ipsum* Dolor</code></pre> | ||
</div> | ||
|
||
</div> | ||
|
||
<!-- content end --> |
19 changes: 19 additions & 0 deletions
19
tests/Integration/tests/directives/sectionauthor/input/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
============== | ||
Document Title | ||
============== | ||
|
||
Some Section | ||
============ | ||
|
||
.. sectionauthor:: Lina Wolf <lina.wolf@typo3.org> | ||
|
||
Some other section | ||
================== | ||
|
||
.. sectionauthor:: Lina Wolf | ||
|
||
.. codeauthor:: Lina Wolf <lina.wolf@typo3.org> | ||
|
||
.. code-block:: rst | ||
Lorem *Ipsum* Dolor |
11 changes: 6 additions & 5 deletions
11
tests/Integration/tests/directives/youtube/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
<!-- content start --> | ||
<div class="section" id="document-title"> | ||
<h1>Document Title</h1> | ||
<div class="section" id="document-title"> | ||
<h1>Document Title</h1> | ||
|
||
<iframe src="https://www.youtube-nocookie.com/embed/hdDD0SNJ-pk" width="560" height="315" title="PHP DocBlock - Adding Comments to Classes & Methods" allow="encrypted-media; picture-in-picture; web-share" allowfullscreen> | ||
</iframe> | ||
<iframe src="https://www.youtube-nocookie.com/embed/hdDD0SNJ-pk" width="560" height="315" title="PHP DocBlock - Adding Comments to Classes & Methods" allow="encrypted-media; picture-in-picture; web-share" allowfullscreen> | ||
</iframe> | ||
|
||
</div> | ||
|
||
</div> | ||
<!-- content end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ <h2>An image with relative paths</h2> | |
</figcaption> | ||
</figure> | ||
|
||
|
||
</div> | ||
|
||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ <h2>An image with relative paths</h2> | |
</figcaption> | ||
</figure> | ||
|
||
|
||
</div> | ||
|
||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters