md2json-symfony für verbessertes Markdown-Parsing via Composer und Symfony statt regex oder spyc
This commit is contained in:
parent
51573e2fe7
commit
b6d64972a2
452 changed files with 40010 additions and 0 deletions
51
md2json-symfony.php
Normal file
51
md2json-symfony.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$url = 'https://git.rpi-virtuell.de/Comenius-Institut/FOERBICO/raw/branch/main/Website/content/posts/2025-03-20-Workshop-KlimaOER/index.md';
|
||||
|
||||
// Markdown-Inhalt von der URL laden
|
||||
$content = file_get_contents($url);
|
||||
if ($content === false) {
|
||||
die("Fehler: Konnte Datei nicht laden.");
|
||||
}
|
||||
|
||||
// YAML-Header und Markdown-Inhalt trennen
|
||||
$parts = explode('---', $content);
|
||||
if (count($parts) < 3) {
|
||||
die("Fehler: Ungültiges Dateiformat - YAML-Header nicht gefunden.");
|
||||
}
|
||||
|
||||
$yamlContent = trim($parts[1]);
|
||||
$markdownContent = trim($parts[2]);
|
||||
|
||||
// YAML in JSON konvertieren
|
||||
try {
|
||||
$parsedYaml = Yaml::parse($yamlContent);
|
||||
$jsonOutput = json_encode(
|
||||
$parsedYaml,
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
die("YAML-Parsing Fehler: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Hauptüberschrift aus Markdown entfernen
|
||||
$markdownLines = explode("\n", $markdownContent);
|
||||
foreach ($markdownLines as $key => $line) {
|
||||
if (strpos(trim($line), '# ') === 0) {
|
||||
unset($markdownLines[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$cleanedMarkdown = implode("\n", $markdownLines);
|
||||
|
||||
// Ergebnisse speichern
|
||||
file_put_contents('metadata.json', $jsonOutput);
|
||||
file_put_contents('content.md', $cleanedMarkdown);
|
||||
|
||||
echo "Erfolgreich verarbeitet:\n";
|
||||
echo "- JSON-Metadaten: metadata.json\n";
|
||||
echo "- Bereinigter Inhalt: content.md\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue