Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mention of the .class syntax for source code #842

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/authoring/markdown-basics.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ code
```
````

Equivalent to the short form used in the examples above is a longer form that uses the language as a class (i.e. `.python`) inside braces:

```` markdown
```{.python}
1 + 1
```
````

The longer form allows you to add attributes to the block in a similar way to [Divs](#sec-divs-and-spans). Some specific features that use this syntax are [Lines Numbers](/docs/output-formats/html-code.qmd#line-numbers) and [Code Filename](/docs/output-formats/html-code.qmd#code-filename). Here is an example of the latter:

```` markdown
```{.python filename="run.py"}
code
```
````

If you are creating HTML output there is a wide variety of options available for code block output. See the article on [HTML Code](/docs/output-formats/html-code.qmd) for additional details.

## Equations
Expand Down Expand Up @@ -268,7 +284,7 @@ Videos can refer to video files (e.g. MPEG) or can be links to videos published

{{< include _pagebreak.qmd >}}

## Divs and Spans
## Divs and Spans {#sec-divs-and-spans}

You can add classes, attributes, and other identifiers to regions of content using Divs and Spans (you'll see an example of this below in [Callout Blocks]).

Expand Down
4 changes: 2 additions & 2 deletions docs/output-formats/html-code.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ code-block-border-left: "#31BAE9"

![](images/code-custom.png){fig-alt="A block of code with a gray background and a blue vertical stripe running along its left border."}

## Code Filename
## Code Filename {#code-filename}

Use the `filename` attribute on code blocks If you are documenting the contents of a file and want to be especially clear about the name of the file the code is associated with.

Expand Down Expand Up @@ -317,7 +317,7 @@ Note that as with adaptive text higlighting themes, when you provide a dark and

{{< include _code-annotation.md >}}

## Line Numbers
## Line Numbers {#line-numbers}

If you want to display line numbers alongside the code block, add the `code-line-numbers` option. For example:

Expand Down
Loading