aboutsummaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2015-03-17 22:03:39 +0100
committerChristian Weiske <cweiske@cweiske.de>2015-03-17 22:03:39 +0100
commita375467d42cb53599ffddbd1d7ce8fae028972f8 (patch)
tree806da86795775a9e889c70fc4283dc5d7b76ab78 /controller
parent81554f1309cc6a80578100b9583a591012df0d43 (diff)
downloadgrauphel-a375467d42cb53599ffddbd1d7ce8fae028972f8.tar.gz
grauphel-a375467d42cb53599ffddbd1d7ce8fae028972f8.zip
reStructuredText output
Diffstat (limited to 'controller')
-rw-r--r--controller/guicontroller.php3
-rw-r--r--controller/notescontroller.php40
2 files changed, 42 insertions, 1 deletions
diff --git a/controller/guicontroller.php b/controller/guicontroller.php
index 15380c7..29dd03f 100644
--- a/controller/guicontroller.php
+++ b/controller/guicontroller.php
@@ -130,6 +130,9 @@ class GuiController extends Controller
'guid' => $guid, 'username' => $this->user->getUid()
)
),
+ 'text' => $this->urlGen->linkToRoute(
+ 'grauphel.notes.text', array('guid' => $guid)
+ ),
'xml' => $this->urlGen->linkToRoute(
'grauphel.notes.xml', array('guid' => $guid)
),
diff --git a/controller/notescontroller.php b/controller/notescontroller.php
index 893a100..c599e75 100644
--- a/controller/notescontroller.php
+++ b/controller/notescontroller.php
@@ -124,7 +124,7 @@ class NotesController extends Controller
} catch (\OCA\Grauphel\Converter\Exception $e) {
$res = new ErrorResponse(
'Error converting note to HTML.'
- . ' Please repport a bug to the grauphel developers.'
+ . ' Please report a bug to the grauphel developers.'
);
$res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
return $res;
@@ -142,6 +142,44 @@ class NotesController extends Controller
}
/**
+ * 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 {
+ $text = $note->title . "\n"
+ . str_repeat('*', strlen($note->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;
+ }
+
+ /**
* Output a note in tomboy XML format
*
* @link https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat