Documents in Markdown: a document can be written in Markdown with Write and Preview or in the rich text editor and switched either way, pictures pasted or dropped into the Markdown are kept as files, New Document starts in the way last used, Import Markdown Files beside Upload makes a document from each .md file, a Markdown button beside PDF downloads a document as a .md file, and Markdown pasted into a document's rich text editor goes in as formatting; versions, restore, copy and the API carry the Markdown, and the API's document create and update no longer escape values twice; database 4.2.3 adds documents.document_markdown and document_versions.document_version_markdown, and league/commonmark 2.10 and league/html-to-markdown 5.2 are added to libs/vendor through composer; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-29 00:48:15 -05:00
parent a84c3eca79
commit 8b4fa5a1a0
484 changed files with 43707 additions and 63 deletions

View File

@@ -0,0 +1,111 @@
<?php declare(strict_types=1);
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette\Schema;
use Nette;
/**
* Schema validator.
*/
final class Processor
{
/** @var list<\Closure(Context): void> */
public array $onNewContext = [];
private Context $context;
private bool $skipDefaults = false;
/**
* When enabled, missing properties are not filled with their default values.
*/
public function skipDefaults(bool $value = true): void
{
$this->skipDefaults = $value;
}
/**
* Normalizes and validates data. Result is a clean completed data.
* @throws ValidationException
*/
public function process(Schema $schema, mixed $data): mixed
{
$context = $this->createContext();
try {
$data = $schema->normalize($data, $context);
$this->throwErrors($context);
$data = $schema->complete($data, $context);
$this->throwErrors($context);
return $data;
} finally {
$this->context = $context;
}
}
/**
* Normalizes and validates and merges multiple data. Result is a clean completed data.
* @param list<mixed> $dataset
* @throws ValidationException
*/
public function processMultiple(Schema $schema, array $dataset): mixed
{
$context = $this->createContext();
try {
$flatten = null;
$first = true;
foreach ($dataset as $data) {
$data = $schema->normalize($data, $context);
$this->throwErrors($context);
$flatten = $first ? $data : $schema->merge($data, $flatten);
$first = false;
}
$data = $schema->complete($flatten, $context);
$this->throwErrors($context);
return $data;
} finally {
$this->context = $context;
}
}
/**
* Returns all deprecation warnings collected during the last processing run.
* @return list<string>
*/
public function getWarnings(): array
{
$res = [];
if (isset($this->context)) {
foreach ($this->context->warnings as $message) {
$res[] = $message->toString();
}
}
return $res;
}
private function throwErrors(Context $context): void
{
if ($context->errors) {
throw new ValidationException(null, $context->errors);
}
}
private function createContext(): Context
{
$context = new Context;
$context->skipDefaults = $this->skipDefaults;
Nette\Utils\Arrays::invoke($this->onNewContext, $context);
return $context;
}
}