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

@@ -775,9 +775,9 @@ function filesZipFolderItems($client_id, $folder_id) {
/**
* Copy a document - for the same client or another one the agent can reach. The copy has the
* content, summary, tags, template and review schedule; its pictures are copied with it, so it
* keeps them if the original goes. It starts out of the client portal, linked to nothing, with
* no history. Returns the new document's id.
* content (in Markdown, for one written in it), summary, tags, template and review schedule;
* its pictures are copied with it, so it keeps them if the original goes. It starts out of the
* client portal, linked to nothing, with no history. Returns the new document's id.
*/
function documentCopy($document_id, $client_id, $folder_id, $name) {
global $mysqli, $session_user_id;
@@ -801,13 +801,15 @@ function documentCopy($document_id, $client_id, $folder_id, $name) {
$new_id = mysqli_insert_id($mysqli);
$content = (string) $row['document_content'];
$markdown = $row['document_markdown'] ?? null; // written in Markdown, what it says as written
$from = dirname(__DIR__) . "/uploads/documents/$document_id";
if (is_dir($from)) {
copyDirectory($from, dirname(__DIR__) . "/uploads/documents/$new_id");
$content = str_replace("/uploads/documents/$document_id/", "/uploads/documents/$new_id/", $content);
$markdown = $markdown === null ? null : str_replace("/uploads/documents/$document_id/", "/uploads/documents/$new_id/", $markdown);
}
mysqli_query($mysqli, "UPDATE documents SET document_content = '" . mysqli_real_escape_string($mysqli, $content) . "',
document_content_raw = '" . escapeSql(documentContentRaw($name, $content)) . "' WHERE document_id = $new_id");
document_content_raw = '" . escapeSql(documentContentRaw($name, $content)) . "'" . documentMarkdownSet($markdown) . " WHERE document_id = $new_id");
tagSetForRecord('document', $new_id, tagIdsForRecord('document', $document_id));