Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/properties-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test DB item 1

| Property | Value |
| --- | --- |
| CheckboxField | ✓ |
| Type | type-1 |
| Email | [test@gogmail.com](mailto:test@gogmail.com) |
| Date | 2025-09-02 |
| Status | In progress |
| Priority Level | 3, 2 |
| Files & media | [ChatGPT Image Sep 3, 2025, 09_59_04 PM.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/0d31a281-d71e-4bb9-9031-a5256095b873/641f2fcb-cf13-4c62-8d9d-2871f34a1a6a/ChatGPT_Image_Sep_3_2025_09_59_04_PM.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TSVKJSYL%2F20251113%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20251113T142329Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEIb%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIFRgCBhDrbx1BLqDYCSDBN0nKqfqOJQCDDgcaAlS7FlFAiEA61lIOYodqWb175B59GZ0I5UZAEVGESLENFu7u63l7yQq%2FwMITxAAGgw2Mzc0MjMxODM4MDUiDOjdkbEDAHH2feRgTCrcA52bxAy4SCWSISHqMfTFKV2hIXhxNoozmqaLUe2h2J4ZyCkPy7PoUDxaQ50Lz22Ef4qtAfpfuhfjDxG7U31MZuOVyVL8FHY7HLgkfG9xa%2Fmde0rvJRbVB0jVDJ6IPUYXnIVFt2i99jm20Y69%2Frxqdpojjf8qYXZ%2BFhLKyvEQMVtkf8JoGs5d%2BdzA8%2FKW1tfyTArdYlr9hwPge8%2BtBiFVGbtCtUzmYsQ6DgE8AQSvdaymhlyWZLGMXLM8teiVvygXfj1UmBgphObTgP5bHpzMAUkcGKr2Tgy6oeGmRPru2iajdVZanlXbliixd%2B89y0cYy%2F2TW7EI7qQTbb71hyoG72k4pb9Fe%2B4wNXcX42cC%2FuURsVdmfhjxLP%2FwmGuuJuKZAaIvPQBBvBQZR8uX4kcXHA5EP8B4H5Q16%2BpImFcREddY4dV4ge4zdQ7bRkfvtKDqB5GZOao3fYB59gow222KG1AEuf4q0m68QmeSye9tleUxG21mLpYRwd97Hb%2BZUQd%2F8YETrqMcQgJPla%2FIuR71zpRaMTt%2FCdsbhH0qudsDOMJO1cEvDnfF1dhA3ktdyMfDWcNplz5Y0XG8FvkJ1TvNAODiTC%2F9ToHstPj76i%2BUdP9wQFlVoEEoNwLnWeoSMPHC18gGOqUB1DXrEJu41npTQQ2drVOjvBH0Ce2PT4mEx7SJpUJYL1o53dsHF3vvXPvlivx1pp6azmVDYwsAlFncBNTwBBm6rkytMfi4vC9GgB5ovSwCGNuWgQpYm8ZQuy5SYZ4Rgq1pI6Sqz75B1fnUgOa7bHAJrTfZ%2FdaHISPNwbsWULzDE44jpADZk9mxdmROHT1S6Urgn38UlZlo9iAqH2ffG4YjK%2B3HMKWR&X-Amz-Signature=6f39e1d0620132a3ed8b664b8b99adf82929e79cf1dd8f561a2a1153803f36be&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject) |
| Person | Maestro Error |
| Name | Test DB item 1 |




> 💪 Test callout





125 changes: 125 additions & 0 deletions examples/properties-fetch-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

require_once __DIR__.'/../vendor/autoload.php';

use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\View;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
use Redberry\MdNotion\Adapters\BlockAdapterFactory;
use Redberry\MdNotion\SDK\Notion;
use Redberry\MdNotion\Services\BlockRegistry;
use Redberry\MdNotion\Services\DatabaseReader;
use Redberry\MdNotion\Services\DatabaseTable;
use Redberry\MdNotion\Services\PageReader;
use Redberry\MdNotion\Services\PropertiesTable;

// Set up Laravel container
$container = new Container;
Container::setInstance($container);

// Set up Facade root
Facade::setFacadeApplication($container);

// Register filesystem
$container->singleton('files', fn () => new Filesystem);

// Register blade compiler
$container->singleton('blade.compiler', function ($app) {
return new BladeCompiler(
$app['files'],
__DIR__.'/../storage/views'
);
});

// Set up view finder
$viewFinder = new FileViewFinder(
$container['files'],
[__DIR__.'/../resources/views']
);

// Add namespace for our views
$viewFinder->addNamespace('md-notion', __DIR__.'/../resources/views');

// Set up view factory
$resolver = new EngineResolver;
$resolver->register('blade', function () use ($container) {
return new CompilerEngine($container['blade.compiler']);
});

$factory = new Factory(
$resolver,
$viewFinder,
new Dispatcher($container)
);

// Bind view factory to container
$container->instance('view', $factory);
View::setFacadeApplication($container);

