.docname {Element styling}
.include {docs}

If you've used Typst, you may be familiar with the `#show` directive for styling elements. .br
Quarkdown provides a similar, powerful mechanism that involves [function extensions](extending-functions.qd), allowing you to customize not only their appearance, but also their behavior and content.

Several Markdown elements are associated to a special function called *primitive*. For example, headings (`#`, `##`, etc.) are backed by the `.heading` primitive function.
Extending a primitive allows you to intercept and alter the call itself through `.super`, which invokes the original function with optional overrides.

> Tip: For a full list of supported primitives, see the [*Primitives*](https://quarkdown.com/docs/quarkdown-stdlib/com.quarkdown.stdlib.module.Primitives/index.html) module.

.exampleoutput {.heading {This is red} depth:{2} background:{red} indexed:{no}}
    .extend {heading}
        .super background:{red}

    ## This is red

> Tip: For a list of styling properties supported by most primitives, see [*Styling properties*](element-styling-properties.qd).

## Conditional styling

The `where` parameter allows you to apply styling conditionally based on the arguments of the original function call.

.exampleoutput {
    .heading {This is red} depth:{2} background:{red} indexed:{no}

    .heading {This is not red} depth:{3} indexed:{no}
}
    .extend {heading} where:{depth: .depth::equals {2}}
        .super background:{red}

    ## This is red (depth 2)

    ### This is not red (depth 3)

Any argument of the intercepted call can be used in the condition, for example [cross-reference identifiers](cross-references.qd) via `ref`:

.exampleoutput {
    .math {E=mc^2} block:{yes} foreground:{skyblue} fontsize:{larger}

    .math {F=ma} block:{yes}
}
    .extend {math} where:{ref: .ref::startswith {einstein}}
        .super foreground:{skyblue} fontsize:{larger}

    $ E=mc^2 $ {#einstein-relativity}

    $ F=ma $

## Content changes

Intercepted parameters can also be modified on the go. A common use case would be transforming the Markdown content of an element. 

.exampleoutput {Check out the [docs](https://quarkdown.com/docs) and the [repo .icon {box-arrow-up-right}](https://github.com/iamgio/quarkdown)} \
               prelude:{Here we add an [icon](icons.qd) to all external links. Note that [body arguments](syntax-of-a-function-call.qd#the-body-argument) work with `\.super` normally.}
    .extend {link} where:{url: .url::startswith {https://quarkdown.com}::not}
        content:
        .super
            .content .icon {box-arrow-up-right}

    Check out the [docs](https://quarkdown.com/docs)
    and the [repo](https://github.com/iamgio/quarkdown)

## Pattern matching

Quarkdown supports transforming arbitrary content according to RegEx patterns via the **`.match {content} {pattern} {replacement}`** .docslink {quarkdown-stdlib/com.quarkdown.stdlib.module.Text/match.html} function, which replaces all occurrences of `pattern` within `content` with `replacement`.

.exampleoutput {***Quarkdown*** takes its name from ***quarks***}
    .extend {paragraph}
        content:
        .super
            .content::match {[Qq]uark(down|s)?}
                ***.1***

    Quarkdown takes its name from quarks