[英]How to get the metadata from a Markdown file using python-markdown?
[英]How to create a new markdown cue extending another one using python-markdown
我在鹈鹕上使用markdown,但是对图像的控制不是很好(就像其他markdown一样)
我试图创建一个扩展以将图像包装成一定宽度以扩展图像并在其周围添加标签。
基本上我想这样写:
!![alt text](path.to.image.png title of the image)
并生成此html
<a href="path.to.image.png"><img width=100% src="path.to.image.png" alt="alt text" title="title of the image"/></a>
本教程太基础了。 是否可以环绕当前的img代码,还是我必须像全新的md提示一样创建它?
谢谢!
是的,您需要创建自己的内联模式。 内置模式都无法满足要求。 就是说,这不应该很难:
class MyImgPattern(Pattern):
def handleMatch(self, m):
a = etree.Element('a', attrib={'href':m.group(3)})
img = etree.Element('img', attrib={
'width': '100%',
'src': m.group(3),
'alt': m.group(2),
'title': m.group(4)
})
a.append(img)
return a
请注意,我基于内置图像模式所使用的结构为您的正则表达式假定了某种结构。 根据您使用的正则表达式,您可能需要相应地调整组。
然后按照正常情况告诉Markdown您的新模式,您应该一切顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.