Skip to content

Commit bf7a7d7

Browse files
committed
feat: #53 new command html to markdown
1 parent a00d612 commit bf7a7d7

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Confluence;
6+
use LaravelZero\Framework\Commands\Command;
7+
8+
class ConfluenceHtml2MarkdownCommand extends Command
9+
{
10+
/**
11+
* The signature of the command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'confluence:html2markdown
16+
{html_path : HTML 文件路径,如 ./confluence/space1/231543.html}
17+
';
18+
19+
/**
20+
* The description of the command.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Confluence HTML 转 Markdown';
25+
26+
/**
27+
* Execute the console command.
28+
*
29+
*/
30+
public function handle(Confluence $confluence): int
31+
{
32+
$htmlPath = $this->argument('html_path');
33+
$dataDir = dirname($htmlPath);
34+
$page = basename($htmlPath);
35+
$markdown = $confluence->htmlFile2Markdown($htmlPath);
36+
$mdFilename = substr($page, 0, -5) . '.md';
37+
$mdPath = $dataDir . DIRECTORY_SEPARATOR . $mdFilename;
38+
file_put_contents($mdPath, $markdown . "\n");
39+
$this->info($mdPath);
40+
return 0;
41+
}
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Tests\TestCase;
6+
7+
class ConfluenceHtml2MarkdownCommandTest extends TestCase
8+
{
9+
public function testHandleConfluenceHtmlSuccess()
10+
{
11+
$this->artisan('confluence:html2markdown', [
12+
'html_path' => $this->dataDir . 'confluence/space1/text-demo_65601.html'
13+
])
14+
->expectsOutput($this->dataDir . 'confluence/space1/text-demo_65601.md')
15+
->assertExitCode(0);
16+
$this->assertEquals("你好\n==\n", file_get_contents($this->dataDir . 'confluence/space1/text-demo_65601.md'));
17+
}
18+
}

0 commit comments

Comments
 (0)