Browse Source

Render bio with markdown in ProfileBlock

Ref. #6
master
Chimo 2 years ago
parent
commit
91f711fbd6
2 changed files with 73 additions and 1 deletions
  1. 12
    1
      MarkdownPlugin.php
  2. 61
    0
      lib/MarkdownProfileBlock.php

+ 12
- 1
MarkdownPlugin.php View File

@@ -4,9 +4,11 @@ if (!defined('GNUSOCIAL')) {
exit(1);
}

require __DIR__ . '/lib/MarkdownProfileBlock.php';

class MarkdownPlugin extends Plugin
{
const VERSION = '0.0.9';
const VERSION = '0.1.0';
const NAME_SPACE = 'markdown'; // 'namespace' is a reserved keyword

function initialize()
@@ -149,6 +151,15 @@ class MarkdownPlugin extends Plugin
return common_purify($this->fix_whitespace($rendered));
}

function onStartShowAccountProfileBlock($action, $profile)
{
$markdownProfile = new MarkdownProfileBlock($action, $profile);

$markdownProfile->show();

return false;
}

function onStartNoticeSave($notice)
{
// Only run this on local notices

+ 61
- 0
lib/MarkdownProfileBlock.php View File

@@ -0,0 +1,61 @@
<?php

if (!defined('GNUSOCIAL')) {
exit(1);
}

class MarkdownProfileBlock extends ProfileBlock
{
protected $profile;

function __construct(Action $out, Profile $profile)
{
parent::__construct($out);

$this->profile = $profile;
}

function name()
{
return $this->profile->getBestName();
}

function url()
{
return $this->profile->profileurl;
}

function location()
{
return $this->profile->location;
}

function homepage()
{
return $this->profile->homepage;
}

function description()
{
return $this->profile->bio;
}

function showDescription()
{
$description = $this->description();

$markdown_parser = new \Michelf\Markdown();
$rendered = $markdown_parser->defaultTransform($description);
$safe = common_purify($rendered);

if (!empty($description)) {
$this->out->elementStart(
'div',
'profile_block_description'
);
$this->out->raw($safe);
$this->out->elementEnd('div');
}
}
}


Loading…
Cancel
Save