Example #1
0
 public function transformReadmeMd($readmepathsource, $readmepathdestination)
 {
     if (!File::exists($readmepathsource)) {
         $this->command->error('File ' . $readmepathsource . ' not exist');
         exit;
     }
     $dir = \Padosoft\Workbench\Parameters\Dir::adjustPath(__DIR__) . 'resources/index.html';
     if (!File::exists($dir)) {
         $this->command->error('File ' . $dir . ' not exist');
         exit;
     }
     File::copy($dir, $readmepathdestination);
     $index = file_get_contents($readmepathdestination);
     $index = str_replace('@@@package_name', $this->workbenchSettings->requested['packagename']['valore'], $index);
     $readme = file_get_contents($readmepathsource);
     $converter = new CommonMarkConverter();
     $index = str_replace("@@@readme", $converter->convertToHtml($readme), $index);
     $documentation = "<h1>API Documentation</h1>\n<p>Please see API documentation at http://" . $this->workbenchSettings->requested['organization']['valore'] . ".github.io/" . $this->workbenchSettings->requested['packagename']['valore'] . "</p>";
     $documentation_mod = "<a name=api-documentation ></a>" . "<h1>API Documentation</h1>\n<p>Please see API documentation at <a href ='http://" . $this->workbenchSettings->requested['organization']['valore'] . ".github.io/" . $this->workbenchSettings->requested['packagename']['valore'] . "'>" . $this->workbenchSettings->requested['packagename']['valore'] . "</a></p>";
     $destination = File::dirname($readmepathdestination);
     $list = array_diff(File::directories($destination), array($destination . '\\resources'));
     $list = array_diff($list, array($destination . '/resources'));
     $documentation_mod = $documentation_mod . "<ul>";
     foreach ($list as $tag) {
         $tag = File::basename(\Padosoft\Workbench\Parameters\Dir::adjustPath($tag));
         $documentation_mod = $documentation_mod . "<li><a href = 'https://" . $this->workbenchSettings->requested['organization']['valore'] . ".github.io/" . $this->workbenchSettings->requested['packagename']['valore'] . "/" . $tag . "'>" . $tag . "</a></li>";
     }
     $documentation_mod = $documentation_mod . "</ul>";
     $index = str_replace($documentation, $documentation_mod, $index);
     file_put_contents($readmepathdestination, $index);
 }
Example #2
0
 public function MarkDownConverter()
 {
     return function ($file) {
         $converter = new CommonMarkConverter();
         return $converter->convertToHTML($file);
     };
 }
 /**
  * Transform the content body attribute from Markdown to HTML.
  *
  * @param \League\Event\EventInterface $event
  */
 public function handle(EventInterface $event)
 {
     $md = new CommonMarkConverter();
     if (isset($event->content['body'])) {
         $event->content['body'] = $md->convertToHtml($event->content['body']);
     }
 }
Example #4
0
 public function getFormattedContentAttribute()
 {
     $commonMark = new CommonMarkConverter();
     $content = "{$this->content} \n\n {$this->image_links}";
     //dd($content);
     $content = $commonMark->convertToHtml($content);
     return Htmlawed::filter($content);
 }
 public function compile($body)
 {
     $css = file_get_contents(__DIR__ . '/../../../bower_components/github-markdown-css/github-markdown.css');
     $html = '<div class="markdown-body">' . $this->markdowner->convertToHtml($body) . '</div>';
     $this->inliner->setCSS($css);
     $this->inliner->setHTML($html);
     return $this->inliner->convert();
 }
Example #6
0
 public function create(Request $request)
 {
     $this->validate($request, ['user_id' => 'required', 'thread_id' => 'required', 'content' => 'required|min:20']);
     $md = new CommonMarkConverter();
     $parsed = $md->convertToHtml($request->input('content'));
     Answer::create(['user_id' => $request->input('user_id'), 'thread_id' => $request->input('thread_id'), 'content' => $parsed]);
     return \Redirect::back();
 }
Example #7
0
 public function __construct()
 {
     // This playground exists to test the components that allow for package template dependencies to be
     // located and auto-loaded at runtime, without replacing any current auto-loaders.
     echo "NewUp Playground Alpha", PHP_EOL, "You should see HTML below, and not markdown.", PHP_EOL, PHP_EOL;
     $converter = new CommonMarkConverter();
     echo $converter->convertToHtml('# Hello World!');
     exit;
 }
function convert_markdown($string, $linebreaks = null)
{
    $newstring = $string;
    if ($linebreaks) {
        $newstring = nl2br($newstring);
    }
    $converter = new CommonMarkConverter();
    $newstring = $converter->convertToHtml($newstring);
    return $newstring;
}
 public function convertToHtml($markdown, Converter $converter = null)
 {
     if (!is_null($this->_cmEnvironment)) {
         return $this->renderMarkdown($markdown);
     }
     if (is_null($converter)) {
         $converter = new Converter();
     }
     return $converter->convertToHtml($markdown);
 }
