sven/commonmark-dark-mode-images
最新稳定版本:v1.0.0
Composer 安装命令:
composer require sven/commonmark-dark-mode-images
包简介
Use different images in light- and dark mode in CommonMark-rendered Markdown
README 文档
README
⚠️ This package is abandoned. Use sven/commonmark-image-media-queries instead ⚠️
This CommonMark extension allows you to determine what images to show in dark- or light mode in Markdown converted using CommonMark.
Installation
Via composer:
composer require sven/commonmark-dark-mode-images
Usage
To enable the extension, first make sure the Attributes extension
that ships with CommonMark is enabled. Then, add the extension to the CommonMark environment:
use Sven\CommonMark\DarkModeImages\DarkModeImagesExtension; $environment->addExtension(new DarkModeImagesExtension());
You'll have to apply some classes to your Markdown images to indicate to this extension that they should be converted:
{.light-image} {.dark-image}
These {.light-image} and {.dark-image} tags are part of the Attributes extension.
They apply classes to the converted <img> elements, which this extension uses to do its magic. The resulting HTML will
look something like this:
<picture class="dark-mode-images-picture"> <source srcset="/images/settings-dark.jpg" media="(prefers-color-scheme: dark)" /> <img src="/images/settings-light.jpg" alt="Screenshot of a settings dialog"/> </picture>
And the result in the browser:
Configuration
Fallback or original
This option allows you to select either 'light' or 'dark' as the "original" form of the picture you're embedding.
This determines which picture will be used if the browser doesn't support the <picture> element.
use League\CommonMark\Environment\Environment; use Sven\CommonMark\DarkModeImages\DarkModeImagesExtension; $environment = new Environment([ 'dark_mode_images' => [ 'fallback' => 'dark', // Default: 'light'. ], ]); $environment->addExtension(new DarkModeImagesExtension());
Class on <picture> element
To change the class that is eventually applied to the rendered <picture> element, use the picture_class
configuration option:
use League\CommonMark\Environment\Environment; use Sven\CommonMark\DarkModeImages\DarkModeImagesExtension; $environment = new Environment([ 'dark_mode_images' => [ 'picture_class' => '<your class here>', // Default: 'dark-mode-images-picture'. ], ]); $environment->addExtension(new DarkModeImagesExtension());
Light and dark classes
Use the dark_image_class and light_image_class configuration options to determine what classes to apply to your
Markdown images to indicate which is for dark mode, and which is for light mode.
use League\CommonMark\Environment\Environment; use Sven\CommonMark\DarkModeImages\DarkModeImagesExtension; $environment = new Environment([ 'dark_mode_images' => [ 'light_image_class' => 'l', // Default: 'light-image'. 'dark_image_class' => 'd', // Default: 'dark-image'. ], ]); $environment->addExtension(new DarkModeImagesExtension());
Note
It is not recommended to use this extension when converting to Markdown on-the-fly on every request. This is best suited for use in a static site generator like Jigsaw.
Contributing
All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors.
License
sven/commonmark-dark-mode-images is licensed under the MIT License (MIT). Please see the license file
for more information.
sven/commonmark-dark-mode-images 适用场景与选型建议
sven/commonmark-dark-mode-images 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「markdown」 「images」 「light」 「color scheme」 「commonmark」 「dark」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sven/commonmark-dark-mode-images 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sven/commonmark-dark-mode-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sven/commonmark-dark-mode-images 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
Simple minimal but useful set of utils (properties, strings, datetimes, etc.)
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Adds more BBCode
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-11
