From 5ea79ac1fc488ce0e57de9f9c44f9dbd5f9f1e26 Mon Sep 17 00:00:00 2001 From: Nemo Date: Fri, 29 Jun 2018 00:24:42 +0530 Subject: [PATCH] Add markdown support to Container Linux Feed (#730) --- bridges/ContainerLinuxReleasesBridge.php | 31 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/bridges/ContainerLinuxReleasesBridge.php b/bridges/ContainerLinuxReleasesBridge.php index c5f64a1..bcb421d 100644 --- a/bridges/ContainerLinuxReleasesBridge.php +++ b/bridges/ContainerLinuxReleasesBridge.php @@ -40,18 +40,35 @@ class ContainerLinuxReleasesBridge extends BridgeAbstract { $item['uri'] = "https://coreos.com/releases/#$releaseVersion"; $item['title'] = $releaseVersion; - $item['content'] = nl2br($release['release_notes']); - $item['content'] .= << + $content = $release['release_notes']; + $content .= << -- Kernel: {$release['major_software']['kernel'][0]}
-- Docker: {$release['major_software']['docker'][0]}
-- etcd: {$release['major_software']['etcd'][0]}
+* Kernel: {$release['major_software']['kernel'][0]} +* Docker: {$release['major_software']['docker'][0]} +* etcd: {$release['major_software']['etcd'][0]} EOT; $item['timestamp'] = strtotime($release['release_date']); + // Based on https://gist.github.com/jbroadway/2836900 + // Links + $regex = '/\[([^\[]+)\]\(([^\)]+)\)/'; + $replacement = '\1'; + $item['content'] = preg_replace($regex, $replacement, $content); + + // Headings + $regex = '/^(.*)\:\s?$/m'; + $replacement = '

\1

'; + $item['content'] = preg_replace($regex, $replacement, $item['content']); + + // Lists + $regex = '/\n\s*[\*|\-](.*)/'; + $item['content'] = preg_replace_callback ($regex, function($regs) { + $item = $regs[1]; + return sprintf ("
  • %s
", trim ($item)); + }, $item['content']); + $this->items[] = $item; } }