Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: alerts continue and complete #46

Merged
merged 5 commits into from
Dec 5, 2024
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
19 changes: 19 additions & 0 deletions .github/workflows/add-to-keyman-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Add new issues and pull requests to projects

on:
pull_request:
types:
- opened
issues:
types:
- opened

jobs:
add-to-project:
name: Add new issues and pull requests to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/keymanapp/projects/1
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
59 changes: 42 additions & 17 deletions _common/GFMAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public function __construct()
$this->BlockTypes['>'][] = 'Alert';
}

protected function blockQuote($block)
protected function blockQuote($line)
{
if(!preg_match('/^\>\s*\[\!(IMPORTANT|TIPS|NOTE|WARNING|CAUTION)\]\s(.*)/i', $block['text'], $matches)) {
return parent::blockQuote($block);
}
if(!preg_match('/^\>\s*\[\!(IMPORTANT|TIPS|NOTE|WARNING|CAUTION)\]/i', $line['text'], $matches)) {
return parent::blockQuote($line);
}
// Fetch The Alert's type and title.
$alertType = strtolower($matches[1]);
$alertTitle = ucfirst($alertType);
$iconType = "";
$alertContent = "";

$icon = array(
// svg and path
Expand All @@ -41,32 +40,58 @@ protected function blockQuote($block)
'caution' => '<svg class="octicon octicon-stop mr-2" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill="red" d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>',
'warning' => '<svg class="octicon octicon-alert mr-2" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill="orange" d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>'
);
$iconType .= $icon[$alertType] . $alertTitle; // return string

// check for matches of the $alertType in $icon. If there is no match, return plain text for the block.
if(empty($icon[$alertType])) {
return parent::blockQuote($block);
return parent::blockQuote($line);
}
$iconType = $icon[$alertType].$alertTitle;

$alertContent .= ltrim($matches[2]);

return array(
// Formatting:> [!AlertType]
$block = array(
'element' => array(
'name' => 'div',
'attributes' => array('class' => "markdown-alert markdown-alert-$alertType"),
'handler' => 'elements',
'text' => array(
array(
'name' => 'p',
'attributes' => array('class' => "markdown-alert-title"),
'attributes' => array('class' => "markdown-alert-title title-$alertType"),
'rawHtml' => $iconType
),
array(
'name' => 'p',
'text' => $alertContent,
)
)
)
);
// dd($block);
return $block;
}

protected function blockQuoteContinue($line, array $block) {
if(!preg_match('/^\>\s(.*)/', $line['text'], $matches)) {
return null;
}

// Recognize a new Alert
if(preg_match('/^\>\s*\[\!(IMPORTANT|TIPS|NOTE|WARNING|CAUTION)\]/i', $line['text'])) {
return null;
}

// Handles any interruption
if(isset($block['interrupted'])) {
return $block;
}

// Continue the Alerts, Formatting: > Content
$block['element']['text'][] = [
'name' => 'p',
'text' => $matches[1],
];

// dd($block);

return $block;
}

protected function blockQuoteComplete($block) {
return $block;
}
}