]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
docs: improve stackblitz.js
authorXhmikosR <xhmikosr@gmail.com>
Wed, 2 Aug 2023 07:38:19 +0000 (10:38 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 19 Mar 2024 09:25:15 +0000 (11:25 +0200)
* tweak indentation
* stop extending the sdk object
* conditionally add `index.js`

site/assets/js/stackblitz.js

index c6f44b0f4f27ed15bb90317e5794020bfb0ee919..54eca3e21ab50581bcfcdd2a9555462acbf19d37 100644 (file)
@@ -28,12 +28,12 @@ document.querySelectorAll('.btn-edit').forEach(btn => {
     // Get extra classes for this example
     const classes = Array.from(exampleEl.classList).join(' ')
 
-    sdk.openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
+    openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
   })
 })
 
-sdk.openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
-  const markup = `<!doctype html>
+const openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
+  const indexHtml = `<!doctype html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
@@ -44,18 +44,17 @@ sdk.openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
     <${'script'} src="${jsBundleCdn}"></${'script'}>
   </head>
   <body class="p-3 m-0 border-0 ${classes}">
-
-    <!-- Example Code -->
-${htmlSnippet.replace(/^/gm, '    ')}
-    <!-- End Example Code -->
+    <!-- Example Code Start-->
+${htmlSnippet.trimStart().replace(/^/gm, '    ').replace(/^ {4}$/gm, '').trimEnd()}
+    <!-- Example Code End -->
   </body>
-</html>`
+</html>
+`
 
-  const jsSnippetContent = jsSnippet ? jsSnippetFile : null
   const project = {
     files: {
-      'index.html': markup,
-      'index.js': jsSnippetContent
+      'index.html': indexHtml,
+      ...(jsSnippet && { 'index.js': jsSnippetFile })
     },
     title: 'Bootstrap Example',
     description: `Official example from ${window.location.href}`,