Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Added use_safe_mode configuration value
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeryther committed Nov 16, 2021
1 parent 24c9ea5 commit 38eb884
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/DependencyInjection/MarkdownWikiBundleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function getConfigTreeBuilder(): TreeBuilder {
$root
->addDefaultsIfNotSet()
->children()
->append($this->createSourceDirectoryNode());
->append($this->createSourceDirectoryNode())
->append($this->createSafeModeNode());

return $treeBuilder;
}
Expand All @@ -50,4 +51,11 @@ protected function createSourceDirectoryNode(): NodeDefinition {
->info("The path to the directory holding the source markdown files.")
->defaultValue("%kernel.project_dir%/wiki/");
}

protected function createSafeModeNode(): NodeDefinition {
return $this->builder
->booleanNode("use_safe_mode")
->info("Whether to use parse down safe mode.")
->defaultValue(false);
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/MarkdownWikiBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public function load(array $configs, ContainerBuilder $container) {
protected function addImporterDefinitionArguments(ContainerBuilder $container, array $config) {
$definition = $container->getDefinition("markdownwiki.importer");
$definition->setArgument("\$sourceDirectory", $config["source_directory"]);
$definition->setArgument("\$useSafeMode", $config["use_safe_mode"]);
}
}
1 change: 1 addition & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
markdownwiki.importer:
class: Gigadrive\Bundle\MarkdownWikiBundle\Service\MarkdownWikiImporter
arguments:
- ''
- ''
- '@markdownwiki.parser'
- '@logger'
Expand Down
3 changes: 2 additions & 1 deletion src/Service/MarkdownWikiImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class MarkdownWikiImporter {
public function __construct(
protected string $sourceDirectory,
protected bool $useSafeMode,
protected MarkdownWikiParser $parser,
protected LoggerInterface $logger
) {
Expand Down Expand Up @@ -103,7 +104,7 @@ protected function readFilesInDirectory(string $path): ?MarkdownWikiPage {
if ($language === "content") $language = "en"; // backwards compatibility

$content[$language] = $this->parser
->setSafeMode(true)
->setSafeMode($this->useSafeMode)
->text($file->getContents());
} else {
$language = $file->getFilenameWithoutExtension();
Expand Down

0 comments on commit 38eb884

Please sign in to comment.