Class humhub\modules\content\widgets\richtext\ProsemirrorRichText

Inheritancehumhub\modules\content\widgets\richtext\ProsemirrorRichText » humhub\modules\content\widgets\richtext\AbstractRichText » humhub\widgets\JsWidget » humhub\components\Widget » yii\base\Widget
Available since version1.3

The ProsemirrorRichText is a Prosemirror and Markdown-it based rich text implementation.

This rich text is a pure markdown based rich text enhanced with some additional features and markdown plugins.

In order to stay compatible with the legacy rich text content, this rich text contains some pre-processing logic on the server side, which can be deactivated if not required by means of the richtextCompatMode setting of the content module.

Note that this rich text, when in edit mode, just outputs an invisible div with pure markdown content, which will be interpreted by the related ProsemirrorRichTextEditor.

This rich text implementation supports all features as $preset, the \humhub\modules\content\widgets\richtext\includes and \humhub\modules\content\widgets\richtext\excludes of plugins and is extensible through additional javascript plugins.

Note that the plugin settings as $preset, \humhub\modules\content\widgets\richtext\includes, \humhub\modules\content\widgets\richtext\excludes, $pluginOptions have to be set for the editor as well as for the rich text output widget.

Beside the default (GFM based) markdown-it syntax, the following plugins are available:

anchors

If enabled will add anchors to heading elements. This plugin is disabled by default and can be enabled as follows:

RichText::output($text, [
    'preset' => 'myPreset',
    'pluginOptions' => [
        'anchors' => true
    ]
]);

// or with specific settings
RichText::output($text, [
    'preset' => 'myPreset',
    'pluginOptions' => [
        'anchors' => ['permalink' => true]
    ]
]);

See markdown-it-anchor for more settings.

clipboard

Allows pasting of raw markdown content into the richtext editor.

emoji

twemoji and markdown-it-emoji based emojies

fullscreen

Adds a enlarge/shrink button to the rich text editor.

mention

Markdown link extension for mentionings in the form of .

oembed

Enables scanning and replacement of pasted oembed links in form of link extensions

placeholder

Text placeholder for the editor input

strikethrough

Markdown strikethrough formatting.

table

Simple Markdown table support.

upload

File upload support.

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$container string Html container element. humhub\widgets\JsWidget
$content string Html content. humhub\widgets\JsWidget
$edit boolean Enables the edit rendering mode humhub\modules\content\widgets\richtext\AbstractRichText
$encode boolean humhub\modules\content\widgets\richtext\AbstractRichText
$events [] humhub\widgets\JsWidget
$exclude array Can be used to exclude specific plugins from the set of defaults (preset) humhub\modules\content\widgets\richtext\AbstractRichText
$fadeIn boolean|string|integer humhub\widgets\JsWidget
$id string humhub\widgets\JsWidget
$include array Can be used to explicitly include specific plugins in addition to the set of defaults (preset) humhub\modules\content\widgets\richtext\AbstractRichText
$init mixed humhub\modules\content\widgets\richtext\AbstractRichText
$jsWidget string humhub\modules\content\widgets\richtext\ProsemirrorRichText
$markdown boolean Defines if this rich text is also used as client side markdown text. humhub\modules\content\widgets\richtext\AbstractRichText
$maxLength integer Setting used to truncate the rich text content, usually related to $minimal mode and used for previews humhub\modules\content\widgets\richtext\AbstractRichText
$maxOembed integer Defines the maximum amount of oembeds allowed in a single richtext humhub\modules\content\widgets\richtext\ProsemirrorRichText
$minimal boolean Enables the minimal rendering mode used for example for previews, this mode should take the \humhub\modules\content\widgets\richtext\maxLenght setting into account for truncating the preview content. humhub\modules\content\widgets\richtext\AbstractRichText
$options humhub\widgets\JsWidget
$pluginOptions array Rich text plugin settings. humhub\modules\content\widgets\richtext\AbstractRichText
$preset string Defines a preset of rich text features and settings humhub\modules\content\widgets\richtext\AbstractRichText
$record mixed Can be used to identify the related record humhub\modules\content\widgets\richtext\AbstractRichText
$render boolean If set to false this widget won't be rendered humhub\components\Widget
$text string Text to display humhub\modules\content\widgets\richtext\AbstractRichText
$visible boolean humhub\widgets\JsWidget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
buildOembedOutput() humhub\modules\content\widgets\richtext\ProsemirrorRichText
editorWidget() humhub\modules\content\widgets\richtext\AbstractRichText
getData() Returns an array of data-* attributes to configure your clientside js widget. humhub\modules\content\widgets\richtext\AbstractRichText
getEditorClass() humhub\modules\content\widgets\richtext\AbstractRichText
getId() Returns the html id of this widget, if no id is set this function will generate an id if $autoGenerate is set to true (default). humhub\widgets\JsWidget
getProcessor() humhub\modules\content\widgets\richtext\AbstractRichText
getProcessorClass() humhub\modules\content\widgets\richtext\AbstractRichText
init() humhub\modules\content\widgets\richtext\ProsemirrorRichText
isCompatibilityMode() Checks if the compatibility mode is enabled. humhub\modules\content\widgets\richtext\ProsemirrorRichText
output() Renders the given text by means of the given config. humhub\modules\content\widgets\richtext\AbstractRichText
parseMentionings() Parses the given text for mentionings and replaces them with possibly updated values (e.g. name). humhub\modules\content\widgets\richtext\ProsemirrorRichText
postProcess() Used for the post-processing of the rich text, normally called within humhub\modules\content\components\ContentActiveRecord::afterSave() of the related humhub\modules\content\components\ContentActiveRecord. humhub\modules\content\widgets\richtext\AbstractRichText
preview() Renders the given text in minimal render mode truncated by the maxLength parameter. humhub\modules\content\widgets\richtext\AbstractRichText
process() Process is a wrapper for the run method humhub\components\Widget
replaceLinkExtension() Can be used to scan and replace link extensions of the form in which the actual meaning of the placeholders is up to the extension itself. humhub\modules\content\widgets\richtext\ProsemirrorRichText
run() Default implementation of JsWidget. humhub\modules\content\widgets\richtext\ProsemirrorRichText
scanLinkExtension() Can be used to scan for link extensions of the form in which the actual meaning of the placeholders is up to the extension itself. humhub\modules\content\widgets\richtext\ProsemirrorRichText
setDefaultOptions() Sets some default data options required by all widgets as the widget implementation and the widget evetns and initialization trigger. humhub\widgets\JsWidget
widget() Creates a widget instance and runs it. humhub\components\Widget

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_BEFORE_OUTPUT \humhub\modules\search\events\ParameterEvent With parameter 'output' humhub\modules\content\widgets\richtext\AbstractRichText
EVENT_CREATE humhub\libs\WidgetCreateEvent An event raised before creating a widget. humhub\components\Widget
EVENT_POST_PROCESS humhub\components\Event An event raised after the post-process phase of the rich text. humhub\modules\content\widgets\richtext\AbstractRichText

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
PRESET_DOCUMENT 'document' humhub\modules\content\widgets\richtext\AbstractRichText

