From d956471d42174a656dc2f4817ede056ee9ea77c3 Mon Sep 17 00:00:00 2001 From: Pavel Korytov Date: Mon, 2 Dec 2024 18:46:13 +0300 Subject: [PATCH] [QwenBlogBridge] Add bridge (#4353) --- bridges/QwenBlogBridge.php | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bridges/QwenBlogBridge.php diff --git a/bridges/QwenBlogBridge.php b/bridges/QwenBlogBridge.php new file mode 100644 index 00000000..2af3f401 --- /dev/null +++ b/bridges/QwenBlogBridge.php @@ -0,0 +1,49 @@ + [ + 'limit' => [ + 'name' => 'Limit', + 'type' => 'number', + 'required' => true, + 'defaultValue' => 10 + ], + ] + ]; + + public function collectData() + { + $this->collectExpandableDatas(self::URI . 'index.xml', $this->getInput('limit')); + } + + protected function parseItem(array $item) + { + $dom = getSimpleHTMLDOM($item['uri']); + $content = $dom->find('div.post-content', 0); + if ($content == null) { + return $item; + } + + // Fix code blocks + foreach ($dom->find('pre.chroma') as $code_block) { + // Somehow there are tags in
??
+            $code_block_html = str_get_html($code_block->plaintext);
+            $code = '';
+            foreach ($code_block_html->find('span.line') as $line) {
+                $code .= $line->plaintext . "\n";
+            }
+            $code_block->outertext = '
' . $code . '
'; + } + + $item['content'] = $content; + return $item; + } +}