Сообщить об ошибке.

Расширение tables модуля markdown в Python

Таблицы в документах Markdown

Синтаксис:

import markdown

html = markdown.markdown(some_text, extensions=['tables'])

Параметры:

  • some_text - разметка Markdown,
  • extensions - список расширений модуля.

Возвращаемое значение:

  • текст в формате HTML.

Описание:

Расширение markdown.extensions.tables добавляет возможность создавать таблицы в документах Markdown.

Например, следующая разметка Markdown:

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

Преобразуется в следующий HTML-текст.

<table>
  <thead>
    <tr>
      <th>First Header</th>
      <th>Second Header</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Content Cell</td>
      <td>Content Cell</td>
    </tr>
    <tr>
      <td>Content Cell</td>
      <td>Content Cell</td>
    </tr>
  </tbody>
</table>

Примеры использования:

import markdown
text = """
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
"""
html = markdown.markdown(some_text, extensions=['tables'])
print(html)
# <table>
#   <thead>
#     <tr>
#       <th>First Header</th>
#       <th>Second Header</th>
#     </tr>
#   </thead>
#   <tbody>
#     <tr>
#       <td>Content Cell</td>
#       <td>Content Cell</td>
#     </tr>
#     <tr>
#       <td>Content Cell</td>
#       <td>Content Cell</td>
#     </tr>
#   </tbody>
# </table>