File: README.md

package info (click to toggle)
slidge-style-parser 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220 kB
  • sloc: python: 456; makefile: 19
file content (49 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download
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
# Slidge-style-parser

[![PyPI version](https://badge.fury.io/py/slidge-style-parser.svg)](https://badge.fury.io/py/slidge-style-parser)

License: AGPL-3.0-or-later

A parsing library for [Slidge](https://sr.ht/~nicoco/slidge). Supports parsing these attributes:

- "\_underline_"
- "\*bold*"
- "\~strikethrough~"
- "\`code span`"
- "\```language

   code block

   \```"
- "\>quote"
- "\|\|spoiler||"
- "\\\_escape style_"

Most of them correspond to [XEP-0393: Message Styling](https://xmpp.org/extensions/xep-0393.html).

Methods: 

```python

format_for_telegram(body: String, mentions: Optional<(_, start, end_index_exclusive)>)
    -> (body: String, Vec<(format: String, offset: usize, length: usize, language: String)>)

format_for_matrix(body: String, mentions: Optional<(mxid, start, end_index_exclusive)>) -> body: String

format_body(body: String, new_tags: HashMap<String, (String, String)>) -> String

new_tags = {
    "_": ("<em>", "</em>"),
    "*": ("<strong>", "</strong>"),   
    "~": ("<del>", "</del>"),
    "`": ("<code>", "</code>"),
    "```": ("<pre><code>", "</code></pre>"),
    "```language": ('<pre><code class="language-{}">', "</code></pre>"),
    ">": ("<blockquote>", "</blockquote>"),
    "||": ("<span data-mx-spoiler>", "</span>"),
    "\n": ("<br>", "")
}

```

To build: `uv build` or any other [PEP517](https://peps.python.org/pep-0517/)-compliant tool