class PhpMarkdownExtra in Markdown 8.2
Support for PHP Markdown Extra by Michel Fortin.
@MarkdownAllowedHtml( id = "php-markdown-extra", ) @MarkdownParser( id = "php-markdown-extra", label = @Translation("PHP Markdown Extra"), description = @Translation("Parser for Markdown with extra functionality."), weight = 30, libraries = { @ComposerPackage( id = "michelf/php-markdown", object = "\Michelf\MarkdownExtra", url = "https://michelf.ca/projects/php-markdown/extra", ), } ) @method \Michelf\MarkdownExtra getPhpMarkdown() @noinspection PhpFullyQualifiedNameUsageInspection
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\markdown\Plugin\Markdown\AnnotatedPluginBase implements AnnotatedPluginInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\markdown\Plugin\Markdown\InstallablePluginBase implements InstallablePluginInterface uses PluginDependencyTrait, MoreInfoTrait
- class \Drupal\markdown\Plugin\Markdown\BaseParser implements PluginFormInterface, ParserInterface, FilterAwareInterface uses RefinableCacheableDependencyTrait, EnabledPluginTrait, FilterAwareTrait, SettingsTrait
- class \Drupal\markdown\Plugin\Markdown\PhpMarkdown\PhpMarkdown implements AllowedHtmlInterface, SettingsInterface uses ParserAllowedHtmlTrait
- class \Drupal\markdown\Plugin\Markdown\PhpMarkdown\PhpMarkdownExtra implements AllowedHtmlInterface
- class \Drupal\markdown\Plugin\Markdown\PhpMarkdown\PhpMarkdown implements AllowedHtmlInterface, SettingsInterface uses ParserAllowedHtmlTrait
- class \Drupal\markdown\Plugin\Markdown\BaseParser implements PluginFormInterface, ParserInterface, FilterAwareInterface uses RefinableCacheableDependencyTrait, EnabledPluginTrait, FilterAwareTrait, SettingsTrait
- class \Drupal\markdown\Plugin\Markdown\InstallablePluginBase implements InstallablePluginInterface uses PluginDependencyTrait, MoreInfoTrait
- class \Drupal\markdown\Plugin\Markdown\AnnotatedPluginBase implements AnnotatedPluginInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PhpMarkdownExtra
File
- src/
Plugin/ Markdown/ PhpMarkdown/ PhpMarkdownExtra.php, line 33
Namespace
Drupal\markdown\Plugin\Markdown\PhpMarkdownView source
class PhpMarkdownExtra extends PhpMarkdown implements AllowedHtmlInterface {
/**
* {@inheritdoc}
*/
protected static $phpMarkdownClass = '\\Michelf\\MarkdownExtra';
/**
* {@inheritdoc}
*/
public static function defaultSettings($pluginDefinition) {
/* @var \Drupal\markdown\Annotation\InstallablePlugin $pluginDefinition */
return [
'code_attr_on_pre' => FALSE,
'code_class_prefix' => '',
'enhanced_ordered_list' => TRUE,
'fn_backlink_class' => 'footnote-backref',
'fn_backlink_html' => '↩︎',
'fn_backlink_label' => '',
'fn_backlink_title' => '',
'fn_id_prefix' => '',
'fn_link_class' => 'footnote-ref',
'fn_link_title' => '',
'hashtag_protection' => FALSE,
'omit_footnotes' => FALSE,
'predef_abbr' => [],
'table_align_class_tmpl' => '',
] + parent::defaultSettings($pluginDefinition);
}
/**
* {@inheritdoc}
*/
public function allowedHtmlTags(ParserInterface $parser, ActiveTheme $activeTheme = NULL) {
return [
'*' => [
'role' => TRUE,
],
'abbr' => [],
'caption' => [],
'col' => [
'span' => TRUE,
],
'colgroup' => [
'span' => TRUE,
],
'dd' => [],
'dl' => [],
'dt' => [],
'sup' => [],
'table' => [],
'tbody' => [],
'td' => [
'colspan' => TRUE,
'headers' => TRUE,
'rowspan' => TRUE,
],
'tfoot' => [],
'th' => [
'abbr' => TRUE,
'colspan' => TRUE,
'headers' => TRUE,
'rowspan' => TRUE,
'scope' => TRUE,
],
'thead' => [],
'tr' => [],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $element, FormStateInterface $form_state) {
/** @var \Drupal\markdown\Form\SubformStateInterface $form_state */
$element = parent::buildConfigurationForm($element, $form_state);
$element += $this
->createSettingElement('code_attr_on_pre', [
'#type' => 'checkbox',
'#title' => $this
->t('Code Attribute on <code><pre></code>'),
'#description' => $this
->t('When enabled, attributes for code blocks will go on the <code><pre></code> tag; otherwise they will be placed on the <code><code></code> tag.'),
], $form_state);
$element += $this
->createSettingElement('code_class_prefix', [
'#type' => 'textfield',
'#title' => $this
->t('Code Class Prefix'),
'#description' => $this
->t('An optional prefix for the class names associated with fenced code blocks.'),
], $form_state);
$element += $this
->createSettingElement('hashtag_protection', [
'#type' => 'checkbox',
'#title' => $this
->t('Hashtag Protection'),
'#description' => $this
->t('When enabled, prevents ATX-style headers with no space after the initial hash from being interpreted as headers.'),
], $form_state);
$element += $this
->createSettingElement('table_align_class_tmpl', [
'#type' => 'textfield',
'#title' => $this
->t('Table Align Class Template'),
'#description' => $this
->t('The class attribute determining the alignment of table cells. The default value, which is empty, will cause the align attribute to be used instead of class to specify the alignment.<br>If not empty, the align attribute will not appear. Instead, the value for the class attribute will be determined by replacing any occurrence of <code>%%</code> within the string by left, center, or right. For instance, if set to <code>go-%%</code> and the cell is right-aligned, the result will be: <code>class="go-right"</code>.'),
], $form_state);
// Footnotes.
$footnote_variable = $this
->t('Occurrences of <code>^^</code> in the string will be replaced by the corresponding footnote number in the HTML output. Occurrences of <code>%%</code> will be replaced by a number for the reference (footnotes can have multiple references).');
$element['footnotes'] = [
'#weight' => 9,
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Footnotes'),
'#parents' => $form_state
->createParents(),
];
$element['footnotes'] += $this
->createSettingElement('fn_backlink_class', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Class'),
'#description' => $this
->t('The <code>class</code> attribute to use for footnotes backlinks.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_html', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink HTML'),
'#description' => $this
->t('HTML content for a footnote backlink. The <code>&#xFE0E;</code> suffix in the default value is there to avoid the curled arrow being rendered as an emoji on mobile devices, but it might cause an unrecognized character to appear on older browsers.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_label', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Label'),
'#description' => $this
->t('Add an accessibility label for backlinks (the <code>aria-label</code> attribute), when you want it to be different from the title attribute.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_title', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Title'),
'#description' => $this
->t('An optional <code>title</code> attribute for footnotes links and backlinks. Browsers usually show this as a tooltip when the mouse is over the link.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_id_prefix', [
'#type' => 'textfield',
'#title' => $this
->t('ID Prefix'),
'#description' => $this
->t('A prefix for the <code>id</code> attributes generated by footnotes. This is useful if you have multiple markdown documents displayed inside one HTML document to avoid footnote ids to clash each other.'),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_link_class', [
'#type' => 'textfield',
'#title' => $this
->t('Link Class'),
'#description' => $this
->t('The class attribute to use for footnotes links.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_link_title', [
'#type' => 'textfield',
'#title' => $this
->t('Link Title'),
'#description' => $this
->t('An optional <code>title</code> attribute for footnotes links. Browsers usually show this as a tooltip when the mouse is over the link.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('omit_footnotes', [
'#type' => 'checkbox',
'#title' => $this
->t('Omit Footnotes'),
'#description' => $this
->t('When enabled, footnotes are not appended at the end of the generated HTML and the <code>footnotes_assembled</code> variable on the parser object (see <code>hook_markdown_html_alter()</code>) will contain the HTML for the footnote list, allowing footnotes to be moved somewhere else on the page.<br>NOTE: when placing the content of footnotes_assembled on the page, consider adding the attribute <code>role="doc-endnotes"</code> to the HTML element that will enclose the list of footnotes so they are reachable to accessibility tools the same way they would be with the default HTML output.'),
], $form_state);
// Predefined.
$element['predefined'] += $this
->createSettingElement('predef_abbr', [
'#weight' => -1,
'#type' => 'textarea',
'#title' => $this
->t('Abbreviations'),
'#description' => $this
->t('A predefined key|value pipe list of abbreviations, where the key is the value left of a pipe (<code>|</code>) and the abbreviation is to the right of it; only one key|value pipe item per line.<br>For example, adding the following <code>html|Hyper Text Markup Language</code> allows the following in markdown <code>*[html]</code> to be parsed and replaced with <code><abbr title="Hyper Text Markup Language">HTML</abbr></code>.'),
], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalize');
return $element;
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
$configuration = parent::getConfiguration();
// Normalize settings from a key|value string into an associative array.
foreach ([
'predef_abbr',
] as $name) {
if (isset($configuration['settings'][$name])) {
$configuration['settings'][$name] = KeyValuePipeConverter::normalize($configuration['settings'][$name]);
}
}
return $configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
// Normalize settings from a key|value string into an associative array.
foreach ([
'predef_abbr',
] as $name) {
if (isset($configuration['settings'][$name])) {
$configuration['settings'][$name] = KeyValuePipeConverter::normalize($configuration['settings'][$name]);
}
}
return parent::setConfiguration($configuration);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnnotatedPluginBase:: |
protected | property | The original plugin_id that was called, not a fallback identifier. | |
AnnotatedPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the configuration overrides for the plugin. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the description of the plugin, if set. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Retrieves the original plugin identifier. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Returns the provider (extension name) of the plugin. Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Returns the weight of the plugin (used for sorting). Overrides AnnotatedPluginInterface:: |
|
AnnotatedPluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
AnnotatedPluginBase:: |
public | function | ||
BaseParser:: |
protected | property | ||
BaseParser:: |
public | function |
Overrides RenderStrategyInterface:: |
|
BaseParser:: |
public | function |
Retrieves the allowed HTML plugins relevant to the object. Overrides RenderStrategyInterface:: |
|
BaseParser:: |
protected | function |
Determines the configuration sort order by weight. Overrides InstallablePluginBase:: |
1 |
BaseParser:: |
protected | function | Builds context around a markdown parser's hierarchy filter format chain. | |
BaseParser:: |
public | function |
Retrieves the custom (user provided) allowed HTML. Overrides RenderStrategyInterface:: |
|
BaseParser:: |
public | function |
Retrieves the render strategy to use. Overrides RenderStrategyInterface:: |
|
BaseParser:: |
public | function |
Parses markdown into HTML. Overrides ParserInterface:: |
|
BaseParser:: |
protected | function | A description explaining why a setting is disabled due to render strategy. | |
BaseParser:: |
protected | function | Adds a conditional state for a setting element based on render strategy. | |
BaseParser:: |
public static | function | Validates parser settings. | |
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
public | function | 3 | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
EnabledPluginTrait:: |
public | function | 1 | |
EnabledPluginTrait:: |
public | function | ||
FilterAwareTrait:: |
protected | property | A Filter plugin. | |
FilterAwareTrait:: |
public | function | ||
FilterAwareTrait:: |
public | function | ||
InstallablePluginBase:: |
protected | property | The config for this plugin. | |
InstallablePluginBase:: |
public | function |
Builds a display for a library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Builds a display status based on the current state of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the config instance for this plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
protected static | function | ||
InstallablePluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides AnnotatedPluginBase:: |
1 |
InstallablePluginBase:: |
public | function | Retrieves available installs. | |
InstallablePluginBase:: |
protected | function | Returns the configuration name for the plugin. | |
InstallablePluginBase:: |
public | function | Retrieves the container. | |
InstallablePluginBase:: |
public | function |
Retrieves the deprecation message, if any. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the experimental message. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the composer package name of the installable library, if any. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the installed library used by the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Displays the human-readable label of the plugin. Overrides AnnotatedPluginBase:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the plugin as a link using its label and URL. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
@TODO: Refactor to use variadic parameters. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the class name of the object defined by the installed library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
protected | function | 1 | |
InstallablePluginBase:: |
public | function |
Retrieves the preferred library of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the configuration for the plugin, but sorted. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Retrieves the URL of the plugin, if set. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
The current version of the plugin. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function | ||
InstallablePluginBase:: |
public | function |
Indicates whether plugin has multiple installs to check. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the plugin is installed. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the plugin is using the preferred library. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the preferred library is installed. Overrides InstallablePluginInterface:: |
|
InstallablePluginBase:: |
public | function |
Indicates whether the plugin should be shown in the UI. Overrides InstallablePluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MoreInfoTrait:: |
protected | function | Appends existing content with a "More Info" link. | |
PhpMarkdown:: |
protected | property | The PHP Markdown instance. | |
PhpMarkdown:: |
protected | function |
Converts Markdown into HTML. Overrides BaseParser:: |
|
PhpMarkdown:: |
public | function | Retrieves the PHP Markdown parser. | |
PhpMarkdown:: |
public | function |
Indicates whether the setting exists. Overrides SettingsTrait:: |
|
PhpMarkdown:: |
public | function |
Overrides DependencySerializationTrait:: |
|
PhpMarkdownExtra:: |
protected static | property |
The PHP Markdown class to use. Overrides PhpMarkdown:: |
|
PhpMarkdownExtra:: |
public | function |
Retrieves the allowed HTML tags. Overrides ParserAllowedHtmlTrait:: |
|
PhpMarkdownExtra:: |
public | function |
Form constructor. Overrides PhpMarkdown:: |
|
PhpMarkdownExtra:: |
public static | function |
Provides the default settings for the plugin. Overrides PhpMarkdown:: |
|
PhpMarkdownExtra:: |
public | function |
Gets this plugin's configuration. Overrides PhpMarkdown:: |
|
PhpMarkdownExtra:: |
public | function |
Sets the configuration for this plugin instance. Overrides PhpMarkdown:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | |
PluginDependencyTrait:: |
protected | function | Calculates and returns dependencies of a specific plugin instance. Aliased as: getPluginDependenciesTrait | |
PluginDependencyTrait:: |
protected | function | Wraps the module handler. | |
PluginDependencyTrait:: |
protected | function | Wraps the theme handler. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RendererTrait:: |
protected static | property | The Renderer service. | |
RendererTrait:: |
protected | function | Retrieves the Renderer service. | |
RenderStrategyInterface:: |
constant | The documentation URL for further explaining render strategies. | ||
RenderStrategyInterface:: |
constant | Strategy used to escape HTML input prior to parsing markdown. | ||
RenderStrategyInterface:: |
constant | Strategy used to filter the output of parsed markdown. | ||
RenderStrategyInterface:: |
constant | The URL for explaining Markdown and XSS; render strategies. | ||
RenderStrategyInterface:: |
constant | No render strategy. | ||
RenderStrategyInterface:: |
constant | Strategy used to remove HTML input prior to parsing markdown. | ||
SettingsTrait:: |
protected | function | Creates a setting element. | |
SettingsTrait:: |
public | function | ||
SettingsTrait:: |
public | function | ||
SettingsTrait:: |
public | function | ||
SettingsTrait:: |
public | function | ||
SettingsTrait:: |
public | function | 6 | |
SettingsTrait:: |
public | function | ||
SettingsTrait:: |
public | function | 2 | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |