Code & Equations
Code blocks
Potion uses highlight.js for syntax highlighting with base16-one-light as the default theme. A selection of light and dark themes can be used for your site.
CSS code
p {
color: #442200;
width: 500px;
border: 1px solid black;
}
p,
li,
h1 {
color: red;
}
bash script
#!/bin/bash
for i in /var/*; do
echo $i
done
for ((i = 0 ; i < 10 ; i++)); do
echo "Hello Friend"
done
Code blocks with captions
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Shows how to implement an AWS Lambda function that handles input from direct
invocation.
"""
# snippet-start:[python.example_code.lambda.handler.arithmetic]
import logging
import os
logger = logging.getLogger()
# Define a list of Python lambda functions that are called by this AWS Lambda function.
ACTIONS = {
"plus": lambda x, y: x + y,
"minus": lambda x, y: x - y,
"times": lambda x, y: x * y,
"divided-by": lambda x, y: x / y,
}
def lambda_handler(event, context):
"""
Accepts an action and two numbers, performs the specified action on the numbers,
and returns the result.
:param event: The event dict that contains the parameters sent when the function
is invoked.
:param context: The context in which the function is called.
:return: The result of the specified action.
"""
# Set the log level based on a variable configured in the Lambda environment.
logger.setLevel(os.environ.get("LOG_LEVEL", logging.INFO))
logger.debug("Event: %s", event)
action = event.get("action")
func = ACTIONS.get(action)
x = event.get("x")
y = event.get("y")
result = None
try:
if func is not None and x is not None and y is not None:
result = func(x, y)
logger.info("%s %s %s is %s", x, action, y, result)
else:
logger.error("I can't calculate %s %s %s.", x, action, y)
except ZeroDivisionError:
logger.warning("I can't divide %s by 0!", x)
response = {"result": result}
return response
# snippet-end:[python.example_code.lambda.handler.arithmetic]
const testElements = document.getElementsByClassName("test");
const testDivs = Array.prototype.filter.call(
testElements,
(testElement) => testElement.nodeName === "DIV",
);
<html lang="en">
<body>
<div id="parent-id">
<p>hello world 1</p>
<p class="test">hello world 2</p>
<p>hello world 3</p>
<p>hello world 4</p>
</div>
<script>
const parentDOM = document.getElementById("parent-id");
// a list of matching elements, *not* the element itself
const test = parentDOM.getElementsByClassName("test");
console.log(test);
const testTarget = parentDOM.getElementsByClassName("test")[0];
console.log(testTarget);
</script>
</body>
</html>
Equations
We can do inline equations like this ∑n=1∞2−n=1 or show a simple integral ∫abx2dx
A first equation block
sZsZ2sZ2sZ2sZ2sZ2sZ2sZ2sZ=N−1∑i=1N(Zi−MZ)2=N−1∑i=1N(Zi−0)2=N−11i=1∑NZi2=N−11i=1∑N(sXi−MX)2=N−11×s21×i=1∑N(Xi−MX)2=s21×N−1∑i=1N(Xi−MX)2=s21×s2=1=1=1
Two equation blocks one after the other
Ab↓⏐ CaB⏐↑cD
MZMZ=N∑i=1NZi=N1i=1∑N(sXi−MX)=sN1i=1∑N(Xi−MX)=sN1(i=1∑NXi−NMX)=s1(N∑i=1NXi−MX)=s1(MX−MX)=0