Example #10
0
 public function readBySlug($slug)
 {
     if (!is_string($slug)) {
         throw new InvalidArgumentException('Slug must be a string.');
     }
     $path = "{$this->pageFolder}{$slug}.md";
     if (!file_exists($path)) {
         throw new PageNotFoundException($slug);
     }
     return $this->converter->convertToHtml(file_get_contents($path));
 }
Example #11
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request)
 {
     $this->validate($request, ['category_id' => 'required|integer', 'user_id' => 'required|integer', 'question' => 'required|max:255', 'explanation' => 'required|min:30']);
     $md = new CommonMarkConverter();
     $parsed = $md->convertToHtml($request->input('explanation'));
     #dd($request->all());
     if ($request->has('is_open')) {
         DB::table('threads')->where('id', '=', $request->input('id'))->update(['category_id' => $request->input('category_id'), 'user_id' => $request->input('user_id'), 'question' => $request->input('question'), 'explanation' => $parsed, 'is_open' => $request->input('is_open'), 'is_solved' => $request->input('is_solved')]);
     } else {
         DB::table('threads')->where('id', '=', $request->input('id'))->update(['category_id' => $request->input('category_id'), 'user_id' => $request->input('user_id'), 'question' => $request->input('question'), 'explanation' => $parsed, 'is_solved' => $request->input('is_solved')]);
     }
     $thread = Thread::find($request->input('id'));
     return Redirect::route('thread.show', ['slug' => $thread->slug]);
 }
Example #12
0
 /**
  * @codeCoverageIgnore
  *
  * @param $route
  *
  * @return array
  */
 public function getFromGithub($route)
 {
     $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/en/' . e($route) . '.md';
     $content = ['text' => '<p>There is no help for this route!</p>', 'title' => $route];
     try {
         $content['text'] = file_get_contents($uri);
     } catch (ErrorException $e) {
         Log::error(trim($e->getMessage()));
     }
     if (strlen(trim($content['text'])) == 0) {
         $content['text'] = '<p>There is no help for this route.</p>';
     }
     $converter = new CommonMarkConverter();
     $content['text'] = $converter->convertToHtml($content['text']);
     return $content;
 }
