+ /**
+ * Output a note as a standalone text file
+ *
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function text($guid)
+ {
+ $note = $this->getNotes()->load($guid, false);
+ if ($note === null) {
+ $res = new ErrorResponse('Note does not exist');
+ $res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
+ return $res;
+ }
+
+ $converter = new \OCA\Grauphel\Converter\ReStructuredText();
+ $converter->internalLinkHandler = array($this, 'textNoteLinkHandler');
+ try {
+ $title = htmlspecialchars_decode($note->title, ENT_QUOTES | ENT_HTML5);
+ $text = $title . "\n"
+ . str_repeat('*', strlen($title)) . "\n"
+ . "\n";
+ $text .= $converter->convert($note->{'note-content'});
+ return new \OCA\Grauphel\Response\TextResponse($text);
+ } catch (\OCA\Grauphel\Converter\Exception $e) {
+ $res = new ErrorResponse(
+ 'Error converting note to reStructuredText.'
+ . ' Please report a bug to the grauphel developers.'
+ );
+ $res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
+ return $res;
+ }
+ }
+
+ public function textNoteLinkHandler($noteTitle)
+ {
+ return $noteTitle;
+ }
+