From eea74e4afd5b3e442f8e591c6a466ef2469bb3eb Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 15 Jul 2024 15:14:36 +1000 Subject: [PATCH 1/3] Render blockquotes on the server --- app/Markdown/BlockQuoteRenderer.php | 92 +++++++++++++++++++ .../GithubFlavoredMarkdownConverter.php | 18 +++- .../GithubFlavoredMarkdownExtension.php | 21 ----- public/img/callouts/star.min.svg | 1 - .../images/exclamation.svg | 2 +- .../images/laracast.svg | 0 .../images/lightbulb.svg | 0 resources/js/docs.js | 84 ----------------- resources/views/docs.blade.php | 8 +- tailwind.config.js | 1 + 10 files changed, 117 insertions(+), 110 deletions(-) create mode 100644 app/Markdown/BlockQuoteRenderer.php delete mode 100644 app/Markdown/GithubFlavoredMarkdownExtension.php delete mode 100644 public/img/callouts/star.min.svg rename public/img/callouts/exclamation.min.svg => resources/images/exclamation.svg (68%) rename public/img/callouts/laracast.min.svg => resources/images/laracast.svg (100%) rename public/img/callouts/lightbulb.min.svg => resources/images/lightbulb.svg (100%) diff --git a/app/Markdown/BlockQuoteRenderer.php b/app/Markdown/BlockQuoteRenderer.php new file mode 100644 index 00000000..a1578a3c --- /dev/null +++ b/app/Markdown/BlockQuoteRenderer.php @@ -0,0 +1,92 @@ +render($node, $childRenderer); + + if (! $element instanceof HtmlElement || $element->getTagName() !== 'blockquote') { + return $element; + } + + $html = trim($element->getContents(true)); + + if (! str_starts_with($html, '

')) { + return $element; + } + + $htmlPartial = Str::after($html, '

'); + + if (preg_match('/^\[!(NOTE|WARNING)\](?:
)?/', $htmlPartial, $matches) === 1) { + // GitHub styled notes, e.g., + // > [!NOTE] Content + // or + // > [!NOTE] + // > Content + + [$asset, $class] = match ($matches[1]) { + 'WARNING' => [Vite::content('resources/images/exclamation.svg'), 'bg-red-600'], + 'NOTE' => [Vite::content('resources/images/lightbulb.svg'), 'bg-purple-600'], + }; + } elseif (preg_match('/^(Note|Warning):?<\/strong>:?(?:
)?/', $htmlPartial, $matches) === 1) { + // Legacy GitHub styled notes, e.g., + // > **Note:** Content + // or + // > **Note**: Content + // or + // > **Note** Content + // or + // > **Note:** + // > Content + // or + // > **Note**: + // > Content + // or + // > **Note** + // > Content + + [$asset, $class] = match ($matches[1]) { + 'Warning' => [Vite::content('resources/images/exclamation.svg'), 'bg-red-600'], + 'Note' => [Vite::content('resources/images/lightbulb.svg'), 'bg-purple-600'], + }; + } elseif (preg_match('/^\{(note|tip|video)\}/', $htmlPartial, $matches) === 1) { + // Legacy Laravel styled notes, e.g., + // > {tip} Content + + [$asset, $class] = match ($matches[1]) { + 'note' => [Vite::content('resources/images/exclamation.svg'), 'bg-red-600'], + 'tip' => [Vite::content('resources/images/lightbulb.svg'), 'bg-purple-600'], + 'video' => [Vite::content('resources/images/laracast.svg'), 'bg-blue-600'], + }; + } else { + return $element; + } + + $bodyPartial = str_replace($matches[0], '', $htmlPartial); + + return << +

+
{$asset}
+
+

{$bodyPartial} + + HTML; + } +} diff --git a/app/Markdown/GithubFlavoredMarkdownConverter.php b/app/Markdown/GithubFlavoredMarkdownConverter.php index f464dc5e..77aafca7 100644 --- a/app/Markdown/GithubFlavoredMarkdownConverter.php +++ b/app/Markdown/GithubFlavoredMarkdownConverter.php @@ -2,14 +2,25 @@ namespace App\Markdown; +use Illuminate\Support\Str; +use League\CommonMark\Extension\Autolink\AutolinkExtension; +use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; +use League\CommonMark\Extension\Table\TableExtension; +use League\CommonMark\Extension\TaskList\TaskListExtension; use League\CommonMark\MarkdownConverter; use League\CommonMark\Environment\Environment; use App\Markdown\GithubFlavoredMarkdownExtension; +use Illuminate\Support\Facades\Vite; +use League\CommonMark\Node\Node; +use League\CommonMark\Renderer\ChildNodeRendererInterface; +use League\CommonMark\Util\HtmlElement; use Torchlight\Commonmark\V2\TorchlightExtension; use Laravel\Unfenced\UnfencedExtension; use League\CommonMark\Environment\EnvironmentInterface; use League\CommonMark\Extension\Attributes\AttributesExtension; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; +use League\CommonMark\Extension\CommonMark\Node\Block\BlockQuote; +use League\CommonMark\Renderer\NodeRendererInterface; /** * Converts GitHub Flavored Markdown to HTML. @@ -25,11 +36,16 @@ public function __construct(array $config = []) { $environment = new Environment($config); $environment->addExtension(new CommonMarkCoreExtension()); - $environment->addExtension(new GithubFlavoredMarkdownExtension()); + $environment->addExtension(new AutolinkExtension()); + $environment->addExtension(new StrikethroughExtension()); + $environment->addExtension(new TableExtension()); + $environment->addExtension(new TaskListExtension()); $environment->addExtension(new UnfencedExtension()); $environment->addExtension(new AttributesExtension()); $environment->addExtension(new TorchlightExtension()); + $environment->addRenderer(BlockQuote::class, new BlockQuoteRenderer()); + parent::__construct($environment); } diff --git a/app/Markdown/GithubFlavoredMarkdownExtension.php b/app/Markdown/GithubFlavoredMarkdownExtension.php deleted file mode 100644 index 7a4d8c6f..00000000 --- a/app/Markdown/GithubFlavoredMarkdownExtension.php +++ /dev/null @@ -1,21 +0,0 @@ -addExtension(new AutolinkExtension()); - $environment->addExtension(new StrikethroughExtension()); - $environment->addExtension(new TableExtension()); - $environment->addExtension(new TaskListExtension()); - } -} diff --git a/public/img/callouts/star.min.svg b/public/img/callouts/star.min.svg deleted file mode 100644 index dc7524ab..00000000 --- a/public/img/callouts/star.min.svg +++ /dev/null @@ -1 +0,0 @@ -star \ No newline at end of file diff --git a/public/img/callouts/exclamation.min.svg b/resources/images/exclamation.svg similarity index 68% rename from public/img/callouts/exclamation.min.svg rename to resources/images/exclamation.svg index b9ce3950..c0d4398e 100644 --- a/public/img/callouts/exclamation.min.svg +++ b/resources/images/exclamation.svg @@ -1 +1 @@ -exclamation \ No newline at end of file +exclamation diff --git a/public/img/callouts/laracast.min.svg b/resources/images/laracast.svg similarity index 100% rename from public/img/callouts/laracast.min.svg rename to resources/images/laracast.svg diff --git a/public/img/callouts/lightbulb.min.svg b/resources/images/lightbulb.svg similarity index 100% rename from public/img/callouts/lightbulb.min.svg rename to resources/images/lightbulb.svg diff --git a/resources/js/docs.js b/resources/js/docs.js index 16c06796..1ecc2fdc 100644 --- a/resources/js/docs.js +++ b/resources/js/docs.js @@ -4,7 +4,6 @@ import './theme' document.addEventListener('DOMContentLoaded', () => { wrapHeadingsInAnchors(); setupNavCurrentLinkHandling(); - replaceBlockquotesWithCalloutsInDocs(); highlightSupportPolicyTable(); const skipToContentLink = document.querySelector('#skip-to-content-link'); @@ -48,89 +47,6 @@ function setupNavCurrentLinkHandling() { }); } -function replaceBlockquotesWithCalloutsInDocs() { - [...document.querySelectorAll('.docs_main blockquote p')].forEach(el => { - // Legacy Laravel styled notes... - replaceBlockquote(el, /\{(.*?)\}/, (type) => { - switch (type) { - case "note": - return ['/img/callouts/exclamation.min.svg', 'bg-red-600', 6, 35]; - case "tip": - return ['/img/callouts/lightbulb.min.svg', 'bg-purple-600', 28, 40]; - case "laracasts": - case "video": - return ['/img/callouts/laracast.min.svg', 'bg-blue-600', 49, 40]; - default: - return [null, null, 0, 0]; - } - }); - - // GitHub styled notes... - replaceBlockquote(el, /^\[\!(.*?)\](?:
\n?)?/, (type) => { - switch (type) { - case "WARNING": - return ['/img/callouts/exclamation.min.svg', 'bg-red-600', 6, 35]; - case "NOTE": - return ['/img/callouts/lightbulb.min.svg', 'bg-purple-600', 28, 40]; - default: - return [null, null, 0, 0]; - } - }); - - // Legagcy GitHub styled notes... - replaceBlockquote(el, /^(.*?)<\/strong>(?:
\n?)?/, (type) => { - switch (type) { - case "Warning": - return ['/img/callouts/exclamation.min.svg', 'bg-red-600', 6, 35]; - case "Note": - return ['/img/callouts/lightbulb.min.svg', 'bg-purple-600', 28, 40]; - default: - return [null, null, 0, 0]; - } - }); - }); -} - -function replaceBlockquote(el, regex, getImageAndColorByType) { - var str = el.innerHTML; - var match = str.match(regex); - var img, color, width, height; - - if (match) { - var type = match[1] || false; - } - - if (type) { - [img, color, width, height] = getImageAndColorByType(type); - - if (img === null && color === null) { - return; - } - - const wrapper = document.createElement('div'); - wrapper.classList = 'mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center'; - - const imageWrapper = document.createElement('div'); - imageWrapper.classList = `w-20 h-20 mb-6 flex items-center justify-center shrink-0 ${color} lg:mb-0`; - const image = document.createElement('img'); - image.src = img; - image.height = height - image.width = width - image.loading = 'lazy' - image.classList = `opacity-75`; - imageWrapper.appendChild(image); - wrapper.appendChild(imageWrapper); - - el.parentNode.insertBefore(wrapper, el); - - el.innerHTML = str.replace(regex, ''); - - el.classList = 'mb-0 lg:ml-6'; - wrapper.classList.add('callout'); - wrapper.appendChild(el); - } -} - function highlightSupportPolicyTable() { function highlightCells(table) { diff --git a/resources/views/docs.blade.php b/resources/views/docs.blade.php index 8d2e8b44..6337de33 100644 --- a/resources/views/docs.blade.php +++ b/resources/views/docs.blade.php @@ -192,7 +192,9 @@ class="appearance-none flex-1 w-full px-0 py-1 placeholder-gray-900 tracking-wid

- Icon +
+ {!! Vite::content('resources/images/exclamation.svg') !!} +

@@ -209,7 +211,9 @@ class="appearance-none flex-1 w-full px-0 py-1 placeholder-gray-900 tracking-wid

- Icon +
+ {!! Vite::content('resources/images/exclamation.svg') !!} +

diff --git a/tailwind.config.js b/tailwind.config.js index ad72fcc5..7031be30 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -37,6 +37,7 @@ const accentColors = { export default { content: [ + 'app/Markdown/*.php', 'resources/views/**/*.blade.php', 'resources/js/**/*.js', ], From 06b6a21eaf0bb9cad498df8e8fd9a3bf0a845d89 Mon Sep 17 00:00:00 2001 From: timacdonald Date: Mon, 15 Jul 2024 06:21:21 +0000 Subject: [PATCH 2/3] Compile Assets --- public/build/assets/docs-7c75c91c.js | 6 ------ public/build/assets/docs-8564cabe.js | 6 ++++++ public/build/assets/exclamation-c1673397.svg | 1 + public/build/assets/laracast-a56494c6.svg | 1 + public/build/assets/lightbulb-ab2e1311.svg | 1 + public/build/manifest.json | 14 +++++++++++++- 6 files changed, 22 insertions(+), 7 deletions(-) delete mode 100644 public/build/assets/docs-7c75c91c.js create mode 100644 public/build/assets/docs-8564cabe.js create mode 100644 public/build/assets/exclamation-c1673397.svg create mode 100644 public/build/assets/laracast-a56494c6.svg create mode 100644 public/build/assets/lightbulb-ab2e1311.svg diff --git a/public/build/assets/docs-7c75c91c.js b/public/build/assets/docs-7c75c91c.js deleted file mode 100644 index 5cd8b14b..00000000 --- a/public/build/assets/docs-7c75c91c.js +++ /dev/null @@ -1,6 +0,0 @@ -var J=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function X(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var R={exports:{}};/*! - * clipboard.js v2.0.10 - * https://clipboardjs.com/ - * - * Licensed MIT © Zeno Rocha - */(function(r,h){(function(g,E){r.exports=E()})(J,function(){return function(){var w={686:function(s,o,t){t.d(o,{default:function(){return G}});var a=t(279),d=t.n(a),u=t(370),v=t.n(u),p=t(817),S=t.n(p);function m(c){try{return document.execCommand(c)}catch{return!1}}var b=function(n){var e=S()(n);return m("cut"),e},y=b;function C(c){var n=document.documentElement.getAttribute("dir")==="rtl",e=document.createElement("textarea");e.style.fontSize="12pt",e.style.border="0",e.style.padding="0",e.style.margin="0",e.style.position="absolute",e.style[n?"right":"left"]="-9999px";var l=window.pageYOffset||document.documentElement.scrollTop;return e.style.top="".concat(l,"px"),e.setAttribute("readonly",""),e.value=c,e}var j=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},l="";if(typeof n=="string"){var i=C(n);e.container.appendChild(i),l=S()(i),m("copy"),i.remove()}else l=S()(n),m("copy");return l},k=j;function x(c){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?x=function(e){return typeof e}:x=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},x(c)}var q=function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=n.action,l=e===void 0?"copy":e,i=n.container,f=n.target,T=n.text;if(l!=="copy"&&l!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(f!==void 0)if(f&&x(f)==="object"&&f.nodeType===1){if(l==="copy"&&f.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(l==="cut"&&(f.hasAttribute("readonly")||f.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(T)return k(T,{container:i});if(f)return l==="cut"?y(f):k(f,{container:i})},B=q;function _(c){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?_=function(e){return typeof e}:_=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_(c)}function z(c,n){if(!(c instanceof n))throw new TypeError("Cannot call a class as a function")}function D(c,n){for(var e=0;e"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function L(c){return L=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},L(c)}function M(c,n){var e="data-clipboard-".concat(c);if(n.hasAttribute(e))return n.getAttribute(e)}var Y=function(c){$(e,c);var n=F(e);function e(l,i){var f;return z(this,e),f=n.call(this),f.resolveOptions(i),f.listenClick(l),f}return I(e,[{key:"resolveOptions",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof i.action=="function"?i.action:this.defaultAction,this.target=typeof i.target=="function"?i.target:this.defaultTarget,this.text=typeof i.text=="function"?i.text:this.defaultText,this.container=_(i.container)==="object"?i.container:document.body}},{key:"listenClick",value:function(i){var f=this;this.listener=v()(i,"click",function(T){return f.onClick(T)})}},{key:"onClick",value:function(i){var f=i.delegateTarget||i.currentTarget,T=this.action(f)||"copy",A=B({action:T,container:this.container,target:this.target(f),text:this.text(f)});this.emit(A?"success":"error",{action:T,text:A,trigger:f,clearSelection:function(){f&&f.focus(),document.activeElement.blur(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(i){return M("action",i)}},{key:"defaultTarget",value:function(i){var f=M("target",i);if(f)return document.querySelector(f)}},{key:"defaultText",value:function(i){return M("text",i)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(i){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return k(i,f)}},{key:"cut",value:function(i){return y(i)}},{key:"isSupported",value:function(){var i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],f=typeof i=="string"?[i]:i,T=!!document.queryCommandSupported;return f.forEach(function(A){T=T&&!!document.queryCommandSupported(A)}),T}}]),e}(d()),G=Y},828:function(s){var o=9;if(typeof Element<"u"&&!Element.prototype.matches){var t=Element.prototype;t.matches=t.matchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector||t.webkitMatchesSelector}function a(d,u){for(;d&&d.nodeType!==o;){if(typeof d.matches=="function"&&d.matches(u))return d;d=d.parentNode}}s.exports=a},438:function(s,o,t){var a=t(828);function d(p,S,m,b,y){var C=v.apply(this,arguments);return p.addEventListener(m,C,y),{destroy:function(){p.removeEventListener(m,C,y)}}}function u(p,S,m,b,y){return typeof p.addEventListener=="function"?d.apply(null,arguments):typeof m=="function"?d.bind(null,document).apply(null,arguments):(typeof p=="string"&&(p=document.querySelectorAll(p)),Array.prototype.map.call(p,function(C){return d(C,S,m,b,y)}))}function v(p,S,m,b){return function(y){y.delegateTarget=a(y.target,S),y.delegateTarget&&b.call(p,y)}}s.exports=u},879:function(s,o){o.node=function(t){return t!==void 0&&t instanceof HTMLElement&&t.nodeType===1},o.nodeList=function(t){var a=Object.prototype.toString.call(t);return t!==void 0&&(a==="[object NodeList]"||a==="[object HTMLCollection]")&&"length"in t&&(t.length===0||o.node(t[0]))},o.string=function(t){return typeof t=="string"||t instanceof String},o.fn=function(t){var a=Object.prototype.toString.call(t);return a==="[object Function]"}},370:function(s,o,t){var a=t(879),d=t(438);function u(m,b,y){if(!m&&!b&&!y)throw new Error("Missing required arguments");if(!a.string(b))throw new TypeError("Second argument must be a String");if(!a.fn(y))throw new TypeError("Third argument must be a Function");if(a.node(m))return v(m,b,y);if(a.nodeList(m))return p(m,b,y);if(a.string(m))return S(m,b,y);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function v(m,b,y){return m.addEventListener(b,y),{destroy:function(){m.removeEventListener(b,y)}}}function p(m,b,y){return Array.prototype.forEach.call(m,function(C){C.addEventListener(b,y)}),{destroy:function(){Array.prototype.forEach.call(m,function(C){C.removeEventListener(b,y)})}}}function S(m,b,y){return d(document.body,m,b,y)}s.exports=u},817:function(s){function o(t){var a;if(t.nodeName==="SELECT")t.focus(),a=t.value;else if(t.nodeName==="INPUT"||t.nodeName==="TEXTAREA"){var d=t.hasAttribute("readonly");d||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),d||t.removeAttribute("readonly"),a=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var u=window.getSelection(),v=document.createRange();v.selectNodeContents(t),u.removeAllRanges(),u.addRange(v),a=u.toString()}return a}s.exports=o},279:function(s){function o(){}o.prototype={on:function(t,a,d){var u=this.e||(this.e={});return(u[t]||(u[t]=[])).push({fn:a,ctx:d}),this},once:function(t,a,d){var u=this;function v(){u.off(t,v),a.apply(d,arguments)}return v._=a,this.on(t,v,d)},emit:function(t){var a=[].slice.call(arguments,1),d=((this.e||(this.e={}))[t]||[]).slice(),u=0,v=d.length;for(u;u',Z='';let tt=document.querySelectorAll("#main-content pre");tt.forEach((r,h)=>{var w=document.createElement("div");["relative","code-block-wrapper"].forEach(o=>{w.classList.add(o)}),r.parentNode.insertBefore(w,r),w.appendChild(r);let g=document.createElement("button");g.innerHTML=P,g.id=`clipButton-${h}`,["md:block","hidden"].forEach(o=>{g.classList.add(o)}),g.setAttribute("aria-label","Copy to Clipboard"),g.setAttribute("title","Copy to Clipboard"),g.classList.add("copyBtn"),w.appendChild(g),new Q(`#${g.id}`).on("success",o=>{g.innerHTML=Z,o.clearSelection(),setTimeout(()=>{g.innerHTML=P},1500)});let s=r.querySelector("code");s.id=`clipText-${h}`,g.dataset.clipboardTarget=`#${s.id}`});window.toDarkMode=()=>{localStorage.theme="dark",window.updateTheme()};window.toLightMode=()=>{localStorage.theme="light",window.updateTheme()};window.toSystemMode=()=>{localStorage.theme="system",window.updateTheme()};window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",r=>{localStorage.theme==="system"&&(r.matches?(document.documentElement.classList.add("dark"),document.documentElement.setAttribute("data-theme","dark")):(document.documentElement.classList.remove("dark"),document.documentElement.setAttribute("data-theme","light"))),updateThemeAndSchemeColor()});document.addEventListener("DOMContentLoaded",()=>{et(),nt(),rt(),ot();const r=document.querySelector("#skip-to-content-link"),h=document.querySelector("#main-content");r.addEventListener("click",w=>{w.preventDefault(),h.setAttribute("tabindex",-1),h.focus()}),h.addEventListener("blur",()=>{h.removeAttribute("tabindex")})});function et(){[...document.querySelector(".docs_main").querySelectorAll("a[name]")].forEach(r=>{const h=r.parentNode.nextElementSibling;h.id=r.name,r.href=`#${r.name}`,r.removeAttribute("name"),[...h.childNodes].forEach(w=>r.appendChild(w)),h.appendChild(r)})}function nt(){[...document.querySelectorAll(".docs_sidebar h2")].forEach(r=>{r.addEventListener("click",h=>{h.preventDefault();const w=r.parentNode.classList.contains("sub--on");[...document.querySelectorAll(".docs_sidebar ul li")].forEach(g=>g.classList.remove("sub--on")),w||r.parentNode.classList.add("sub--on")})})}function rt(){[...document.querySelectorAll(".docs_main blockquote p")].forEach(r=>{N(r,/\{(.*?)\}/,h=>{switch(h){case"note":return["/img/callouts/exclamation.min.svg","bg-red-600",6,35];case"tip":return["/img/callouts/lightbulb.min.svg","bg-purple-600",28,40];case"laracasts":case"video":return["/img/callouts/laracast.min.svg","bg-blue-600",49,40];default:return[null,null,0,0]}}),N(r,/^\[\!(.*?)\](?:
\n?)?/,h=>{switch(h){case"WARNING":return["/img/callouts/exclamation.min.svg","bg-red-600",6,35];case"NOTE":return["/img/callouts/lightbulb.min.svg","bg-purple-600",28,40];default:return[null,null,0,0]}}),N(r,/^(.*?)<\/strong>(?:
\n?)?/,h=>{switch(h){case"Warning":return["/img/callouts/exclamation.min.svg","bg-red-600",6,35];case"Note":return["/img/callouts/lightbulb.min.svg","bg-purple-600",28,40];default:return[null,null,0,0]}})})}function N(r,h,w){var g=r.innerHTML,E=g.match(h),s,o,t,a;if(E)var d=E[1]||!1;if(d){if([s,o,t,a]=w(d),s===null&&o===null)return;const u=document.createElement("div");u.classList="mb-10 max-w-2xl mx-auto px-4 py-8 shadow-lg lg:flex lg:items-center";const v=document.createElement("div");v.classList=`w-20 h-20 mb-6 flex items-center justify-center shrink-0 ${o} lg:mb-0`;const p=document.createElement("img");p.src=s,p.height=a,p.width=t,p.loading="lazy",p.classList="opacity-75",v.appendChild(p),u.appendChild(v),r.parentNode.insertBefore(u,r),r.innerHTML=g.replace(h,""),r.classList="mb-0 lg:ml-6",u.classList.add("callout"),u.appendChild(r)}}function ot(){function r(g){const E=new Date().valueOf();Array.from(g.rows).forEach((s,o)=>{if(o>0){const t=s.cells,a=t[0],d=H(t[t.length-2]),u=H(t[t.length-1]);E>u?a.classList.add("bg-red-500","support-policy-highlight"):E<=u&&E>d&&a.classList.add("bg-orange-600","support-policy-highlight")}})}const h=document.querySelector(".docs_main #support-policy ~ div table:first-of-type");if(h){r(h);return}const w=document.querySelector(".docs_main #support-policy ~ table:first-of-type");w&&r(w)}function H(r){return Date.parse(r.innerHTML.replace(/(\d+)(st|nd|rd|th)/,"$1"))} diff --git a/public/build/assets/docs-8564cabe.js b/public/build/assets/docs-8564cabe.js new file mode 100644 index 00000000..63e1dd00 --- /dev/null +++ b/public/build/assets/docs-8564cabe.js @@ -0,0 +1,6 @@ +var J=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function W(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var R={exports:{}};/*! + * clipboard.js v2.0.10 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */(function(u,b){(function(h,E){u.exports=E()})(J,function(){return function(){var w={686:function(f,o,t){t.d(o,{default:function(){return G}});var c=t(279),l=t.n(c),d=t(370),g=t.n(d),v=t(817),S=t.n(v);function p(i){try{return document.execCommand(i)}catch{return!1}}var m=function(n){var e=S()(n);return p("cut"),e},y=m;function _(i){var n=document.documentElement.getAttribute("dir")==="rtl",e=document.createElement("textarea");e.style.fontSize="12pt",e.style.border="0",e.style.padding="0",e.style.margin="0",e.style.position="absolute",e.style[n?"right":"left"]="-9999px";var a=window.pageYOffset||document.documentElement.scrollTop;return e.style.top="".concat(a,"px"),e.setAttribute("readonly",""),e.value=i,e}var H=function(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},a="";if(typeof n=="string"){var r=_(n);e.container.appendChild(r),a=S()(r),p("copy"),r.remove()}else a=S()(n),p("copy");return a},O=H;function A(i){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?A=function(e){return typeof e}:A=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},A(i)}var j=function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=n.action,a=e===void 0?"copy":e,r=n.container,s=n.target,T=n.text;if(a!=="copy"&&a!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(s!==void 0)if(s&&A(s)==="object"&&s.nodeType===1){if(a==="copy"&&s.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(a==="cut"&&(s.hasAttribute("readonly")||s.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(T)return O(T,{container:r});if(s)return a==="cut"?y(s):O(s,{container:r})},q=j;function C(i){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?C=function(e){return typeof e}:C=function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},C(i)}function z(i,n){if(!(i instanceof n))throw new TypeError("Cannot call a class as a function")}function N(i,n){for(var e=0;e"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function x(i){return x=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},x(i)}function k(i,n){var e="data-clipboard-".concat(i);if(n.hasAttribute(e))return n.getAttribute(e)}var Y=function(i){I(e,i);var n=$(e);function e(a,r){var s;return z(this,e),s=n.call(this),s.resolveOptions(r),s.listenClick(a),s}return B(e,[{key:"resolveOptions",value:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof r.action=="function"?r.action:this.defaultAction,this.target=typeof r.target=="function"?r.target:this.defaultTarget,this.text=typeof r.text=="function"?r.text:this.defaultText,this.container=C(r.container)==="object"?r.container:document.body}},{key:"listenClick",value:function(r){var s=this;this.listener=g()(r,"click",function(T){return s.onClick(T)})}},{key:"onClick",value:function(r){var s=r.delegateTarget||r.currentTarget,T=this.action(s)||"copy",L=q({action:T,container:this.container,target:this.target(s),text:this.text(s)});this.emit(L?"success":"error",{action:T,text:L,trigger:s,clearSelection:function(){s&&s.focus(),document.activeElement.blur(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(r){return k("action",r)}},{key:"defaultTarget",value:function(r){var s=k("target",r);if(s)return document.querySelector(s)}},{key:"defaultText",value:function(r){return k("text",r)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return O(r,s)}},{key:"cut",value:function(r){return y(r)}},{key:"isSupported",value:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],s=typeof r=="string"?[r]:r,T=!!document.queryCommandSupported;return s.forEach(function(L){T=T&&!!document.queryCommandSupported(L)}),T}}]),e}(l()),G=Y},828:function(f){var o=9;if(typeof Element<"u"&&!Element.prototype.matches){var t=Element.prototype;t.matches=t.matchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector||t.webkitMatchesSelector}function c(l,d){for(;l&&l.nodeType!==o;){if(typeof l.matches=="function"&&l.matches(d))return l;l=l.parentNode}}f.exports=c},438:function(f,o,t){var c=t(828);function l(v,S,p,m,y){var _=g.apply(this,arguments);return v.addEventListener(p,_,y),{destroy:function(){v.removeEventListener(p,_,y)}}}function d(v,S,p,m,y){return typeof v.addEventListener=="function"?l.apply(null,arguments):typeof p=="function"?l.bind(null,document).apply(null,arguments):(typeof v=="string"&&(v=document.querySelectorAll(v)),Array.prototype.map.call(v,function(_){return l(_,S,p,m,y)}))}function g(v,S,p,m){return function(y){y.delegateTarget=c(y.target,S),y.delegateTarget&&m.call(v,y)}}f.exports=d},879:function(f,o){o.node=function(t){return t!==void 0&&t instanceof HTMLElement&&t.nodeType===1},o.nodeList=function(t){var c=Object.prototype.toString.call(t);return t!==void 0&&(c==="[object NodeList]"||c==="[object HTMLCollection]")&&"length"in t&&(t.length===0||o.node(t[0]))},o.string=function(t){return typeof t=="string"||t instanceof String},o.fn=function(t){var c=Object.prototype.toString.call(t);return c==="[object Function]"}},370:function(f,o,t){var c=t(879),l=t(438);function d(p,m,y){if(!p&&!m&&!y)throw new Error("Missing required arguments");if(!c.string(m))throw new TypeError("Second argument must be a String");if(!c.fn(y))throw new TypeError("Third argument must be a Function");if(c.node(p))return g(p,m,y);if(c.nodeList(p))return v(p,m,y);if(c.string(p))return S(p,m,y);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function g(p,m,y){return p.addEventListener(m,y),{destroy:function(){p.removeEventListener(m,y)}}}function v(p,m,y){return Array.prototype.forEach.call(p,function(_){_.addEventListener(m,y)}),{destroy:function(){Array.prototype.forEach.call(p,function(_){_.removeEventListener(m,y)})}}}function S(p,m,y){return l(document.body,p,m,y)}f.exports=d},817:function(f){function o(t){var c;if(t.nodeName==="SELECT")t.focus(),c=t.value;else if(t.nodeName==="INPUT"||t.nodeName==="TEXTAREA"){var l=t.hasAttribute("readonly");l||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),l||t.removeAttribute("readonly"),c=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var d=window.getSelection(),g=document.createRange();g.selectNodeContents(t),d.removeAllRanges(),d.addRange(g),c=d.toString()}return c}f.exports=o},279:function(f){function o(){}o.prototype={on:function(t,c,l){var d=this.e||(this.e={});return(d[t]||(d[t]=[])).push({fn:c,ctx:l}),this},once:function(t,c,l){var d=this;function g(){d.off(t,g),c.apply(l,arguments)}return g._=c,this.on(t,g,l)},emit:function(t){var c=[].slice.call(arguments,1),l=((this.e||(this.e={}))[t]||[]).slice(),d=0,g=l.length;for(d;d',Q='';let Z=document.querySelectorAll("#main-content pre");Z.forEach((u,b)=>{var w=document.createElement("div");["relative","code-block-wrapper"].forEach(o=>{w.classList.add(o)}),u.parentNode.insertBefore(w,u),w.appendChild(u);let h=document.createElement("button");h.innerHTML=D,h.id=`clipButton-${b}`,["md:block","hidden"].forEach(o=>{h.classList.add(o)}),h.setAttribute("aria-label","Copy to Clipboard"),h.setAttribute("title","Copy to Clipboard"),h.classList.add("copyBtn"),w.appendChild(h),new K(`#${h.id}`).on("success",o=>{h.innerHTML=Q,o.clearSelection(),setTimeout(()=>{h.innerHTML=D},1500)});let f=u.querySelector("code");f.id=`clipText-${b}`,h.dataset.clipboardTarget=`#${f.id}`});window.toDarkMode=()=>{localStorage.theme="dark",window.updateTheme()};window.toLightMode=()=>{localStorage.theme="light",window.updateTheme()};window.toSystemMode=()=>{localStorage.theme="system",window.updateTheme()};window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",u=>{localStorage.theme==="system"&&(u.matches?(document.documentElement.classList.add("dark"),document.documentElement.setAttribute("data-theme","dark")):(document.documentElement.classList.remove("dark"),document.documentElement.setAttribute("data-theme","light"))),updateThemeAndSchemeColor()});document.addEventListener("DOMContentLoaded",()=>{tt(),et(),nt();const u=document.querySelector("#skip-to-content-link"),b=document.querySelector("#main-content");u.addEventListener("click",w=>{w.preventDefault(),b.setAttribute("tabindex",-1),b.focus()}),b.addEventListener("blur",()=>{b.removeAttribute("tabindex")})});function tt(){[...document.querySelector(".docs_main").querySelectorAll("a[name]")].forEach(u=>{const b=u.parentNode.nextElementSibling;b.id=u.name,u.href=`#${u.name}`,u.removeAttribute("name"),[...b.childNodes].forEach(w=>u.appendChild(w)),b.appendChild(u)})}function et(){[...document.querySelectorAll(".docs_sidebar h2")].forEach(u=>{u.addEventListener("click",b=>{b.preventDefault();const w=u.parentNode.classList.contains("sub--on");[...document.querySelectorAll(".docs_sidebar ul li")].forEach(h=>h.classList.remove("sub--on")),w||u.parentNode.classList.add("sub--on")})})}function nt(){function u(h){const E=new Date().valueOf();Array.from(h.rows).forEach((f,o)=>{if(o>0){const t=f.cells,c=t[0],l=P(t[t.length-2]),d=P(t[t.length-1]);E>d?c.classList.add("bg-red-500","support-policy-highlight"):E<=d&&E>l&&c.classList.add("bg-orange-600","support-policy-highlight")}})}const b=document.querySelector(".docs_main #support-policy ~ div table:first-of-type");if(b){u(b);return}const w=document.querySelector(".docs_main #support-policy ~ table:first-of-type");w&&u(w)}function P(u){return Date.parse(u.innerHTML.replace(/(\d+)(st|nd|rd|th)/,"$1"))} diff --git a/public/build/assets/exclamation-c1673397.svg b/public/build/assets/exclamation-c1673397.svg new file mode 100644 index 00000000..c0d4398e --- /dev/null +++ b/public/build/assets/exclamation-c1673397.svg @@ -0,0 +1 @@ +exclamation diff --git a/public/build/assets/laracast-a56494c6.svg b/public/build/assets/laracast-a56494c6.svg new file mode 100644 index 00000000..83ea7b11 --- /dev/null +++ b/public/build/assets/laracast-a56494c6.svg @@ -0,0 +1 @@ +laracast \ No newline at end of file diff --git a/public/build/assets/lightbulb-ab2e1311.svg b/public/build/assets/lightbulb-ab2e1311.svg new file mode 100644 index 00000000..92ee3a63 --- /dev/null +++ b/public/build/assets/lightbulb-ab2e1311.svg @@ -0,0 +1 @@ +lightbulb \ No newline at end of file diff --git a/public/build/manifest.json b/public/build/manifest.json index 8410b3e9..c6bb8485 100644 --- a/public/build/manifest.json +++ b/public/build/manifest.json @@ -8,6 +8,10 @@ "file": "assets/diversity-inclusion-fc4ce0be.svg", "src": "resources/images/diversity-inclusion.svg" }, + "resources/images/exclamation.svg": { + "file": "assets/exclamation-c1673397.svg", + "src": "resources/images/exclamation.svg" + }, "resources/images/flexible-working-style.svg": { "file": "assets/flexible-working-style-399ea2b6.svg", "src": "resources/images/flexible-working-style.svg" @@ -20,6 +24,10 @@ "file": "assets/l11-background-blur-fcb5ac5e.png", "src": "resources/images/l11-background-blur.png" }, + "resources/images/laracast.svg": { + "file": "assets/laracast-a56494c6.svg", + "src": "resources/images/laracast.svg" + }, "resources/images/learn-and-grow.svg": { "file": "assets/learn-and-grow-bc3acbef.svg", "src": "resources/images/learn-and-grow.svg" @@ -28,6 +36,10 @@ "file": "assets/life-work-balance-8708d8f8.svg", "src": "resources/images/life-work-balance.svg" }, + "resources/images/lightbulb.svg": { + "file": "assets/lightbulb-ab2e1311.svg", + "src": "resources/images/lightbulb.svg" + }, "resources/images/perks.svg": { "file": "assets/perks-1c409941.svg", "src": "resources/images/perks.svg" @@ -42,7 +54,7 @@ "src": "resources/js/app.js" }, "resources/js/docs.js": { - "file": "assets/docs-7c75c91c.js", + "file": "assets/docs-8564cabe.js", "isEntry": true, "src": "resources/js/docs.js" } From 34f490a1bde8f91423bf842ce3355db79229f8fa Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 16 Jul 2024 09:07:06 +1000 Subject: [PATCH 3/3] Formatting --- app/Markdown/BlockQuoteRenderer.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Markdown/BlockQuoteRenderer.php b/app/Markdown/BlockQuoteRenderer.php index a1578a3c..6db8da9d 100644 --- a/app/Markdown/BlockQuoteRenderer.php +++ b/app/Markdown/BlockQuoteRenderer.php @@ -14,14 +14,15 @@ class BlockQuoteRenderer implements NodeRendererInterface { /** * @return \Stringable|string|null - * - * @throws InvalidArgumentException if the wrong type of Node is provided */ public function render(Node $node, ChildNodeRendererInterface $childRenderer) { $element = (new BaseBlockQuoteRenderer($node))->render($node, $childRenderer); - if (! $element instanceof HtmlElement || $element->getTagName() !== 'blockquote') { + if ( + ! $element instanceof HtmlElement || + $element->getTagName() !== 'blockquote' + ) { return $element; } @@ -31,9 +32,9 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) return $element; } - $htmlPartial = Str::after($html, '

'); + $paragraphPartial = Str::after($html, '

'); - if (preg_match('/^\[!(NOTE|WARNING)\](?:
)?/', $htmlPartial, $matches) === 1) { + if (preg_match('/^\[!(NOTE|WARNING)\](?:
)?/', $paragraphPartial, $matches) === 1) { // GitHub styled notes, e.g., // > [!NOTE] Content // or @@ -44,8 +45,8 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) 'WARNING' => [Vite::content('resources/images/exclamation.svg'), 'bg-red-600'], 'NOTE' => [Vite::content('resources/images/lightbulb.svg'), 'bg-purple-600'], }; - } elseif (preg_match('/^(Note|Warning):?<\/strong>:?(?:
)?/', $htmlPartial, $matches) === 1) { - // Legacy GitHub styled notes, e.g., + } elseif (preg_match('/^(Note|Warning):?<\/strong>:?(?:
)?/', $paragraphPartial, $matches) === 1) { + // Legacy GitHub styled notes, e.g., // > **Note:** Content // or // > **Note**: Content @@ -65,7 +66,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) 'Warning' => [Vite::content('resources/images/exclamation.svg'), 'bg-red-600'], 'Note' => [Vite::content('resources/images/lightbulb.svg'), 'bg-purple-600'], }; - } elseif (preg_match('/^\{(note|tip|video)\}/', $htmlPartial, $matches) === 1) { + } elseif (preg_match('/^\{(note|tip|video)\}/', $paragraphPartial, $matches) === 1) { // Legacy Laravel styled notes, e.g., // > {tip} Content @@ -78,14 +79,14 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) return $element; } - $bodyPartial = str_replace($matches[0], '', $htmlPartial); + $paragraphPartial = str_replace($matches[0], '', $paragraphPartial); return <<

{$asset}
-

{$bodyPartial} +

{$paragraphPartial}

HTML; }