Literal include (::literal-include)
The ::literal-include directive displays the contents of a file inside a code block, optionally with syntax highlighting.
When to use
Use ::literal-include to show real, runnable source (a Python module, a config file) in a code block without copying it into the page, so the documented code stays in sync with the actual file. Use Include instead to inline rendered Markdown rather than show a file as code.
Technical details
::literal-include[<filepath>]
OR
::literal-include[<filepath>]{language='<language>'}
The filepath is relative to the docs/web/includes/ directory, and the included file must exist within that directory. A syntax-highlighting language may optionally be specified via the language option.
Rules
- The filepath is relative to
docs/web/includes/, and the file must exist there. - The
languageoption is optional; when omitted, the code block has no syntax highlighting.
Style
- Set
languagewhenever the file has a known language so the code block is highlighted.
Template
::literal-include[filepath]{language='python'}
Examples
Example:
::literal-include[code-examples/unit-testing/myfunctions.py]
::literal-include[code-examples/unit-testing/myfunctions.py]{language='python'}
Output:
import pyspark
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
# Because this file is not a Databricks notebook, you
# must create a Spark session. Databricks notebooks
# create a Spark session for you by default.
spark = SparkSession.builder \
.appName('integrity-tests') \
.getOrCreate()
# Does the specified table exist in the specified database?
def tableExists(tableName, dbName):
return spark.catalog.tableExists(f"{dbName}.{tableName}")
# Does the specified column exist in the given DataFrame?
def columnExists(dataFrame, columnName):
if columnName in dataFrame.columns:
return True
else:
return False
# How many rows are there for the specified value in the specified column
# in the given DataFrame?
def numRowsInColumnForValue(dataFrame, columnName, columnValue):
df = dataFrame.filter(col(columnName) == columnValue)
return df.count()
import pyspark
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
# Because this file is not a Databricks notebook, you
# must create a Spark session. Databricks notebooks
# create a Spark session for you by default.
spark = SparkSession.builder \
.appName('integrity-tests') \
.getOrCreate()
# Does the specified table exist in the specified database?
def tableExists(tableName, dbName):
return spark.catalog.tableExists(f"{dbName}.{tableName}")
# Does the specified column exist in the given DataFrame?
def columnExists(dataFrame, columnName):
if columnName in dataFrame.columns:
return True
else:
return False
# How many rows are there for the specified value in the specified column
# in the given DataFrame?
def numRowsInColumnForValue(dataFrame, columnName, columnValue):
df = dataFrame.filter(col(columnName) == columnValue)
return df.count()
Used in
Content atoms appear in any page section. Literal includes are common in Procedure and tutorials, where documented code should match a real source file.