Skip to content

Extensions

carve-php bundles a set of optional extensions - from autolinking and mentions to tabs, math and citations. This package lets you enable them per converter profile in config/carve.php, by name or with options.

For what each extension does (syntax, output, options), see the carve-php extension documentation. For which features are core vs. opt-in across Carve implementations, see the feature tier overview.

Enabling Extensions

Each entry in a profile's extensions array is either a shorthand string or an array with a type key plus options. Only options you set are forwarded - everything else keeps the library defaults.

php
// config/carve.php
'converters' => [
    'docs' => [
        'safe_mode' => false,
        'extensions' => [
            // Shorthand - library defaults
            'table_of_contents',
            'heading_permalinks',

            // With options
            [
                'type' => 'mentions',
                'mention_url' => 'https://github.com/{name}',
            ],
            [
                'type' => 'wikilinks',
                'url_template' => '/wiki/{page}',
            ],
        ],
    ],
],

Supported Types

TypeExtension
admonitionAdmonition callouts (::: note, ::: warning, …)
ascii_heading_idsASCII-transliterate generated heading ids
autolinkTurn bare URLs into links
citations[@key] citations with a generated reference list
code_callouts<1> markers in code blocks
code_groupTabbed code groups from labeled fences
color_swatchInline color swatches for color literals
default_attributesAttach default attributes to elements
detailsCollapsible <details> blocks
external_linkstarget/rel/nofollow handling for external links
fenced_renderRender fenced blocks via a client library (diagrams, charts)
frontmatterYAML/TOML/JSON frontmatter handling
glossaryGlossary term definitions and references
heading_level_shiftShift all heading levels by an offset
heading_numbersNumbered headings
heading_permalinksAnchor links on headings
heading_referenceWiki-style [Heading Name][] links to headings
img_fenceRender an img/image fence as sanitized SVG (sandboxed data-URI image)
indexBack-of-book index generation
inline_footnotes^[inline] footnotes
list_tableTables written as nested lists
lowercase_heading_idsLowercase generated heading ids
math_block$$-style display math blocks
mentions@user mentions and #tag tags
mermaidShorthand for fenced_render with language: mermaid
plantumlShorthand for fenced_render with language: [plantuml, puml], class plantuml
plus_bulletAccept + as an additional bullet marker
semantic_spanSemantic span classes
smart_quotesLocale-aware typographic quotes
spoilerSpoiler blocks
tab_normalizeNormalize tab indentation
table_of_contentsGenerated table of contents
tabsTabbed content panels
toc_placementPlace the TOC via a ::: toc marker
wikilinks[[Page Name]] wiki links

Unknown types are silently skipped, so double-check the spelling if an extension does not seem to take effect.

Every type is also available as a constant on ExtensionFactory - use those for IDE completion and typo safety (ExtensionFactory::types() returns the full list):

php
use MarkupCarve\LaravelCarve\Service\ExtensionFactory;

'extensions' => [
    ExtensionFactory::TYPE_TABLE_OF_CONTENTS,
    ExtensionFactory::TYPE_HEADING_PERMALINKS,
    [
        'type' => ExtensionFactory::TYPE_MENTIONS,
        'mention_url' => 'https://github.com/{name}',
    ],
],

Beyond the Named Types

Every extension bundled with carve-php has a config type above. For custom or third-party extensions, add the instance programmatically on the underlying converter:

php
use App\Carve\MyCustomExtension;
use MarkupCarve\LaravelCarve\Service\CarveManager;

$converter = app(CarveManager::class)->converter('docs');
$converter->getConverter()->addExtension(new MyCustomExtension());

Next Steps

Released under the MIT License.