> For the complete documentation index, see [llms.txt](https://docs.vale.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vale.sh/topics/markup.md). Agents can also search and read this documentation through its [MCP server](https://docs.vale.sh/~gitbook/mcp).

# Markup

Learn how a rule reads a page as it is written: its headings, lists, fences, and links, with their markers and indentation.

{% hint style="info" %}
Requires Vale v3.30.0 or later.
{% endhint %}

Vale reads markup to find the prose in it, and most rules are about that prose. A rule about the markup itself (how a heading is written, how far a list is indented, whether a code block says which language it's in) needs the page as the author typed it. `raw` beside a [`doc(...)` selection](https://docs.vale.sh/topics/scopes.md#selections) gives a rule exactly that, one block at a time:

```yaml
# styles/House/CodeBlocks.yml
extends: metric
message: "Put a blank line after this code block."
level: warning
scope: 'raw & doc(pre.fenced)'
formula: blank_after < 1 && last == 0
```

No new kind of rule is involved. `existence`, `metric`, `consistency`, `conditional`, `occurrence`, and `script` rules all work on these scopes, and so do [actions](https://docs.vale.sh/topics/actions.md), comments that switch a rule off, and [parameters](https://docs.vale.sh/topics/styles.md#parameters).

## [Blocks as written](#blocks-as-written)

`raw` alone is the whole file as one string. Beside a `doc(...)` term it is narrowed, as any scope is, to the blocks the selector matches. Each block is the lines the page writes it on, markers and all:

| Scope             | The rule reads                                               |
| ----------------- | ------------------------------------------------------------ |
| `raw`             | The whole file, as one block.                                |
| `doc(h2)`         | The prose of each second-level heading: `Install Vale`.      |
| `raw & doc(h2)`   | Each second-level heading as written: `## Install **Vale**`. |
| `raw & ~doc(pre)` | Every block as written except code blocks.                   |

```yaml
extends: existence
message: "Write headings with '#'."
level: error
nonword: true
scope: 'raw & doc(h1, h2)'
tokens:
  - '^(=+|-+)[ \t]*$'
```

```yaml
extends: existence
message: "Remove the trailing space."
level: warning
nonword: true
scope: 'raw & ~doc(pre)'
tokens:
  - '[ \t]+$'
```

```yaml
extends: existence
message: "Use '-' for a list, not '%s'."
level: warning
nonword: true
scope: 'raw & doc(ul) & ~doc(pre)'
tokens:
  - '^[ \t]*[*+](?= )'
```

Because each block has a place in the file, a rule on one behaves like any other rule:

* The alert is reported on the line and column the match is written on.
* A line belongs to the innermost block written on it, so code inside a list item is left out with the rest of the code.
* A [comment](https://docs.vale.sh/topics/.vale.ini.md#markup-based-configuration) switches the rule off from where it is written until one switches it back on.
* Front matter is not one of a page's blocks. A rule reads it with [`raw & frontmatter`](#front-matter-and-footnotes).

A pattern on a block as written is used as it is: `^` and `$` match at each line, and `\A` and `\z` at the block's ends.

### [Selectors](#selectors)

The selector is the same CSS that a [`doc(...)` selection](https://docs.vale.sh/topics/scopes.md#selections) takes, with a few names for what a page has and CSS doesn't:

| Selector       | Matches                                                     |
| -------------- | ----------------------------------------------------------- |
| `:heading`     | A heading of any level.                                     |
| `:first-block` | The block a page opens with, after any front matter.        |
| `::first-line` | Where the element opens, in place of every block inside it. |
| `pre.fenced`   | A fenced code block. `pre` alone includes indented code.    |

`::first-line` matters for an element that holds other blocks. `raw & doc(li)` reaches every block inside a list item; `raw & doc(li::first-line)` is the item's own first line, where its marker is:

```yaml
extends: metric
message: "Number list items in order."
level: warning
scope: 'raw & doc(ol > li::first-line)'
formula: number != item
```

### [A scope as the whole rule](#a-scope-as-the-whole-rule)

On a part of the page as written, an `existence` rule doesn't need `tokens`. It reports what its scope selects, where that starts:

```yaml
extends: existence
message: "Open the page with a title."
level: error
scope: 'raw & doc(:first-block:not(h1)::first-line)'
```

`raw` alone, and any scope of prose, still require `tokens`.

## [Layout](#layout)

Some rules are about lines and gaps, not characters. A block as written has counts that a [`metric`](https://docs.vale.sh/checks/metric.md) formula reads by name:

```yaml
extends: metric
message: "Put a blank line before a heading."
level: warning
scope: 'raw & doc(:heading)'
formula: blank_before < 1 && first == 0
```

```yaml
extends: metric
message: "Don't skip a heading level."
level: error
scope: 'raw & doc(:heading)'
formula: heading_prev > 0 && heading_level > heading_prev + 1
```

A formula that is a comparison is the whole test: the rule reports each block it's true of. When the formula is a number, bound it with `max` or `min`, which a configuration can then set:

```yaml
# styles/House/LineLength.yml
extends: metric
message: "Keep lines to 80 characters."
level: suggestion
scope: 'raw & doc(p, li)'
formula: width
max: 80
```

```ini
House.LineLength[max] = 100
```

A count taken on one line of a block, such as `width`, is reported on that line, and every line out of bounds is reported.

### [Any block](#any-block)

| Count                         | Meaning                                                                                                                 |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `line`                        | The line the block starts on.                                                                                           |
| `lines`                       | How many lines it has.                                                                                                  |
| `indent`                      | The first line's indentation. In a quotation, counted from the `>`.                                                     |
| `width`                       | Its longest line, in characters.                                                                                        |
| `wrap`                        | How far along a line its last word starts, at most. A line is too long when it could have been broken before the limit. |
| `blank_before`, `blank_after` | The blank lines above and below it. A line of spaces is blank, and so is a quotation's `>` on its own.                  |
| `comment_before`              | How many of the lines above it hold a comment.                                                                          |
| `first`, `last`               | 1 when nothing is written before it, or after it. Front matter doesn't count: the block under it is first.              |
| `after_front_matter`          | 1 for the block written right under the front matter.                                                                   |
| `front_matter`                | How many lines of front matter the page opens with.                                                                     |

### [Headings and fences](#headings-and-fences)

| Count                 | Meaning                                                         |
| --------------------- | --------------------------------------------------------------- |
| `heading_level`       | The heading's level, 1 to 6.                                    |
| `heading_prev`        | The level of the heading before it, and 0 for the page's first. |
| `heading_seen`        | How many headings above it on the page say the same thing.      |
| `heading_seen_beside` | How many of its siblings above it say the same thing.           |
| `fence_closed`        | 1 when a fenced block is closed by a line of its own.           |

### [Lists](#lists)

| Count                                      | Meaning                                                                                     |
| ------------------------------------------ | ------------------------------------------------------------------------------------------- |
| `item`                                     | An ordered item's place in its list, from 1.                                                |
| `number`                                   | The number the item is written with.                                                        |
| `number_width`                             | How many digits that number has.                                                            |
| `marker_space`                             | The spaces after the item's marker.                                                         |
| `list_item`                                | Which item of its list this is, from 1.                                                     |
| `list_depth`                               | How deep in lists the block is, from 0, and -1 outside one.                                 |
| `list_begin`, `list_end`                   | 1 when the block opens, or ends, the outermost list it is in.                               |
| `list_indent`, `list_start`, `list_second` | The first item's indentation and number, and the second item's number.                      |
| `list_loose`, `list_tight`                 | How many of the items after the first have a blank line above them, and how many have none. |
| `list_split`                               | 1 when an item contains a block with a blank line above it.                                 |
| `list_single`                              | 1 when every item is one line with nothing between them.                                    |
| `list_aligned`                             | 1 when every item's number ends in the same column.                                         |
| `list_after_list`                          | 1 when the item above this one ends with a list of its own.                                 |

### [Table rows](#table-rows)

A formula on a table can be asked of each row, and every row it's true of is reported:

| Count          | Meaning                          |
| -------------- | -------------------------------- |
| `row`          | Which line of the block this is. |
| `cells`        | How many cells the row has.      |
| `header_cells` | How many the first row has.      |

```yaml
extends: metric
message: "Give this row as many cells as the header."
level: error
scope: 'raw & doc(table)'
formula: cells != header_cells
```

A [`script`](https://docs.vale.sh/checks/script.md#the-page-as-written) reads the same counts by name, and more of the table.

## [Inside a block](#inside-a-block)

A block as written holds smaller things: code spans, links, emphasis. A scope beside `raw` reads one of them, or leaves it out:

| Scope                | What it is                                                                                               |
| -------------------- | -------------------------------------------------------------------------------------------------------- |
| `code`               | A code span, from its opening backticks to its closing ones.                                             |
| `link`               | Anything written as a link. See [Links](#links).                                                         |
| `url`                | Where a link goes. An address written on its own, with no link around it, is `url.bare`.                 |
| `label`              | The label a reference link refers to, and the one it is defined under.                                   |
| `emphasis`, `strong` | An emphasis, from its opening marker to its closing one. One inside a word is also `emphasis.intraword`. |
| `delimiter`          | A pair of emphasis markers that didn't make emphasis, `* like this *`.                                   |
| `math`               | Math between dollar signs.                                                                               |
| `html`               | An HTML tag.                                                                                             |
| `comment`            | An HTML comment.                                                                                         |
| `info`               | A fence's info string.                                                                                   |

```yaml
extends: existence
message: "Use 'main', not '%s'."
level: warning
nonword: true
ignorecase: true
scope: 'raw & doc(p, li) & code'
tokens:
  - '\A`master`\z'
```

```yaml
extends: existence
message: "Remove the spaces inside these markers."
level: warning
scope: 'raw & delimiter'
```

Negated, the same names say what a rule about markup doesn't mean. A tag shown in a code span is an example of HTML, not HTML:

```yaml
scope: 'raw & doc(p, li) & ~code & ~comment'
```

Each is found where the page's parser found one, so a code block has none and neither does text behind a backslash.

### [In each format](#in-each-format)

`code`, `emphasis`, `strong`, `link`, and `url` are read as each format writes them, so one rule works in all of them:

| Scope      | Markdown     | AsciiDoc                    | reStructuredText   | Org            | Typst               | LaTeX             |
| ---------- | ------------ | --------------------------- | ------------------ | -------------- | ------------------- | ----------------- |
| `code`     | `` `x` ``    | `` `x` ``, `+x+`            | ` ``x`` `          | `~x~`, `=x=`   | `` `x` ``           | `\texttt{x}`      |
| `emphasis` | `*x*`, `_x_` | `_x_`                       | `*x*`              | `/x/`          | `_x_`               | `\emph{x}`        |
| `strong`   | `**x**`      | `*x*`                       | `**x**`            | `*x*`          | `*x*`               | `\textbf{x}`      |
| `link`     | `[text](to)` | `to[text]`, `xref:to[text]` | `` `text <to>`_ `` | `[[to][text]]` | `#link("to")[text]` | `\href{to}{text}` |

In HTML they are the elements themselves: `<code>`, `<em>`, `<strong>`, and `<a>`.

The other scopes in the table above name things only Markdown writes, and find nothing in another format. The same goes for a link's states. `code` alone, without `raw`, is still the [prose scope](https://docs.vale.sh/topics/scopes.md#inline-elements): a span's text without its backticks.

### [Links](#links)

A link says how it is written, and a reference link whether its label is defined:

| Scope             | Written as              |
| ----------------- | ----------------------- |
| `link.inline`     | `[text](target)`        |
| `link.full`       | `[text][label]`         |
| `link.collapsed`  | `[label][]`             |
| `link.shortcut`   | `[label]`               |
| `link.autolink`   | `<https://example.com>` |
| `link.definition` | `[label]: target`       |

`link.full`, `link.collapsed`, and `link.shortcut` are also `.defined` or `.undefined`. A `link.definition` that no link uses is `.unused`, and one that repeats an earlier label is `.duplicate`.

```yaml
extends: existence
message: "No definition on this page has this label."
level: error
scope: 'raw & link.full.undefined'
```

```yaml
extends: existence
message: "Say where '%s' goes."
level: warning
nonword: true
ignorecase: true
scope: 'raw & doc(p, li) & link.inline'
tokens:
  - '\A\[(here|this|this page)\]'
```

## [Front matter and footnotes](#front-matter-and-footnotes)

`raw & frontmatter` is the front matter as written, from its opening line to its closing one, with a block's counts. The keys inside it are still read with [`frontmatter.<key>`](https://docs.vale.sh/formats/front-matter.md).

```yaml
extends: metric
message: "Put a blank line after the front matter."
level: warning
scope: 'raw & frontmatter'
formula: blank_after < 1 && last == 0
```

`raw & footnote.definition` is a footnote's definition with the lines under it that are written further in, and `raw & footnote.reference` is each place one is referred to. A definition with no text is still one, so a rule can find it:

```yaml
extends: existence
message: "Give this footnote some text."
level: error
nonword: true
scope: 'raw & footnote.definition'
tokens:
  - '\A\[\^[^\]]+\]:[ \t]*\z'
```

## [A page's data](#a-pages-data)

A link's target, or the language of a fence, is data. It is collected under the [`meta` scope](https://docs.vale.sh/topics/scopes.md#metadata) in every format, where prose rules pass over it:

| Scope                                                  | Holds                                                                                                                  |
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| `meta.class.url`                                       | A link's target.                                                                                                       |
| `meta.class.image`                                     | An image's source.                                                                                                     |
| `meta.class.language`                                  | The language of a code block.                                                                                          |
| `meta.class.anchor`                                    | Each id a link can point at, as the format makes it.                                                                   |
| `meta.class.definition`                                | Each label a Markdown page defines.                                                                                    |
| `meta.class.footnote`, `meta.class.footnote-reference` | The label of each footnote a Markdown page defines, and of each place one is used.                                     |
| `meta.class.reference`                                 | Each label a Markdown page uses. Only [`in`](https://docs.vale.sh/checks/conditional.md#across-a-pages-data) reads it. |

```yaml
extends: existence
message: "Link to the 'https' address."
level: warning
nonword: true
scope: meta.class.url
tokens:
  - '^http://'
```

A link with no target and a fence with no language are empty blocks where they are written, so an `occurrence` rule reports what is missing. Indented code can't say its language, so it isn't reported.

```yaml
extends: occurrence
message: "Name the language of this code block."
level: warning
scope: meta.class.language
min: 1
token: '\S'
```

A [`conditional`](https://docs.vale.sh/checks/conditional.md) rule with `in` compares two of them, which is how a fragment is checked against the page's headings:

```yaml
extends: conditional
message: "No heading on this page is '%s'."
level: error
scope: meta.class.url
first: '(?<=^#).+$'
second: '^(.+)$'
in: meta.class.anchor
```

## [One way on a page](#one-way-on-a-page)

A [`consistency`](https://docs.vale.sh/checks/consistency.md) rule with `first` keeps a page to whichever way of writing something it uses first, and reports each place the other appears:

```yaml
extends: consistency
message: "Write emphasis one way on a page."
level: warning
nonword: true
first: true
scope: 'raw & emphasis & ~emphasis.intraword'
either:
  '\A\*': '\A_'
```

## [Formats](#formats)

`raw & doc(...)` is a page's blocks as written in every markup format. Markdown and its dialects get each block's lines from the parser. In the others, a block is placed by its text.

| Construct                                                        | Markdown, MDX, Quarto, MyST, Markdoc, R Markdown | AsciiDoc | reStructuredText | Org | HTML |            Typst            |            LaTeX            |
| ---------------------------------------------------------------- | :----------------------------------------------: | :------: | :--------------: | :-: | :--: | :-------------------------: | :-------------------------: |
| Heading, paragraph, list, table, code block, quotation           |                         ✓                        |     ✓    |         ✓        |  ✓  |   ✓  |              ✓              |              ✓              |
| Rule                                                             |                         ✓                        |     ✓    |         ✓        |  ✓  |   ✓  |              ✓              |           not read          |
| Code in a list item                                              |                         ✓                        |     ✓    |         ✓        |  ✓  |   ✓  | not separated from its item | not separated from its item |
| A link's target, an image's source, the language of a code block |                         ✓                        |     ✓    |         ✓        |  ✓  |   ✓  |              ✓              |              ✓              |

The scopes [inside a block](#in-each-format) that every format writes are read in each of them. The link states and footnotes are read from Markdown and its dialects.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.vale.sh/topics/markup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
