我是 Markdown 的 super 粉丝(几乎在我所有的 PHP 元素中都使用它),但不喜欢它有限的输出。大部分渲染有点太简单了,并不能真正让我对其布局有太多控制或自由。例如,我可以插入一张图片:
![Alt Text](path/to/image.jpg) This is my image!
But that will simply be converted into:
<p>
<img src="path/to/image.jpg" alt="Alt Text" /> This is my image!
</p>
假设我想让我的图像向右浮动?我目前无法向语法中添加任何类,但这不是一个不错的功能吗?我希望能够输出:
<p>
<img src="path/to/image.jpg" alt="Alt Text" class="alignright caption">
This is my image!
</p>
对一个或多个 CSS 类的支持将是惊人的。我的问题是关于在 PHP 版本的 Markdown 中实现这种支持的最佳方式。
想法?
最佳答案
Markdown 在核心版本中没有语法来支持 CSS class
名称、内联样式或 id
属性。根据您的工作,您可能会发现 Textile 是更适合您的解决方案。它在某些方面类似于 Markdown,而在其他方面则完全不同。例如,要获得上面问题中提到的输出,您可以使用此 Textile 字符串:
(alignright caption)path/to/image.jpg(替代文字)!这是我的头像!
这将转化为:
<p>
<img src="path/to/image.jpg" alt="Alt Text" class="alignright caption">
This is my image!
</p>
您还可以使用 {}
您可以 play with the syntax在他们的现场演示页面上。
我在寻找 PHP 的 Textile 解析器时遇到了一些麻烦,因此您对这个答案的理解可能不如我希望的那么多。我确实找到了 this snippet , 但肯定不是全部。
关于php - 扩展 PHP Markdown 以接受 CSS 类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2150867/