wp-md-rest-import/debug.php

49 lines
1.5 KiB
PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Diese Datei dient zur Überprüfung des Markdown-Parsings und der Fehlerbehandlung
// Funktion zum Laden des Markdown-Inhalts von einer URL
function fetch_markdown($url) {
$content = file_get_contents($url);
if ($content === false) {
throw new Exception("Fehler beim Laden der URL: $url");
}
return $content;
}
// Funktion zum Parsen des Markdown-Inhalts
function parse_markdown($markdown) {
if (preg_match('/^---\s*(.*?)\s*---\s*(.*)$/s', $markdown, $matches)) {
$yaml_raw = $matches[1];
$content_md = $matches[2];
require_once 'lib/spyc.php';
require_once 'lib/Parsedown.php';
$yaml = Spyc::YAMLLoadString($yaml_raw);
$html = (new Parsedown())->text($content_md);
return [$yaml, $html];
} else {
throw new Exception("YAML-Header im Markdown nicht gefunden.");
}
}
// Hauptlogik
try {
$url = 'https://git.rpi-virtuell.de/Comenius-Institut/FOERBICO/raw/branch/main/Website/content/posts/2025-02-25-KLT-M%C3%BCnster/index.md';
echo "Lade Markdown von: $url\n\n";
$markdown = fetch_markdown($url);
echo "Markdown-Inhalt:\n" . $markdown . "\n\n";
list($yaml, $html) = parse_markdown($markdown);
echo "--- YAML-Header als Array ---\n";
print_r($yaml);
echo "\n--- Generiertes HTML ---\n";
echo $html . "\n";
} catch (Exception $e) {
echo "Fehler: " . $e->getMessage();
}