Search code examples
pythonhtmltelegramtelegram-bottelegraph

Formatting lists in Telegraph API


Working on a system that includes posting articles on Telegraph via python. Generally, everything works. But recently I found weird behavior of <ol> and <ul> tags in different browsers. On the mobile version of Telegraph, it works as expected, while everywhere else it is not. Are there any solutions except hardcoding the numbers of lines? You can check it out yourself here https://telegra.ph/Arthur-Conan-Doyle-Estudio-en-Escarlata-1-09-06 (active as of October 5th, 2021). The code I am using is below:

def update_page(path, title, content, author):
  response = telegraph.edit_page(path, html_content = content, title = title,
                               author_name = author, return_content=True)
  current_path = 'http://telegra.ph/{}'.format(path)
  return current_path 

html = '''
<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>
<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>
'''
title = 'Testing lists'
update_page(test_path, title, html, AUTHOR)

Examples of behavior: the behavior I need, mobile version of Telegraph and here is what I get in Chrome, Firefox and Safari


Solution

  • Try writing list items in one line like <li>1</li><li>2</li><li>3</li>. This solved it for me.