Example #13
0
 /**
  * @param string $language
  * @param string $route
  *
  * @return array
  */
 public function getFromGithub(string $language, string $route) : array
 {
     $uri = sprintf('https://raw.githubusercontent.com/JC5/firefly-iii-help/master/%s/%s.md', $language, $route);
     $routeIndex = str_replace('.', '-', $route);
     $title = trans('help.' . $routeIndex);
     $content = ['text' => '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>', 'title' => $title];
     $result = Requests::get($uri);
     if ($result->status_code === 200) {
         $content['text'] = $result->body;
     }
     if (strlen(trim($content['text'])) == 0) {
         $content['text'] = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
     }
     $converter = new CommonMarkConverter();
     $content['text'] = $converter->convertToHtml($content['text']);
     return $content;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $users = User::where(['frequency' => 'weekly', 'confirmed' => true, 'unsubscribed' => false])->get();
     $threads = Thread::all();
     $currentWeekIndex = Carbon::now()->weekOfYear;
     $currentYear = Carbon::now()->year;
     $currentWeekChallenges = $threads->filter(function ($thread) use($currentWeekIndex, $currentYear) {
         return $thread->published_at->weekOfYear == $currentWeekIndex && $thread->published_at->year == $currentYear;
     });
     if ($currentWeekChallenges->count() == 0) {
         return;
     }
     $markdownConverter = new CommonMarkConverter();
     $currentWeekChallenges->map(function ($challenge) use($markdownConverter) {
         $challenge->markdown_content = $markdownConverter->convertToHtml($challenge->content);
         $challenge->markdown_content = str_replace('<pre>', '<pre style="white-space: pre-wrap;"', $challenge->markdown_content);
     });
     $users->each(function ($user) use($currentWeekChallenges) {
         $challengesForUser = $this->getChallengesForCurrentUser($user, $currentWeekChallenges);
         if ($challengesForUser->count() > 0) {
             $this->dispatch(new SendChallengesEmail($user, $challengesForUser, 'weekly'));
         }
     });
 }
 /**
  * If ui.help.message is set in $configuration, translate it if requested and then convert it from markdown to HTML.
  *
  * @param array $configuration
  * @param string $idPrefix
  * @param string $nodeTypeName
  * @return void
  */
 protected function translateAndConvertHelpMessage(array &$configuration, $idPrefix, $nodeTypeName = null)
 {
     $helpMessage = '';
     if (isset($configuration['ui']['help'])) {
         // message handling
         if (isset($configuration['ui']['help']['message'])) {
             if ($this->shouldFetchTranslation($configuration['ui']['help'], 'message')) {
                 $translationIdentifier = $this->splitIdentifier($idPrefix . 'ui.help.message');
                 $helpMessage = $this->translator->translateById($translationIdentifier['id'], [], null, null, $translationIdentifier['source'], $translationIdentifier['packageKey']);
             } else {
                 $helpMessage = $configuration['ui']['help']['message'];
             }
         }
         // prepare thumbnail
         if ($nodeTypeName !== null) {
             $thumbnailUrl = '';
             if (isset($configuration['ui']['help']['thumbnail'])) {
                 $thumbnailUrl = $configuration['ui']['help']['thumbnail'];
                 if (strpos($thumbnailUrl, 'resource://') === 0) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUriByPath($thumbnailUrl);
                 }
             } else {
                 # look in well know location
                 $splitPrefix = $this->splitIdentifier($nodeTypeName);
                 $relativePathAndFilename = 'NodeTypes/Thumbnails/' . $splitPrefix['id'] . '.png';
                 $resourcePath = 'resource://' . $splitPrefix['packageKey'] . '/Public/' . $relativePathAndFilename;
                 if (file_exists($resourcePath)) {
                     $thumbnailUrl = $this->resourceManager->getPublicPackageResourceUriByPath($resourcePath);
                 }
             }
             if ($thumbnailUrl !== '') {
                 $helpMessage = '![alt text](' . $thumbnailUrl . ') ' . $helpMessage;
             }
         }
         if ($helpMessage !== '') {
             $helpMessage = $this->markdownConverter->convertToHtml($helpMessage);
             $helpMessage = $this->addTargetAttribute($helpMessage);
         }
     }
     $configuration['ui']['help']['message'] = $helpMessage;
 }
 /**
  * Compile the view at the given path.
  *
  * @param string $path
  *
  * @return void
  */
 public function compile($path)
 {
     $contents = $this->markdown->convertToHtml($this->files->get($path));
     $this->files->put($this->getCompiledPath($path), $contents);
 }
 /**
  * {@inheritdoc}
  */
 public function transform($content)
 {
     return $this->converter->convertToHtml($content);
 }
@extends('template.main')

@section('title', 'Modmail Listing')
@section('css-title', 'modmail-listing')

@section('content')
	<?php 
use League\CommonMark\CommonMarkConverter;
$converter = new CommonMarkConverter();
// Sanitizes input for the markdown converter
function s($str)
{
    $str = str_replace('<em>', '&lt;em&gt;', $str);
    $str = preg_replace('/]\\s\\(/', '](', $str);
    return $str;
}
?>
	<div id="content">
		<p class="timeframe bg-primary"><span>Showing </span>{{ $filters['start'] }} - {{ $filters['end'] < $filters['total'] ? $filters['end'] : $filters['total'] }}<span> of </span>{{ $filters['total'] }}<span> results from </span>{{ $filters['from'] }}<span> to </span>{{ $filters['to'] }}<span> of items created by </span>{{ $filters['author'] }}<span> matching a subject filter of </span>{{ $filters['subject'] }} <span> and a body filter of </span>{{ $filters['body'] }}</p>
		<p>{!! $results->render() !!}</p>
		<div class="col-md-6">
			@foreach ($results as $modmail)
			<div>
				<h4><a href="https://reddit.com/message/messages/{{ substr($modmail['_id'], 3) }}">{{ $modmail['subject'] }}</a></h4>
				<p class="byline">Sent by <a href="https://reddit.com/user/{{ $modmail['author'] }}">{{ $modmail['author'] }}</a> on {{ strftime("%d %B %Y at %H:%M:%S", $modmail['created_at']) }}</p>
				<p><?php 
echo $converter->convertToHtml(s($modmail['body']));
?>
</p>
				@if (count($modmail['replies']) > 0)
				<div class="replies">
Example #19
0
 /**
  * Set the content to parse
  *
  * @param $value
  */
 public function setContent($value)
 {
     $converter = new CommonMarkConverter();
     $this->content = new Crawler($converter->convertToHtml($value));
 }
Example #20
0
 /**
  * Convert Markdown to HTML
  * @param  string $text Markdown text
  * @return string       Converted HTML
  */
 public function toHTML($text)
 {
     $converter = new CommonMarkConverter();
     $text = $converter->convertToHtml($text);
     return $text;
 }
 /**
  * Prepare array to fill the conversation model.
  *
  * @return array
  */
 public function prepareDate()
 {
     return ['user_id' => Auth::User()->id, 'title' => $this->title, 'topic_id' => $this->topic_id, 'message' => $this->converter->convertToHtml($this->message), 'slug' => Slug::generateUniqueSlug($this->title, 'conversations')];
 }
 /**
  * Prepare an array to fill the reply model.
  *
  * @return array
  */
 public function prepareData()
 {
     return ['user_id' => auth()->User()->id, 'conversation_id' => $this->conversation_id, 'message' => $this->converter->convertToHtml($this->message)];
 }
Example #23
0
 /**
  * Converts CommonMark to HTML.
  *
  * @param string $commonMark
  * @return string 
  * @api 
  * @static 
  */
 public static function convertToHtml($commonMark)
 {
     //Method inherited from \League\CommonMark\Converter
     return \League\CommonMark\CommonMarkConverter::convertToHtml($commonMark);
 }
<?php

// @codingStandardsIgnoreFile
use League\CommonMark\CommonMarkConverter;
use PhlyBlog\AuthorEntity;
use PhlyBlog\EntryEntity;
$author = new AuthorEntity();
$author->setId('matthew');
$author->setName("Matthew Weier O'Phinney");
$author->setEmail('*****@*****.**');
$author->setUrl('http://mwop.net/');
$markdown = new CommonMarkConverter();
$post = new EntryEntity();
$post->setTitle('Expressive 1.0.0RC3 Released!');
$post->setAuthor($author);
$post->setDraft(false);
$post->setPublic(true);
$post->setCreated(new DateTime('2015-12-07 13:00', new DateTimezone('America/Chicago')));
$post->setUpdated(new DateTime('2015-12-07 13:00', new DateTimezone('America/Chicago')));
$body = <<<'EOS'
The Zend Framework community is pleased to announce the immediate availability of Expressive 1.0.0rc3!

You can install it using [Composer](https://getcomposer.org), using the `create-project` command:

```bash
$ composer create-project zendframework/zend-expressive-skeleton:1.0.0rc3@rc expressive
```

If you're already using Expressive, read below for how to update your application!
EOS;
$post->setBody($markdown->convertToHtml($body));
Example #25
0
 public function render()
 {
     $converter = new CommonMarkConverter();
     $contents = $this->backend->getFileContents($this->name);
     return $converter->convertToHtml($contents);
 }
Example #26
0
 /**
  * Gather changes for the new version.
  *
  * @return array
  */
 protected function gatherChanges()
 {
     $converter = new CommonMarkConverter();
     $changes = [];
     foreach ($this->changelog->getSections() as $section) {
         $sectionChanges = [];
         // Prepare question
         $question = new Question('Add something to "' . ucfirst($section) . '"');
         $question->setValidator(function ($value) {
             return $value ?: 'NOPE';
         });
         // Gather changes from user
         while ($change = $this->output->askQuestion($question)) {
             if ($change === 'NOPE') {
                 break;
             }
             $sectionChanges[] = $converter->convertToHtml($change);
         }
         if ($sectionChanges) {
             $changes[$section] = $sectionChanges;
         }
     }
     return $changes;
 }
 /**
  * Converts CommonMark to HTML.
  *
  * @param string $commonMark
  * @return string 
  * @api 
  * @static 
  */
 public static function convertToHtml($commonMark)
 {
     return \League\CommonMark\CommonMarkConverter::convertToHtml($commonMark);
 }
 /**
  * Convert the Description into HTML.
  *
  * @return string
  */
 public function getDescriptionAttribute($value)
 {
     $c = new CommonMarkConverter();
     return $c->convertToHtml($value);
 }
 /**
  * Get the evaluated contents of the view.
  *
  * @param string $path
  * @param array  $data
  *
  * @return string
  */
 public function get($path, array $data = [])
 {
     $contents = parent::get($path, $data);
     return $this->markdown->convertToHtml($contents);
 }
Example #30
0
 /**
  * Render a custom page
  *
  * @param array $latest
  * @return string
  */
 protected function render(array $latest) : string
 {
     $state = State::instance();
     switch ($latest['formatting']) {
         case 'Markdown':
             $md = new CommonMarkConverter();
             if (empty($latest['raw'])) {
                 $state->HTMLPurifier->purify($md->convertToHtml($latest['body']));
             }
             return $md->convertToHtml($latest['body']);
         case 'RST':
             $rst = (new RSTParser())->setIncludePolicy(false);
             if (empty($latest['raw'])) {
                 $state->HTMLPurifier->purify((string) $rst->parse($latest['body']));
             }
             return (string) $rst->parse($latest['body']);
         case 'HTML':
         case 'Rich Text':
         default:
             if (empty($latest['raw'])) {
                 return $state->HTMLPurifier->purify($latest['body']);
             }
             return $latest['body'];
     }
 }