Skip to content

Commit

Permalink
[FEAT] use current filename to get the original file name (#788)
Browse files Browse the repository at this point in the history
This will make markdown rendering work with less errors.
  • Loading branch information
jaapio authored Oct 19, 2024
1 parent 40cda82 commit 2be3afc
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 236 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"ext-dom": "*",
"ext-libxml": "*",
"brotkrueml/twig-codehighlight": "^0.1.1",
"phpdocumentor/guides-cli": "^1.0",
"phpdocumentor/guides": "^1.6",
"phpdocumentor/guides-cli": "^1.5",
"phpdocumentor/guides-graphs": "^1.0",
"phpdocumentor/guides-markdown": "^1.0",
"phpdocumentor/guides-markdown": "^1.5",
"phpdocumentor/guides-restructured-text": "^1.5",
"phpdocumentor/guides-theme-bootstrap": "^1.0",
"symfony/clock": "^6.4",
"symfony/finder": "^6.4",
Expand Down Expand Up @@ -54,6 +56,7 @@
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpdocumentor/shim": true,
"phpstan/extension-installer": true
},
"platform": {
Expand Down
189 changes: 163 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Brotkrueml\TwigCodeHighlight\Extension as CodeHighlight;
use phpDocumentor\Guides\Event\PostCollectFilesForParsingEvent;
use phpDocumentor\Guides\Event\PostParseDocument;
use phpDocumentor\Guides\Event\PostProjectNodeCreated;
use phpDocumentor\Guides\Event\PostRenderProcess;
use phpDocumentor\Guides\Event\PreParseProcess;
Expand Down Expand Up @@ -33,6 +34,7 @@
use T3Docs\Typo3DocsTheme\EventListeners\AddThemeSettingsToProjectNode;
use T3Docs\Typo3DocsTheme\EventListeners\CopyResources;
use T3Docs\Typo3DocsTheme\EventListeners\IgnoreLocalizationsFolders;
use T3Docs\Typo3DocsTheme\EventListeners\OriginalFileNameSetter;
use T3Docs\Typo3DocsTheme\EventListeners\TestingModeActivator;
use T3Docs\Typo3DocsTheme\Inventory\Typo3InventoryRepository;
use T3Docs\Typo3DocsTheme\Packagist\PackagistService;
Expand Down Expand Up @@ -197,5 +199,8 @@
->tag('event_listener', ['event' => PostCollectFilesForParsingEvent::class])

->set(TestingModeActivator::class)
->tag('event_listener', ['event' => PreParseProcess::class]);
->tag('event_listener', ['event' => PreParseProcess::class])

->set(OriginalFileNameSetter::class)
->tag('event_listener', ['event' => PostParseDocument::class]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% endif -%}
{%- set copySources = getSettings('copy_sources') -%}
{%- if (copySources) %}
<a class="btn btn-sm btn-light" href="{{ copyDownload(env.currentFileName ~ '.rst', '_sources/' ~ env.currentFileName ~ '.rst.txt') }}" rel="nofollow noopener" target="_blank">
<a class="btn btn-sm btn-light" href="{{ copyDownload(sourceFilename(), '_sources/' ~ sourceFilename() ~ '.txt') }}" rel="nofollow noopener" target="_blank">
<span class="btn-icon"><span class="fas fa-code"></span></span>
<span class="btn-text">View source</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p class="caption">Contributors Corner</p>
<ul class="menu-level-1">
{%- if (copySources) %}
<li><a href="{{ copyDownload(env.currentFileName ~ '.rst', '_sources/' ~ env.currentFileName ~ '.rst.txt') }}" rel="nofollow noopener" target="_blank">
<li><a href="{{ copyDownload(sourceFilename(), '_sources/' ~ sourceFilename() ~ '.txt') }}" rel="nofollow noopener" target="_blank">
View source of current document
</a></li>
{% endif -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace T3Docs\Typo3DocsTheme\EventListeners;

use phpDocumentor\Guides\Event\PostParseDocument;

final class OriginalFileNameSetter
{
public function __invoke(PostParseDocument $event): void
{
$event->setDocumentNode(
$event->getDocumentNode()?->withKeepExistingOptions(['originalFileName' => $event->getOriginalFileName()])
);
}
}
Loading

0 comments on commit 2be3afc

Please sign in to comment.