Initial commit with PSR-4 autoloading and phpunit
This commit is contained in:
commit
1a2a5c01a7
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
vendor
|
||||||
|
.phpunit.result.cache
|
18
composer.json
Normal file
18
composer.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"autoload":{
|
||||||
|
"psr-4": {
|
||||||
|
"LogseqGem\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"LogseqGem\\Tests\\": "tests"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"league/commonmark": "^2.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.5"
|
||||||
|
}
|
||||||
|
}
|
2728
composer.lock
generated
Normal file
2728
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
phpunit.xml
Normal file
7
phpunit.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<phpunit bootstrap="vendor/autoload.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="parser">
|
||||||
|
<file>tests/ParserTest.php</file>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
15
run.php
Normal file
15
run.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
$parser = new LogseqGem\Parser;
|
||||||
|
|
||||||
|
$page = file_get_contents("/Users/annika/sync/BTSync/logseq/pages/Gemlog.md");
|
||||||
|
$page = file_get_contents("/Users/annika/sync/BTSync/logseq/pages/Publishing to the Gemlog with logseq.md");
|
||||||
|
|
||||||
|
$document = $parser->parse($page);
|
||||||
|
foreach ($document->iterator() as $node) {
|
||||||
|
echo 'Current node: ' . get_class($node) . "\n";
|
||||||
|
}
|
23
src/Parser.php
Normal file
23
src/Parser.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LogseqGem;
|
||||||
|
|
||||||
|
use League\CommonMark\Parser\MarkdownParser;
|
||||||
|
use League\CommonMark\Environment\Environment;
|
||||||
|
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
||||||
|
|
||||||
|
abstract class Parser {
|
||||||
|
private MarkdownParser $parser;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$environment = new Environment();
|
||||||
|
$environment->addExtension(new CommonMarkCoreExtension());
|
||||||
|
$this->parser = new MarkdownParser($environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(string $input) {
|
||||||
|
return $this->parser->parse($input);
|
||||||
|
}
|
||||||
|
}
|
18
tests/ParserTest.php
Normal file
18
tests/ParserTest.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LogseqGem\Tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use LogseqGem\Parser;
|
||||||
|
|
||||||
|
use League\CommonMark\Node\Block\Document;
|
||||||
|
|
||||||
|
class ParserTest extends TestCase {
|
||||||
|
public function testParse() {
|
||||||
|
$parser = $this->getMockForAbstractClass(Parser::class);
|
||||||
|
$document = $parser->parse('**foo**');
|
||||||
|
$this->assertInstanceOf(Document::class, $document);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user