On this page
Markdown Code Blocks: Syntax Highlighting and Customization
Learn how to use Markdown’s code block features, including syntax highlighting with Prism and customization options.
Syntax Highlighting
Syntax highlighting is supported by Prism (the default). It can be disabled in favour of Hugo’s buil-tin syntax highlighter, Chroma.
code fences - bash
Syntax:
```bash
curl -X POST -is "http://localhost:4242/create-checkout-session" -d ""
```
Output:
curl -X POST -is "http://localhost:4242/create-checkout-session" -d ""
code fences - JavaScript
Syntax:
```JavaScript {linenos=inline,linenostart=19,hl_lines=[1,"4-5"],anchorlinenos=true}
function foo(bar) {
var a = 42,
b = "Prism";
return a + bar(b);
}
```
Output:
function foo(bar) {
var a = 42,
b = "Prism";
return a + bar(b);
}
code fences - html
Syntax:
```html
<html>
<head>
<title>Buy cool new product</title>
</head>
<body>
<!-- Use action="/create-checkout-session.php" if your server is PHP based. -->
<form action="/create-checkout-session" method="POST">
<button type="submit">Checkout</button>
</form>
</body>
</html>
```
Output:
<html>
<head>
<title>Buy cool new product</title>
</head>
<body>
<!-- Use action="/create-checkout-session.php" if your server is PHP based. -->
<form action="/create-checkout-session" method="POST">
<button type="submit">Checkout</button>
</form>
</body>
</html>
code fences - swift
Syntax:
```swift
let cardParams = STPCardParams()
cardParams.name = "Jenny Rosen"
cardParams.number = "4242424242424242"
cardParams.expMonth = 12
cardParams.expYear = 18
cardParams.cvc = "424"
let sourceParams = STPSourceParams.cardParams(withCard: cardParams)
STPAPIClient.shared.createSource(with: sourceParams) { (source, error) in
if let s = source, s.flow == .none && s.status == .chargeable {
self.createBackendChargeWithSourceID(s.stripeID)
}
}
```
Output:
let cardParams = STPCardParams()
cardParams.name = "Jenny Rosen"
cardParams.number = "4242424242424242"
cardParams.expMonth = 12
cardParams.expYear = 18
cardParams.cvc = "424"
let sourceParams = STPSourceParams.cardParams(withCard: cardParams)
STPAPIClient.shared.createSource(with: sourceParams) { (source, error) in
if let s = source, s.flow == .none && s.status == .chargeable {
self.createBackendChargeWithSourceID(s.stripeID)
}
}
code fences - treeview
Syntax:
```treeview
├── fonts/
├── images/
├── js/
│ ├── vendor/
│ ├── app.js
│ └── index.js
├── lambda/
└── scss/
├── common/
├── components/
├── layouts/
├── vendor/
└── app.scss
```
Output:
├── fonts/
├── images/
├── js/
│ ├── vendor/
│ ├── app.js
│ └── index.js
├── lambda/
└── scss/
├── common/
├── components/
├── layouts/
├── vendor/
└── app.scss
prism shortcode - go
This only applies to Homelab-Alpha website
Syntax:
package
main
import ( "net/http"
"github.com/labstack/echo" "github.com/labstack/echo/middleware"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/checkout/session" )
// This example sets up an endpoint using the Echo framework. // Watch this
video to get started: <https://youtu.be/ePmEVBu8w6Y>.
func main() { stripe.Key = "UfXXWzQ2B1yVX57GU3QV8EQyTizMUvUm"
e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover())
e.POST("/create-checkout-session", createCheckoutSession)
e.Logger.Fatal(e.Start("localhost:4242")) }
func createCheckoutSession(c echo.Context) (err error) { params :=
&stripe.CheckoutSessionParams{ Mode:
stripe.String(string(stripe.CheckoutSessionModePayment)), LineItems:
[]\*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{
PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{ Currency:
stripe.String("usd"), ProductData:
&stripe.CheckoutSessionLineItemPriceDataProductDataParams{ Name:
stripe.String("T-shirt"), }, UnitAmount: stripe.Int64(2000), }, Quantity:
stripe.Int64(1), }, }, SuccessURL:
stripe.String("<http://localhost:4242/success>"), CancelURL:
stripe.String("<http://localhost:4242/cancel>"), }
s, \_ := session.New(params)
if err != nil { return err }
return c.Redirect(http.StatusSeeOther, s.URL) }
Output:
package
main
import ( "net/http"
"github.com/labstack/echo" "github.com/labstack/echo/middleware"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/checkout/session" )
// This example sets up an endpoint using the Echo framework. // Watch this
video to get started: <https://youtu.be/ePmEVBu8w6Y>.
func main() { stripe.Key = "UfXXWzQ2B1yVX57GU3QV8EQyTizMUvUm"
e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover())
e.POST("/create-checkout-session", createCheckoutSession)
e.Logger.Fatal(e.Start("localhost:4242")) }
func createCheckoutSession(c echo.Context) (err error) { params :=
&stripe.CheckoutSessionParams{ Mode:
stripe.String(string(stripe.CheckoutSessionModePayment)), LineItems:
[]\*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{
PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{ Currency:
stripe.String("usd"), ProductData:
&stripe.CheckoutSessionLineItemPriceDataProductDataParams{ Name:
stripe.String("T-shirt"), }, UnitAmount: stripe.Int64(2000), }, Quantity:
stripe.Int64(1), }, }, SuccessURL:
stripe.String("<http://localhost:4242/success>"), CancelURL:
stripe.String("<http://localhost:4242/cancel>"), }
s, \_ := session.New(params)
if err != nil { return err }
return c.Redirect(http.StatusSeeOther, s.URL) }
prism shortcode - JavaScript
This only applies to Homelab-Alpha website
Syntax:
function foo(bar) { var a = 42, b = 'Prism'; return a + bar(b); }
Output:
function foo(bar) { var a = 42, b = 'Prism'; return a + bar(b); }
Last updated 22 Sep 2024, 12:15 CEST .