Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/curder/commonmark-extensions
A collection of CommonMark extensions
https://github.com/curder/commonmark-extensions
commonmark-extension markdown
Last synced: 3 days ago
JSON representation
A collection of CommonMark extensions
- Host: GitHub
- URL: https://github.com/curder/commonmark-extensions
- Owner: curder
- License: mit
- Created: 2024-11-05T06:11:24.000Z (10 days ago)
- Default Branch: master
- Last Pushed: 2024-11-05T06:51:10.000Z (10 days ago)
- Last Synced: 2024-11-05T07:20:53.257Z (10 days ago)
- Topics: commonmark-extension, markdown
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CommonMark Extensions
[![Tests](https://github.com/curder/commonmark-extensions/actions/workflows/run-tests.yml/badge.svg)](https://github.com/curder/commonmark-extensions/actions/workflows/run-tests.yml)
[![Check & fix styling](https://github.com/curder/commonmark-extensions/actions/workflows/pint-fixer.yml/badge.svg)](https://github.com/curder/commonmark-extensions/actions/workflows/pint-fixer.yml)
[![Latest Stable Version](http://poser.pugx.org/curder/commonmark-extensions/v)](https://packagist.org/packages/curder/commonmark-extensions)
[![Total Downloads](http://poser.pugx.org/curder/commonmark-extensions/downloads)](https://packagist.org/packages/curder/commonmark-extensions)
[![License](http://poser.pugx.org/curder/commonmark-extensions/license)](https://packagist.org/packages/curder/commonmark-extensions)一个用于 [league/commonmark](https://github.com/thephpleague/commonmark) 的扩展集合,提供了代码组、自定义容器和标题锚点等功能。
## 功能特性
### 1. 代码组 (Code Groups)
允许创建分组的代码块,支持多语言切换展示:
~~~markdown
::: code-group
```php### 标题三
Section 3
```## 安装
通过 Composer 安装:
```bash
composer require curder/commonmark-extensions
```## 使用方法
```php
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Curder\CommonmarkExtensions\CodeGroupsExtension;
use Curder\CommonmarkExtensions\CustomContainersExtension;
use Curder\CommonmarkExtensions\HeadAnchorsExtension;// 创建环境配置
$config = [];// 创建环境并添加扩展
$environment = new Environment($config);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new CodeGroupsExtension());
$environment->addExtension(new CustomContainersExtension());
$environment->addExtension(new HeadAnchorsExtension());// 创建 Markdown 转换器
$converter = new MarkdownConverter($environment);// 转换 Markdown 为 HTML
$html = $converter->convert($markdown)->getContent();
```## 配置选项
### 代码组配置
```php
'code_groups' => [
'enabled' => true,
'class_names' => [
'code-group' => 'code-group',
'code-group-tabs' => 'code-group-tabs',
'code-group-contents' => 'code-group-contents',
'code-group-tab' => 'code-group-tab',
'code-group-tab-active' => 'active',
'code-group-content' => 'code-group-content',
'code-group-content-active' => 'active',
],
],
```### 自定义容器配置
```php
'custom_containers' => [
'enabled' => true,
'labels' => [
'tip' => '提示',
'warning' => '警告',
'danger' => '危险',
'details' => '详情',
],
'details' => [
'open' => false,
],
'class_names' => [
'container' => 'custom-block',
'title' => 'custom-block-title',
'content' => 'custom-block-content',
],
'icons' => [
'enabled' => false,
'tip' => '',
'warning' => '',
'danger' => '',
'info' => '',
'details' => '',
],
],
```### 标题锚点配置
```php
'head_anchors' => [
'enabled' => true,
],
```