-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
63cb1fb
Merge pull request #31 from keymanapp/alerts/v0.12
Meng-Heng 56fb4c8
Merge branch 'main' of https://github.com/Meng-Heng/shared-sites into…
Meng-Heng 6b73c8e
feat: alerts continue and complete
Meng-Heng d151ca7
fix: improve code
Meng-Heng 09eeb2f
Merge pull request #32 from keymanapp/alerts/final
Meng-Heng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -41,32 +40,59 @@ 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 null; | ||
} | ||
$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; | ||
} | ||
|
||
if(isset($block['interrupted'])) { | ||
$block['element']['text'][] = [ | ||
'text' => '' | ||
]; | ||
unset($block['interrupted']); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what this is doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Continue the Alerts, Formatting: > Content | ||
$block['element']['text'][] = [ | ||
'name' => 'p', | ||
'text' => $matches[1], | ||
]; | ||
|
||
// dd($block); | ||
|
||
return $block; | ||
} | ||
|
||
protected function blockQuoteComplete($block) { | ||
return $block; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be returning
parent::blockQuote($line)
?