Property Details

$editorClass protected static property

humhub\modules\content\widgets\richtext\AbstractRichTextEditor subclass, used for rendering the editor widget.

protected static string $editorClass = \humhub\modules\content\widgets\richtext\ProsemirrorRichTextEditor::class
$jsWidget public property
public string $jsWidget 'ui.richtext.prosemirror.RichText'
$maxOembed public static property

Defines the maximum amount of oembeds allowed in a single richtext

public static integer $maxOembed 10
$processorClass protected static property

humhub\modules\content\widgets\richtext\AbstractRichTextProcessor subclass, used for post-processing the rich text content

protected static string $processorClass = \humhub\modules\content\widgets\richtext\ProsemirrorRichTextProcessor::class

Method Details

buildOembedOutput() public method

public string buildOembedOutput ( )
return string

Html extension holding the actual oembed dom nodes which will be embedded into the rich text

getLinkExtensionPattern() protected static method

protected static string getLinkExtensionPattern ( $extension '[a-zA-Z]+' )
$extension string

The extension to parse, if not set all extensions are included

return string

The regex pattern for a given extension or all extension if no specific extension string is given

init() public method

public void init ( )
isCompatibilityMode() public method

Checks if the compatibility mode is enabled.

The compatibility mode is only required, if old content is present and won't be activated for new installations.

public boolean isCompatibilityMode ( )
parseMentionings() public static method

Parses the given text for mentionings and replaces them with possibly updated values (e.g. name).

public static mixed parseMentionings ( $text, $edit false )
$text

String rich text content to parse

$edit

Bool if not in edit mode deleted or inactive users will be rendered differently

parseOutput() protected method

protected void parseOutput ( )
renderMinimal() protected method

protected string renderMinimal ( )
return string

Truncated and stripped text

replaceLinkExtension() public static method

Can be used to scan and replace link extensions of the form in which the actual meaning of the placeholders is up to the extension itself.

public static mixed replaceLinkExtension ( $text, $extension null, $callback )
$text

String rich text content to parse

$extension

String|null extension string if not given all extension types will be included

$callback
run() public method

Default implementation of JsWidget.

This will render a widget html element specified by $container and $content and the given $options/$event attributes. This function should be overwritten for widgets with a more complex rendering.

public string run ( )
scanLinkExtension() public static method

Can be used to scan for link extensions of the form in which the actual meaning of the placeholders is up to the extension itself.

public static array scanLinkExtension ( $text, $extension null )
$text

String rich text content to parse

$extension

String|null extension string if not given all extension types will be included

toUTF8Emoji() protected method

protected void toUTF8Emoji ( $text )
$text