// Initialize the real Notion SDK with token
$token = include __DIR__.'/../notion-token.php';
$notion = new Notion($token, '2025-09-03');

// Create services
$mdNotionConfig = include __DIR__.'/../config/md-notion.php';
$blockRegistry = new BlockRegistry(new BlockAdapterFactory($notion, $mdNotionConfig['adapters'] ?? []));
$databaseTable = new DatabaseTable;
$pageReader = new PageReader($notion, $blockRegistry);
$databaseReader = new DatabaseReader($notion, $databaseTable);
$propertiesTable = new PropertiesTable;

// Bind services to container so Page objects can use them
$container->instance(PropertiesTable::class, $propertiesTable);

// Use a page ID that has properties (replace with your actual page ID)
// This should be a page from your Notion workspace that has various properties
$pageId = '263d9316605a80c0a8fbfd152e79b9d8'; // Replace with a page that has properties

echo "Fetching page content with properties...\n";

try {
// Read page
$page = $pageReader->read($pageId);

echo "Page fetched successfully!\n";
echo 'Page title: '.$page->getTitle()."\n";
echo 'Has properties: '.($page->hasProperties() ? 'Yes ('.count($page->getProperties()).')' : 'No')."\n";
echo 'Content length: '.strlen($page->getContent() ?? '')." characters\n\n";

// Build markdown content
$markdown = '';

// Add page title
$markdown .= $page->renderTitle(1)."\n\n";

// Add properties table if available
if ($page->hasProperties()) {
$markdown .= $page->renderPropertiesTable()."\n";
}

// Add page content
if ($page->hasContent()) {
$markdown .= $page->getContent()."\n\n";
}

// Save to file
file_put_contents(__DIR__.'/properties-example.md', $markdown);

echo "Page with properties table converted and saved to examples/properties-example.md\n";
echo "\nGenerated markdown:\n";
echo "---\n";
echo $markdown;
echo "---\n";

} catch (\Exception $e) {
echo 'Error: '.$e->getMessage()."\n";
echo "Stack trace:\n";
echo $e->getTraceAsString()."\n";
}
4 changes: 4 additions & 0 deletions resources/views/full-md.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

{!! $current_page['title'] !!}

@if($current_page['hasPropertiesTable'])

{!! $current_page['properties_table'] !!}
@endif
@if($current_page['hasContent'])

{!! $current_page['content'] !!}
Expand Down
8 changes: 8 additions & 0 deletions resources/views/page-md.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{!! $current_page['title'] !!}

@if($current_page['hasPropertiesTable'])

{!! $current_page['properties_table'] !!}
@endif
@if($current_page['hasContent'])

{!! $current_page['content'] !!}
Expand All @@ -25,6 +29,10 @@
@foreach($child_pages as $childPage)
{!! $childPage['title'] !!}

@if($childPage['hasPropertiesTable'])

{!! $childPage['properties_table'] !!}
@endif
@if($childPage['hasContent'])
{!! $childPage['content'] !!}

Expand Down
4 changes: 4 additions & 0 deletions src/ContentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function read(): string
// Build structured data for template
$currentPage = [
'title' => $page->renderTitle(1),
'properties_table' => $page->hasProperties() ? $page->renderPropertiesTable() : null,
'hasPropertiesTable' => $page->hasProperties(),
'content' => $page->hasContent() ? $page->getContent() : null,
'hasContent' => $page->hasContent(),
];
Expand All @@ -101,6 +103,8 @@ public function read(): string
foreach ($page->getChildPages() as $childPage) {
$childPages[] = [
'title' => $childPage->renderTitle(3),
'properties_table' => $childPage->hasProperties() ? $childPage->renderPropertiesTable() : null,
'hasPropertiesTable' => $childPage->hasProperties(),
'content' => $childPage->hasContent() ? $childPage->getContent() : null,
'hasContent' => $childPage->hasContent(),
];
Expand Down
2 changes: 2 additions & 0 deletions src/MdNotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ private function buildFullMarkdownData($page, $level = 1): array
{
$currentPage = [
'title' => $page->renderTitle($level),
'properties_table' => $page->hasProperties() ? $page->renderPropertiesTable() : null,
'hasPropertiesTable' => $page->hasProperties(),
'content' => $page->hasContent() ? $page->getContent() : null,
'hasContent' => $page->hasContent(),
];
Expand Down
16 changes: 16 additions & 0 deletions src/Objects/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ public function fetch(): static
return $this;
}

/**
* Render properties as markdown table
*
* @return string The properties table markdown
*/
public function renderPropertiesTable(): string
{
if (! $this->hasProperties()) {
return '';
}

$propertiesTable = app(\Redberry\MdNotion\Services\PropertiesTable::class);

return $propertiesTable->convertPropertiesToMarkdownTable($this->properties);
}

/**
* Convert the page to an array
*/
Expand Down
Loading
Loading