Markdown.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Tools;
  3. use Illuminate\Support\Str;
  4. class Markdown
  5. {
  6. public static function render($text){
  7. return Markdown::marked($text);
  8. }
  9. public static function marked($text){
  10. $host = env('MORUS_RPC_SERVER');
  11. $client = new \Mint\Morus\V1\MarkdownClient($host, [
  12. 'credentials' => \Grpc\ChannelCredentials::createInsecure(),
  13. ]);
  14. $request = new \Mint\Morus\V1\MarkdownToHtmlRequest();
  15. $request->setPayload($text);
  16. $request->setSanitize(true);
  17. list($response, $status) = $client->ToHtml($request)->wait();
  18. if ($status->code !== \Grpc\STATUS_OK) {
  19. return "ERROR: " . $status->code . ", " . $status->details;
  20. }
  21. return $response->getPayload();
  22. }
  23. public static function parsedown($text){
  24. $Parsedown = new \Parsedown();
  25. return $Parsedown->text($text);
  26. }
  27. public static function strdown($text){
  28. return Str::markdown($text);
  29. }
  30. }