alto/commonmark 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alto/commonmark

Composer 安装命令:

composer require alto/commonmark

包简介

A collection of CommonMark extensions: code block titles, content slicing, heading level adjustment, file import/include, source display, table of contents, tabs, and link rewriting.

README 文档

README

Reusable league/commonmark extensions in a monorepo, installable as either the umbrella package alto/commonmark or as standalone per-extension packages.

Installation

composer require alto/commonmark

alto/commonmark declares replace on all standalone packages, so dependency resolution stays compatible whether you install one or all.

Extension Description GitHub Packagist
CodeBlockTitle Titled fenced code blocks rendered as <figure> GitHub Packagist
ContentSlicer Wraps heading sections in semantic <section> elements GitHub Packagist
HeadingLevel Shift or remap heading levels across the document GitHub Packagist
Import Import file contents into code blocks with line ranges GitHub Packagist
Include Inline-include Markdown fragments for doc composition GitHub Packagist
LinkRewriter Rewrite links & images via base URI, map, or regex GitHub Packagist
Source Embed source files with line numbers and highlighting GitHub Packagist
TableOfContents Auto-generated TOC from headings via @toc GitHub Packagist
Tabs Accessible ARIA tabbed UI from a simple @tabs directive GitHub Packagist

Extensions

CodeBlockTitle

The detail that signals craft — adds a title="..." to any fenced code block and wraps it in a semantic <figure>/<figcaption>. One small thing that makes a doc site feel finished.

```php title="hello.php"
echo "Hello";
```
<figure class="code-block has-title" data-title="hello.php">
  <figcaption class="code-title">hello.php</figcaption>
  <pre><code class="language-php">echo "Hello";
</code></pre>
</figure>

Doc · GitHub · Packagist

ContentSlicer

The rarest one in the set. Most processors stop at rendering headings as tags — this one restructures the entire document into a properly nested <section> tree, giving CSS selectors, JavaScript, and accessibility tooling something real to work with. No custom syntax needed.

## Subtopic 1
More content.
## Subtopic 2
Final content.
<section><h2>Subtopic 1</h2><p>More content.</p></section>
<section><h2>Subtopic 2</h2><p>Final content.</p></section>

Doc · GitHub · Packagist

HeadingLevel

The one you don't need until you really do — then it's irreplaceable. Shifts, remaps, or transforms heading levels when embedding content from one context into another without heading hierarchy collisions.

# Title
## Section
<!-- with down: 1 -->
<h2>Title</h2>
<h3>Section</h3>

Doc · GitHub · Packagist

Import

Solves copy-paste drift between your docs and your source code. Pulls external file content directly into a code block — with line-range selection, language hinting, and depth-limited circular-import protection.

@import "src/Auth.php" {lines: 1-30, lang: php}
<pre><code class="language-php">// src/Auth.php lines 1–30
</code></pre>

Doc · GitHub · Packagist

Include

The backbone of large documentation sets. Pulls in and fully parses markdown fragments inline — making one-file-per-section composition possible without a build system.

@include "parts/intro.md"
<h2>Introduction</h2>
<p>This is the introduction section.</p>

Doc · GitHub · Packagist

LinkRewriter

Indispensable plumbing for any hosted documentation setup. Decouples your markdown from your deployment URL with a composable chain of rewrite rules — base URI, exact maps, regex, and custom callbacks — applied in sequence.

[Guide](/getting-started)
![Logo](/assets/logo.svg)
<!-- with base_uri: https://docs.example.com -->
<a href="https://docs.example.com/getting-started">Guide</a>
<img src="https://docs.example.com/assets/logo.svg" alt="Logo">

Doc · GitHub · Packagist

Source

The flagship of the set. Embeds a real file — not a copy — directly into your documentation, with syntax detection, line-range selection, line numbers, and per-line highlighting. Your docs stay in sync with your code by definition.

@source "src/Service.php" {lines: 9-11, numbers: true, highlight: "9,11"}
<div class="source-block">
  <div class="source-path">src/Service.php</div>
  <pre><code class="language-php"><span class="line highlighted"><span class="line-number">9</span>    public function add(int $a, int $b): int</span>
<span class="line"><span class="line-number">10</span>    {</span>
<span class="line highlighted"><span class="line-number">11</span>        return $a + $b;</span></code></pre>
</div>

Doc · GitHub · Packagist

TableOfContents

A must-have for any document longer than a page. Drop @toc where you want the contents list — headings are collected, IDs assigned, and a navigable list rendered in one pass.

@toc {min: 2}
## Introduction
## Setup
<div class="table-of-contents" id="toc">
  <ul>
    <li><a href="#introduction">Introduction</a></li>
    <li><a href="#setup">Setup</a></li>
  </ul>
</div>

Doc · GitHub · Packagist

Tabs

One directive, fully accessible tabbed UI, zero JavaScript to write. Wraps content in proper ARIA tablist/tab/tabpanel roles with a self-contained switching script.

@tabs
@tab "PHP"
```php
echo 'Hello';
```
@tab "JS"
```js
console.log('Hello');
```
@endtabs
<div class="tab-group" data-tabs-id="tabs-1">
  <div class="tab-list" role="tablist">
    <button class="tab active" role="tab" aria-selected="true"  aria-controls="tabs-1-panel-0">PHP</button>
    <button class="tab"        role="tab" aria-selected="false" aria-controls="tabs-1-panel-1">JS</button>
  </div>
  <div class="tab-panels">
    <div class="tab-panel" id="tabs-1-panel-0" role="tabpanel"></div>
    <div class="tab-panel" id="tabs-1-panel-1" role="tabpanel"></div>
  </div>
</div>

Doc · GitHub · Packagist

Support

If Alto CommonMark is useful to your project, sponsoring on GitHub is a great way to support continued development — and it's always appreciated.

License

MIT. See LICENSE.

alto/commonmark 适用场景与选型建议

alto/commonmark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「source」 「import」 「markdown」 「extension」 「tabs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alto/commonmark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alto/commonmark 我们能提供哪些服务?
定制开发 / 二次开发

基于 alto/commonmark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 46
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-17