Added internal documentation links

This commit is contained in:
Stéphane Goetz 2015-06-29 16:16:39 +02:00 gecommit door Stéphane Goetz
bovenliggende 60b50919b4
commit 5791fccea8
10 gewijzigde bestanden met toevoegingen van 154 en 10 verwijderingen

Bestand weergeven

@ -367,3 +367,5 @@ If you have a global mime map entry for `.less` files set for the server, you wi
## Support
If you need help using Daux.io, or have found a bug, please create an issue on the <a href="https://github.com/justinwalsh/daux.io/issues" target="_blank">GitHub repo</a>.
[Code Highlighting examples](!Examples/Code_Highlighting)

Bestand weergeven

@ -1,5 +1,8 @@
Highlight.js highlights syntax in code examples on blogs, forums and in fact on any web pages. It's very easy to use because it works automatically: finds blocks of code, detects a language, highlights it. [Learn more.](http://softwaremaniacs.org/soft/highlight/en/)
You can even use [Github Flavored Markdown](!Examples/GitHub_Flavored_Markdown)
**Python**
@requires_authorization

Bestand weergeven

@ -1,4 +1,4 @@
<?php namespace Todaymade\Daux\Format\Confluence;
<?php namespace Todaymade\Daux\Format\Base\CommonMark;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
@ -16,11 +16,19 @@ class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
$environment = Environment::createCommonMarkEnvironment();
$environment->mergeConfig($config);
//Add code renderer
$environment->addBlockRenderer('FencedCode', new FencedCodeRenderer());
$environment->addBlockRenderer('IndentedCode', new IndentedCodeRenderer());
$this->extendEnvironment($environment);
$this->docParser = new DocParser($environment);
$this->htmlRenderer = new HtmlRenderer($environment);
}
protected function getLinkRenderer(Environment $environment)
{
return new LinkRenderer($environment->getConfig('daux'));
}
protected function extendEnvironment(Environment $environment)
{
$environment->addInlineRenderer('Link', $this->getLinkRenderer($environment));
}
}

Bestand weergeven

@ -0,0 +1,63 @@
<?php namespace Todaymade\Daux\Format\Base\CommonMark;
use League\CommonMark\HtmlElement;
use League\CommonMark\HtmlRendererInterface;
use League\CommonMark\Inline\Element\AbstractInline;
use League\CommonMark\Inline\Element\Link;
use Todaymade\Daux\Config;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Exception;
use Todaymade\Daux\Tree\Entry;
class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
{
/**
* @var Config
*/
protected $daux;
public function __construct($daux)
{
$this->daux = $daux;
}
/**
* @param $url
* @return Entry
* @throws Exception
*/
protected function resolveInternalFile($url) {
$file = DauxHelper::getFile($this->daux['tree'], $url);
if ($file) {
return $file;
}
$file = DauxHelper::getFile($this->daux['tree'], $url . '.html');
if ($file) {
return $file;
}
throw new Exception("Could not locate file '$url'");
}
/**
* @param Link $inline
* @param HtmlRendererInterface $htmlRenderer
*
* @return HtmlElement
*/
public function render(AbstractInline $inline, HtmlRendererInterface $htmlRenderer)
{
$element = parent::render($inline, $htmlRenderer);
$url = $inline->getUrl();
if (!empty($url) && $url[0] == '!') {
$file = $this->resolveInternalFile(ltrim($url, "!"));
$element->setAttribute('href', $this->daux['base_url'] . $file->getUrl());
}
return $element;
}
}

Bestand weergeven

@ -1,7 +1,7 @@
<?php namespace Todaymade\Daux\Format\Base;
use League\CommonMark\CommonMarkConverter;
use Todaymade\Daux\Config;
use Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter;
use Todaymade\Daux\Tree\Content;
abstract class MarkdownPage extends SimplePage
@ -26,6 +26,11 @@ abstract class MarkdownPage extends SimplePage
$this->file = $file;
}
public function getFile()
{
return $this->file;
}
public function setParams(Config $params)
{
$this->params = $params;
@ -33,7 +38,7 @@ abstract class MarkdownPage extends SimplePage
protected function getMarkdownConverter()
{
return new CommonMarkConverter();
return new CommonMarkConverter(['daux' => $this->params]);
}
protected function convertPage($content)

Bestand weergeven

@ -0,0 +1,20 @@
<?php namespace Todaymade\Daux\Format\Confluence\CommonMark;
use League\CommonMark\Environment;
class CommonMarkConverter extends \Todaymade\Daux\Format\Base\CommonMark\CommonMarkConverter
{
protected function getLinkRenderer(Environment $environment)
{
return new LinkRenderer($environment->getConfig('daux'));
}
protected function extendEnvironment(Environment $environment)
{
parent::extendEnvironment($environment);
//Add code renderer
$environment->addBlockRenderer('FencedCode', new FencedCodeRenderer());
$environment->addBlockRenderer('IndentedCode', new IndentedCodeRenderer());
}
}

Bestand weergeven

@ -1,4 +1,4 @@
<?php namespace Todaymade\Daux\Format\Confluence;
<?php namespace Todaymade\Daux\Format\Confluence\CommonMark;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\FencedCode;

Bestand weergeven

@ -1,4 +1,4 @@
<?php namespace Todaymade\Daux\Format\Confluence;
<?php namespace Todaymade\Daux\Format\Confluence\CommonMark;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\IndentedCode;

Bestand weergeven

@ -0,0 +1,43 @@
<?php namespace Todaymade\Daux\Format\Confluence\CommonMark;
use League\CommonMark\HtmlElement;
use League\CommonMark\HtmlRendererInterface;
use League\CommonMark\Inline\Element\AbstractInline;
use League\CommonMark\Inline\Element\Link;
class LinkRenderer extends \Todaymade\Daux\Format\Base\CommonMark\LinkRenderer
{
/**
* @param Link $inline
* @param HtmlRendererInterface $htmlRenderer
*
* @return HtmlElement
*/
public function render(AbstractInline $inline, HtmlRendererInterface $htmlRenderer)
{
// Default handling
$element = parent::render($inline, $htmlRenderer);
$url = $inline->getUrl();
if (empty($url) || $url[0] != '!') {
return $element;
}
//Internal links
$file = $this->resolveInternalFile(ltrim($url, "!"));
$link_props = [
'ri:content-title' => trim($this->daux['confluence']['prefix']) . " " . $file->getTitle(),
'ri:space-key' => $this->daux['confluence']['space_id']
];
$page = strval(new HtmlElement('ri:page', $link_props, '', true));
$children = $htmlRenderer->renderInlines($inline->getChildren());
if (strpos($children, "<") !== false) {
$children = '<ac:link-body>' . $children . '</ac:link-body>';
} else {
$children = '<ac:plain-text-link-body><![CDATA[' . $children . ']]></ac:plain-text-link-body>';
}
return new HtmlElement('ac:link', [], $page . $children);
}
}

Bestand weergeven

@ -2,6 +2,7 @@
use DOMDocument;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Format\Confluence\CommonMark\CommonMarkConverter;
class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
{
@ -9,7 +10,7 @@ class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
protected function getMarkdownConverter()
{
return new CommonMarkConverter();
return new CommonMarkConverter(['daux' => $this->params]);
}
protected function generatePage()
@ -80,7 +81,6 @@ class MarkdownPage extends \Todaymade\Daux\Format\Base\MarkdownPage
private function createImageTag($filename, $attributes)
{
$img = "<ac:image";
foreach ($attributes as $name => $value) {