diff --git a/docs/01_Features/CommonMark_compliant.md b/docs/01_Features/CommonMark_compliant.md index 44ba8a5..228efa7 100644 --- a/docs/01_Features/CommonMark_compliant.md +++ b/docs/01_Features/CommonMark_compliant.md @@ -63,7 +63,7 @@ Preformatted blocks are useful for ASCII art: ,-. , ,-. ,-. / \ ( )-( ) - \ | ,.>-( )-< + \ | ,.>-( )-< \|,' ( )-( ) Y ___`-' `-' |/__/ `-' diff --git a/docs/01_Features/Multiple_Output_Formats.md b/docs/01_Features/Multiple_Output_Formats.md index 47ab4bc..5835ddf 100644 --- a/docs/01_Features/Multiple_Output_Formats.md +++ b/docs/01_Features/Multiple_Output_Formats.md @@ -16,3 +16,7 @@ Code Highlight | √ | X (Planned) | √ (Using macros) Live Mode | √ | X | X Pages Ordering | √ | √ | X (API Limitation) Google / Piwik analytics | √ | √ | √ (Configured on Conflence) + +## Confluence Example + +You can see this documentation uploaded to Confluence : https://dauxio.atlassian.net/wiki/spaces/DOC/overview diff --git a/docs/_index.md b/docs/_index.md index a1b963f..3dab9bc 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -8,8 +8,8 @@ --- -
-
+
+
#### For Authors @@ -24,7 +24,7 @@ * [Table of Contents](01_Features/Table_of_contents.md)
-
+
#### For Developers @@ -34,7 +34,7 @@ * Work with pages metadata
-
+
#### For Marketing diff --git a/docs/config.json b/docs/config.json index 4989906..6b94d0f 100644 --- a/docs/config.json +++ b/docs/config.json @@ -29,5 +29,10 @@ "GitHub Repo": "https://github.com/dauxio/daux.io", "Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues" } + }, + "confluence": { + "base_url": "https://dauxio.atlassian.net/wiki/", + "space_id": "DOC", + "root_id": 196610 } } diff --git a/libs/Format/Confluence/Api.php b/libs/Format/Confluence/Api.php index 80d098b..43dfc67 100644 --- a/libs/Format/Confluence/Api.php +++ b/libs/Format/Confluence/Api.php @@ -60,9 +60,9 @@ class Api } $message = $label . - ' [url] ' . $request->getUri() . - ' [status code] ' . $response->getStatusCode() . - ' [message] '; + "\n [url] " . $request->getUri() . + "\n [status code] " . $response->getStatusCode() . + "\n [message] "; $body = $response->getBody(); $json = json_decode($body, true); @@ -201,10 +201,47 @@ class Api try { $this->getClient()->put("content/$page_id", ['json' => $body]); } catch (BadResponseException $e) { - throw $this->handleError($e); + $error = $this->handleError($e); + + $re = '/\[([0-9]*),([0-9]*)\]$/'; + preg_match($re, $error->getMessage(), $matches, PREG_OFFSET_CAPTURE, 0); + + if (count($matches) == 3) { + echo "\nContent: \n"; + echo $this->showSourceCode($content, $matches[1][0], $matches[2][0]); + } + + throw $error; } } + public function showSourceCode($css, $lineNumber, $column) + { + $lines = preg_split("/\r?\n/", $css); + $start = max($lineNumber - 3, 0); + $end = min($lineNumber + 2, count($lines)); + + $maxWidth = strlen("$end"); + + $filtered = array_slice($lines, $start, $end - $start); + + $prepared = []; + foreach ($filtered as $index => $line) { + + $number = $start + 1 + $index; + $gutter = substr(' ' . (' ' . $number), -$maxWidth) . ' | '; + + if ($number == $lineNumber) { + $spacing = str_repeat(" ", strlen($gutter) + $column - 2); + $prepared[] = '>' . $gutter . $line . "\n " . $spacing . '^'; + } else { + $prepared[] = ' ' . $gutter . $line; + } + } + + return implode("\n", $prepared); + } + /** * Delete a page * diff --git a/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php new file mode 100644 index 0000000..2e738f2 --- /dev/null +++ b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php @@ -0,0 +1,32 @@ +", "]]]]>", $content); + } + + public function getHTMLElement($body, $language) + { + $body = 'escapeCDATA($body) . ']]>'; + + $content = []; + + if ($language) { + $content[] = new HtmlElement('ac:parameter', ['ac:name' => 'language'], $language); + } + + $content[] = new HtmlElement('ac:plain-text-body', [], $body); + + return new HtmlElement( + 'ac:structured-macro', + ['ac:name' => 'code'], + $content + ); + } +} diff --git a/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php index 4dfcdea..9f66175 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php @@ -2,11 +2,10 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\FencedCode; -use League\CommonMark\Block\Renderer\BlockRendererInterface; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class FencedCodeRenderer implements BlockRendererInterface +class FencedCodeRenderer extends CodeRenderer { protected $supported_languages = [ 'actionscript3', @@ -48,19 +47,9 @@ class FencedCodeRenderer implements BlockRendererInterface throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } - $content = []; + $language = $this->getLanguage($block->getInfoWords(), $htmlRenderer); - if ($language = $this->getLanguage($block->getInfoWords(), $htmlRenderer)) { - $content[] = new HtmlElement('ac:parameter', ['ac:name' => 'language'], $language); - } - - $content[] = new HtmlElement('ac:plain-text-body', [], 'getStringContent() . ']]>'); - - return new HtmlElement( - 'ac:structured-macro', - ['ac:name' => 'code'], - $content - ); + return $this->getHTMLElement($block->getStringContent(), $language); } public function getLanguage($infoWords, ElementRendererInterface $htmlRenderer) diff --git a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php index 537a353..5e3cb09 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php @@ -2,11 +2,10 @@ use League\CommonMark\Block\Element\AbstractBlock; use League\CommonMark\Block\Element\IndentedCode; -use League\CommonMark\Block\Renderer\BlockRendererInterface; use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; -class IndentedCodeRenderer implements BlockRendererInterface +class IndentedCodeRenderer extends CodeRenderer { /** * @param AbstractBlock $block @@ -21,10 +20,6 @@ class IndentedCodeRenderer implements BlockRendererInterface throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } - return new HtmlElement( - 'ac:structured-macro', - ['ac:name' => 'code'], - new HtmlElement('ac:plain-text-body', [], 'getStringContent() . ']]>') - ); + return $this->getHTMLElement($block->getStringContent(), ""); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php index 2bee914..42217d0 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php @@ -41,7 +41,7 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer $file = $this->resolveInternalFile($url); $link_props = [ - 'ri:content-title' => trim($this->daux['confluence']['prefix']) . ' ' . $file->getTitle(), + 'ri:content-title' => trim(trim($this->daux['confluence']['prefix']) . ' ' . $file->getTitle()), 'ri:space-key' => $this->daux['confluence']['space_id'], ]; diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 4dda51c..030f08a 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -73,6 +73,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $confluence = $params['confluence']; $this->prefix = trim($confluence['prefix']) . ' '; + if ($this->prefix == ' ') { + $this->prefix = ''; + } $tree = $this->runAction( 'Generating Tree ...', diff --git a/libs/Format/Confluence/Publisher.php b/libs/Format/Confluence/Publisher.php index bbfb200..aa41b0d 100644 --- a/libs/Format/Confluence/Publisher.php +++ b/libs/Format/Confluence/Publisher.php @@ -48,7 +48,7 @@ class Publisher try { return $this->runAction($title, $this->output, $this->width, $closure); } catch (BadResponseException $e) { - $this->output->writeLn(' ' . $e->getMessage() . ''); + $this->output->writeLn('' . $e->getMessage() . ''); } }