Python markdown将类添加到表中 [英] Python markdown add class to table

查看:146
本文介绍了Python markdown将类添加到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用markdown extantions: ['nl2br','tables','attr_list']



需要制作表格3种类型,如示例,标准,块和价格。但是,我试着用 attr_list 这样做。我没有任何东西..





有这样的东西:





问题:如何添加类到整个表,使用扩展名,

解决方案

这是 attr_list 延期。 Markdown中的某些块级结构没有任何方法来表示HTML中的块级元素。简单推断。例如,考虑表和列表。 Markdown来源中的哪一个是< table> < ul> 不是这样。只有表格单元格(< td> )或列表项(< li> )实际上在标记的来源。



在这种情况下,文档作者如何指定 attr 应该应用于元素那在markdown源码中不存在?我不认为这是可能的。我在上面的解释中列出了列表,因为我认为这一点更清楚。考虑以下列表:

  * foo 
{#baz}
* bar
{ #blah}

id =blah应用于包裹< ul> 或列表的最后一个列表项?它可能是。但是,要与第一个列表项一致工作,它必须应用于列表项而不是包装列表。同样的推理将适用于表。有趣的是,上周末,新版Python-Markdown(2014/02 / 16)包括一个修复,以允许attr_list在表单元格上正常工作。我不会预料到您将能够为包装表元素本身分配属性。



也许这是指向Markdown的语法规则,其部分说明:


Markdown不是HTML的替代品,甚至接近它。它的语法非常小,仅对应于HTML标签的一小部分。这个想法不是创建一个使得更容易插入HTML标签的语法。在我看来,HTML标签已经很容易插入。 Markdown的想法是使阅读,写作和编辑散文变得容易。 HTML是一种出版格式; Markdown是一种写作格式。因此,Markdown的格式化语法仅解决了可以以纯文本形式传达的问题。



对于Markdown语法未涵盖的任何标记,您只需使用HTML本身。 p>

表不是纯文本散文。因此,许多人认为(我包括 1 ),他们并不属于降价。也就是说,最简单的表格可以简单地用纯文本表示,这就是为什么存在简单的表格执行,如Python-Markdown附带的表。如果你想做任何更复杂的事情,那么你应该编写HTML,或者看看另一种符合你需求的标准语言。



不同,并且已经创建了一些第三方扩展程序来解决以上哲学。或许其中一个会更好地满足您的需求。



1 :全面披露:我是Python-Markdown的主要开发人员。鉴于上述推理,我更倾向于删除表支持,而不是添加附加功能。然而,为了继续支持现有用户,现有功能将保留在可预见的将来,而不添加表语法。如果您真的需要更多功能,我们会提供 API ,这样您就可以为任何您开发扩展程序想要。


I use markdown extantions: ['nl2br', 'tables', 'attr_list']

I need make tables 3 types, like example, standart, blocks and prices. But then i try do this with attr_list i have nothing..

And have something like this:

Question: how add class to whole table, using extention, if this possible?

解决方案

This is a known limitation of the attr_list extension. Some block level constructs in Markdown do not have any way to represent the block level element in HTML. It is simply inferred. For example, consider both tables and lists. Where in the Markdown source is the <table> or <ul> represented? It is not. Only the tables cells (<td>) or list items (<li>) are actually represented in the Markdown source.

That being the case, how can the document author specify that the attr should apply to the element that doesn't exist in the markdown source? I don't think it is possible. I included lists in my explanation above because I think the point is more clear. Consider the following list:

* foo
{#baz}
* bar
{#blah}

Is the id="blah" supposed to apply to the wrapping <ul> or the last list item of the list? It could be either. However, to work consistently with the first list item, it has to apply to the list item not the wrapping list. That same reasoning would apply to tables. You would only ever be able to assign attributes to individual cells, not the entire table.

Interestingly, a new release of Python-Markdown this past weekend (2014/02/16) includes a fix to allow attr_list to work properly on table cells. I don't anticipate that you will ever be able to assign attributes to the wrapping table element itself.

Perhaps this is a good time to point to Markdown's syntax rules which state in part:

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

Tables are not plain text prose. Therefore in the opinion of many (myself included1) they don't really belong in markdown. That said, the simplest of tables can be fairly simply represented in plaintext, which is why simple table implementations like the one that ships with Python-Markdown exist. If you want to do anything more complex, then you should be writing HTML or perhaps looking at another markup language that has a philosophy that matches your needs.

That said, opinions differ and some third party extensions have been created to work around the above philosophy. Perhaps one of those will better meet your needs.

1: Full disclosure: I am the primary developer of Python-Markdown. Given the above reasoning I would be more inclined to remove table support altogether than to add additional features. However, in order to continue supporting existing users, the existing features will remain into the foreseeable future with no additions to the table syntax. If you really want more features we offer an API which allows you to develop extensions for whatever you want.

这篇关于Python markdown将类添加到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