Replace SimpleMDE with custom Markdown editor

This commit is contained in:
Frederic Guillot
2016-11-13 22:51:59 -05:00
parent 527a1677a0
commit ebb6b2827d
22 changed files with 1057 additions and 498 deletions

View File

@@ -181,6 +181,44 @@ class FormHelper extends Base
return $html;
}
/**
* Display a markdown editor
*
* @access public
* @param string $name Field name
* @param array $values Form values
* @param array $errors Form errors
* @param array $attributes
* @return string
*/
public function textEditor($name, $values = array(), array $errors = array(), array $attributes = array())
{
if (! isset($attributes['css'])) {
$attributes['css'] = '';
}
$attrHtml = '';
$attributes['css'] .= $this->errorClass($errors, $name);
foreach ($attributes as $attribute => $value) {
$attrHtml .= sprintf(' %s="%s"', $attribute, $value);
}
$html = sprintf(
'<texteditor name="%s" text="%s" label-preview="%s" label-write="%s" placeholder="%s" %s></texteditor>',
$name,
isset($values[$name]) ? $this->helper->text->e($values[$name]) : '',
t('Preview'),
t('Write'),
t('Write your text in Markdown'),
$attrHtml
);
$html .= $this->errorList($errors, $name);
return $html;
}
/**
* Display file field
*

View File

@@ -50,20 +50,7 @@ class TaskHelper extends Base
public function selectDescription(array $values, array $errors)
{
$html = $this->helper->form->label(t('Description'), 'description');
$html .= '<div class="markdown-editor-container">';
$html .= $this->helper->form->textarea(
'description',
$values,
$errors,
array(
'placeholder="'.t('Leave a description').'"',
'tabindex="2"',
'data-mention-search-url="'.$this->helper->url->href('UserAjaxController', 'mention', array('project_id' => $values['project_id'])).'"'
),
'markdown-editor'
);
$html .= '</div>';
$html .= $this->helper->form->textEditor('description', $values, $errors, array('tabindex' => 2));
return $html;
}