Minor doc updates, fixes and improvements

In particular, removed code which no longer worked, made light
theme easier on the eyes, added slight syntax highlightning,
and fixed search for exact matches.
This commit is contained in:
Lonami Exo 2019-03-16 17:17:25 +01:00
parent 05e5becd78
commit a5f5d6ef23
6 changed files with 48 additions and 43 deletions

View File

@ -447,34 +447,25 @@ However, a day is often more than enough.
Sending Messages with Buttons
*****************************
You must sign in as a bot in order to add inline buttons (or normal
**You must sign in as a bot** in order to add inline buttons (or normal
keyboards) to your messages. Once you have signed in as a bot specify
the `Button <telethon.tl.custom.button.Button>` or buttons to use:
.. code-block:: python
from telethon import events
from telethon.tl.custom import Button
async def callback(event):
await event.edit('Thank you!')
client.send_message(chat, 'Hello!',
buttons=Button.inline('Click me', callback))
You can also add the event handler yourself, or change the data payload:
.. code-block:: python
from telethon import events
@client.on(events.CallbackQuery)
async def handler(event):
await event.answer('You clicked {}!'.format(event.data))
async def callback(event):
await event.edit('Thank you for clicking {}!'.format(event.data))
client.send_message(chat, 'Pick one', buttons=[
client.send_message(chat, 'A single button, with "clk1" as data',
buttons=Button.inline('Click me', b'clk1'))
client.send_message(chat, 'Pick one from this grid', buttons=[
[Button.inline('Left'), Button.inline('Right')],
[Button.url('Check my site!', 'https://lonamiwebs.github.io')]
[Button.url('Check this site!', 'https://lonamiwebs.github.io')]
])
You can also use normal buttons (not inline) to request the user's

View File

@ -1,12 +1,12 @@
body {
font-family: 'Nunito', sans-serif;
color: #333;
background-color:#fff;
background-color:#eee;
font-size: 16px;
}
a {
color: #42aaed;
color: #329add;
text-decoration: none;
}
@ -14,7 +14,7 @@ pre {
font-family: 'Source Code Pro', monospace;
padding: 8px;
color: #567;
background: #f0f4f8;
background: #e0e4e8;
border-radius: 0;
overflow-x: auto;
}
@ -30,14 +30,14 @@ table {
}
table td {
border-top: 1px solid #eee;
border-top: 1px solid #ddd;
padding: 8px;
}
.horizontal {
margin-bottom: 16px;
list-style: none;
background: #f0f4f8;
background: #e0e4e8;
border-radius: 4px;
padding: 8px 16px;
}
@ -118,14 +118,14 @@ button {
font-size: 16px;
padding: 8px;
color: #000;
background-color: #fff;
border: 2px solid #42aaed;
background-color: #f7f7f7;
border: 2px solid #329add;
transition-duration: 300ms;
}
button:hover {
background-color: #42aaed;
color: #fff;
background-color: #329add;
color: #f7f7f7;
}
/* https://www.w3schools.com/css/css_navbar.asp */
@ -143,7 +143,7 @@ ul.together li {
ul.together li a {
display: block;
border-radius: 8px;
background: #f0f4f8;
background: #e0e4e8;
padding: 4px 8px;
margin: 8px;
}

View File

@ -85,8 +85,8 @@ if (typeof prependPath !== 'undefined') {
// Returns the penalty for finding the needle in the haystack
// or -1 if the needle wasn't found at all.
function find(haystack, needle) {
if (needle.length == 0) {
return true;
if (haystack.indexOf(needle) != -1) {
return 0;
}
var hi = 0;
var ni = 0;

View File

@ -43,7 +43,6 @@ class DocsWriter:
"""Writes the head part for the generated document,
with the given title and CSS
"""
#
self.title = title
self.write(
'''<!DOCTYPE html>

View File

@ -105,13 +105,14 @@ def _generate_index(root, folder, paths,
filename = folder / (BOT_INDEX if bots_index else INDEX)
with DocsWriter(root, filename, _get_path_for_type) as docs:
# Title should be the current folder name
docs.write_head(str(folder).title(),
docs.write_head(str(folder).replace(os.path.sep, '/').title(),
css_path=paths['css'],
default_css=paths['default_css'])
docs.set_menu_separator(paths['arrow'])
_build_menu(docs)
docs.write_title(str(filename.parent.relative_to(root)).title())
docs.write_title(str(filename.parent.relative_to(root))
.replace(os.path.sep, '/').title())
if bots_index:
docs.write_text('These are the methods that you may be able to '
@ -379,19 +380,18 @@ def _write_html_pages(root, tlobjects, methods, layer, input_res):
'<code>telethon.errors</code>.')
docs.write_title('Example', id='examples')
docs.write(
'<pre>from telethon.sync import TelegramClient\n'
'from telethon import functions, types\n'
'\n'
'with TelegramClient(name, api_id, api_hash) as client:\n'
' result = client(')
docs.write('''<pre>\
<strong>from</strong> telethon.sync <strong>import</strong> TelegramClient
<strong>from</strong> telethon <strong>import</strong> functions, types
<strong>with</strong> TelegramClient(name, api_id, api_hash) <strong>as</strong> client:
result = client(''')
tlobject.as_example(docs, indent=1)
docs.write(')\n')
if tlobject.result.startswith('Vector'):
docs.write(
' for x in result:\n'
' print(x'
)
docs.write('''\
<strong>for</strong> x <strong>in</strong> result:
print(x''')
else:
docs.write(' print(result')
if tlobject.result != 'Bool' \

View File

@ -1,6 +1,19 @@
import re
def _fmt_strings(*dicts):
for d in dicts:
for k, v in d.items():
if v in ('None', 'True', 'False'):
d[k] = '<strong>{}</strong>'.format(v)
else:
d[k] = re.sub(
r'([brf]?([\'"]).*\2)',
lambda m: '<em>{}</em>'.format(m.group(1)),
v
)
KNOWN_NAMED_EXAMPLES = {
('message', 'string'): "'Hello there!'",
('expires_at', 'date'): 'datetime.timedelta(minutes=5)',
@ -41,6 +54,8 @@ KNOWN_TYPED_EXAMPLES = {
'InputPeer': "'username'"
}
_fmt_strings(KNOWN_NAMED_EXAMPLES, KNOWN_TYPED_EXAMPLES)
SYNONYMS = {
'InputUser': 'InputPeer',
'InputChannel': 'InputPeer',