-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathhtml.py
105 lines (91 loc) · 2.52 KB
/
html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'''
All the functions in this file should produce pure HTML, as
opposed to Markdown or other similar languages.
Some folks want to work with systems that don't necessarily
support markdown (or deal with incompabilities between
different flavors of markdown), so when possible, we should
strive for pure HTML in our output in the future.
(Producing pure HTML doesn't have to be a burden--we can
add helpers/converters as necessary.)
'''
from .date_helper import format_date1
from .url import (
sanitize_stream,
sanitize_topic,
)
from .url import (
archive_message_url,
archive_stream_url,
archive_topic_url,
zulip_post_url,
)
def topic_page_links(
site_url,
html_root,
zulip_url,
sanitized_stream_name,
sanitized_topic_name,
stream_name,
topic_name,
):
stream_url = archive_stream_url(site_url, html_root, sanitized_stream_name)
topic_url = archive_topic_url(site_url, html_root, sanitized_stream_name, sanitized_topic_name)
return f'''\
<h2>
<a href="{stream_url}">{stream_name}</a>
>
<a href="{topic_url}">{topic_name}</a>
</h2>
<hr>
<base href="{zulip_url}">
'''
def format_message(
site_url,
html_root,
zulip_url,
zulip_icon_url,
stream_name,
stream_id,
topic_name,
msg
):
msg_id = str(msg['id'])
post_link = zulip_post_url(
zulip_url,
stream_id,
stream_name,
topic_name,
msg_id,
)
user_name = msg['sender_full_name']
date = format_date1(msg['timestamp'])
msg_content = msg['content']
anchor_url = archive_message_url(
site_url,
html_root,
sanitize_stream(stream_name, stream_id),
sanitize_topic(topic_name),
msg_id
)
anchor = '<a name="{0}"></a>'.format(msg_id)
html = f'''
{anchor}
<h4>
{user_name}
(<a href="{post_link}" target="_blank">{date}</a>
<a href="{anchor_url}" class="archive-link-color"> | Archive</a>):
</h4>
{msg_content}
'''
return html
def last_updated_footer(stream_info):
last_updated = format_date1(stream_info['time'])
date_footer = f'\n<hr><p>Last updated: {last_updated} UTC</p>'
return date_footer
def homepage_link(site_url, zulip_icon_url):
if zulip_icon_url:
img_tag = f'<img src="{zulip_icon_url}" alt="homepage" style="height: 30px;max-width: 200px;">'
else:
img_tag = ''
homepage_url = f'<a href="{site_url}/archive/">{img_tag}</a>'
return homepage_url