diff --git a/config/vufind/markdown.ini b/config/vufind/markdown.ini new file mode 100644 index 0000000000000000000000000000000000000000..59e22a2fb63b413111e76e21a62d5f85da7df986 --- /dev/null +++ b/config/vufind/markdown.ini @@ -0,0 +1,32 @@ +; This file could be used to define configuration of markdown to HTML converter. +; More detailed configuration documentation could be found here: +; https://github.com/thephpleague/commonmark/blob/master/docs/1.0/configuration.md +[Markdown] +; How to handle HTML input. Options are: strip, allow, escape. Defaults to strip +;html_input = allow +; Remove risky link and image URLs by setting this to false. Defaults to false +;allow_unsafe_links = true +; String to use for separating renderer block elements +;renderer[block_separator] = "\n" +; String to use for separating inner block contents +;renderer[inner_separator] = "\n" +; String to use for rendering soft breaks +;renderer[inner_separator] = "\n" +; Enable or disable <em> parsing. Enabled by default +;enable_em = false +; Enable or disable <strong> parsing. Enabled by default +;enable_strong = false +; Enable or disable parsing of '*' for emphasis. Enabled by default +;use_asterisk = false +; Enable or disable parsing of '_' for emphasis. Enabled by default +;use_underscore = false +; Array of characters that can be used to indicated a bulleted list (default: +; ["-", "*", "+"]) +;unordered_list_markers[] = "-" +;unordered_list_markers[] = "*" +;unordered_list_markers[] = "+" +; The maximum nesting level for blocks (default: infinite). Setting this to a +; positive integer can help protect against long parse times and/or segfaults if +; blocks are too deeply-nested. +;max_nesting_level = 10 + diff --git a/module/VuFind/src/VuFind/Service/MarkdownFactory.php b/module/VuFind/src/VuFind/Service/MarkdownFactory.php index d95edf3ffbf45ded07ad1abc7b83b01144cc2788..428ff5fa6e87fcaeb8ba345020dc920b22653928 100644 --- a/module/VuFind/src/VuFind/Service/MarkdownFactory.php +++ b/module/VuFind/src/VuFind/Service/MarkdownFactory.php @@ -63,10 +63,28 @@ class MarkdownFactory implements FactoryInterface public function __invoke( ContainerInterface $container, $requestedName, array $options = null ) { + $config = $container->get(\VuFind\Config\PluginManager::class) + ->get('markdown')->Markdown; return new GithubFlavoredMarkdownConverter( [ - 'html_input' => 'strip', - 'allow_unsafe_links' => false, + 'html_input' => $config->html_input ?? 'strip', + 'allow_unsafe_links' => $config->allow_unsafe_links ?? false, + 'enable_em' => $config->enable_em ?? true, + 'enable_strong' => $config->enable_strong ?? true, + 'use_asterisk' => $config->use_asterisk ?? true, + 'use_underscore' => $config->use_underscore ?? true, + 'unordered_list_markers' => isset($config->unordered_list_markers) + && $config->unordered_list_markers instanceof \ArrayAccess + ? $config->unordered_list_markers->toArray() + : ['-', '*', '+'], + 'max_nesting_level' => $config->max_nesting_level ?? \INF, + 'renderer' => [ + 'block_separator' + => $config->renderer['block_separator'] ?? "\n", + 'inner_separator' + => $config->renderer['inner_separator'] ?? "\n", + 'soft_break' => $config->renderer['soft_break'] ?? "\n", + ], ] ); }