Compare commits

..

11 Commits

Author SHA1 Message Date
Maze
bc20e47fb1
Merge branch 'void-install-docs' into 'main'
update Void Linux installation docs

See merge request mx-moment/moment!21
2023-09-04 10:03:55 +00:00
Karel Balej
bc526ab561 update Void Linux installation guide
Remove the requirement to install PyOtherSide manually as it seems to
have been added to Void's package repository some time ago.
2023-09-03 12:04:30 +02:00
Maze
b61d1e7a3e Merge remote-tracking branch 'alex/fix-nio' 2023-08-21 21:16:29 +02:00
Maze
bc0eca1d16 Remove mention of #mirage-client:matrix.org
After losing moderation, this room has become problematic. The least we
can do, is to remove references to it.
2023-08-18 11:07:38 +02:00
gridtime
8d430953f2
fixes nio logger configuration for nio >= 0.21 2023-08-07 20:17:54 +02:00
gridtime
45d98fe0b5
gitignores venv 2023-08-07 19:26:36 +02:00
Maze
4e8311fe56 Use upstream nio instead of fork 2023-06-18 23:51:03 +02:00
Maze
2af33fce77 Add Pop! OS 2023-03-31 21:53:17 +02:00
Maze
111462d3d0 Merge branch 'mistune-2.0.2' into 'main'
Port to Mistune 2.0.2

See merge request mx-moment/moment!16
2023-03-17 21:59:21 +00:00
Maze
9da389ba58 Update INSTALL.md
Do not force updating the whole system
2023-02-09 05:21:20 +00:00
Newbyte
7b9b48b1ae
Port to Mistune 2.0.2 2022-10-16 10:56:57 +02:00
6 changed files with 52 additions and 88 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ __pycache__
.mypy_cache
*.egg-info
*.pyc
venv
*.qmlc
*.jsc

View File

@ -17,6 +17,7 @@ but compiling on Windows and macOS should be possible with the right tools.
- [Gentoo / emerge](#gentoo-emerge)
- [Ubuntu 19.04 / apt](#ubuntu-1904-apt)
- [Ubuntu 19.10+, Debian bullseye / apt](#ubuntu-1910-debian-bullseye-apt)
- [Pop! OS](#pop-os)
- [Void Linux / xbps](#void-linux-xbps)
- [Installing PyOtherSide manually](#installing-pyotherside-manually)
- [Installing libolm manually](#installing-libolm-manually)
@ -166,7 +167,7 @@ export PATH="/usr/lib/qt5/bin:$PATH"
#### Arch Linux / pacman
```sh
pacman -Syu qt5-base qt5-declarative qt5-quickcontrols2 qt5-svg \
pacman -S qt5-base qt5-declarative qt5-quickcontrols2 qt5-svg \
qt5-graphicaleffects qt5-imageformats \
libx11 libxss alsa-lib \
python python-pip \
@ -256,9 +257,27 @@ sudo apt install qt5-default qt5-qmake qt5-image-formats-plugins \
libolm-dev
```
#### Void Linux / xbps
#### Pop! OS
[PyOtherSide](#installing-pyotherside-manually) must be manually installed.
No need to install libolm manually.
```sh
sudo apt update
sudo apt install qt5-qmake qt5-image-formats-plugins qml-module-qtquick2 \
qml-module-qtquick-window2 qml-module-qtquick-layouts \
qml-module-qtquick-dialogs qml-module-qt-labs-platform \
qml-module-qtquick-shapes qml-module-qt-labs-qmlmodels \
qml-module-qtgraphicaleffects qml-module-qtquick-controls2 \
qtdeclarative5-dev qtquickcontrols2-5-dev libx11-dev \
libxss-dev libasound2-dev python3-dev python3-pip \
qml-module-io-thp-pyotherside build-essential git \
cmake zlib1g-dev libtiff5-dev libwebp-dev libopenjp2-7-dev \
libmediainfo-dev libolm-dev meson libdbus-glib-1-dev \
libgirepository1.0-dev patchelf
pip3 install --user dbus-python
```
#### Void Linux / xbps
```sh
sudo xbps-install -Su qt5-devel qt5-declarative-devel \
@ -266,7 +285,7 @@ sudo xbps-install -Su qt5-devel qt5-declarative-devel \
qt5-svg-devel qt5-graphicaleffects qt5-imageformats \
libx11-devel libXScrnSaver-devel alsa-lib-devel \
python3-devel python3-pip \
olm-devel \
olm-devel pyotherside \
base-devel git cmake \
libjpeg-turbo-devel zlib-devel tiff-devel libwebp-devel \
libopenjpeg2-devel libmediainfo-devel

View File

@ -49,4 +49,4 @@ We suggest setting memorable keybindings. In the above example,
<kbd>Ctrl+G Ctrl+M</kbd> could mean "Go to Moment". Note that key chords in
Moment can be as long as you want - for example, you could have
<kbd>Ctrl+G Ctrl+M Ctrl+O</kbd> for `#moment-client:matrix.org` and
<kbd>Ctrl+G Ctrl+M Ctrl+I</kbd> for `#mirage-client:matrix.org`.
<kbd>Ctrl+G Ctrl+M Ctrl+A</kbd> for `#matrix:matrix.org`.

View File

@ -1,11 +1,11 @@
Pillow >= 7.0.0, < 9
aiofiles >= 0.4.0, < 0.7
aiofiles >= 0.4.0, < 24.0.0
appdirs >= 1.4.4, < 2
cairosvg >= 2.4.2, < 3
filetype >= 1.0.7, < 2
html_sanitizer >= 1.9.1, < 2
lxml >= 4.5.1, < 5
mistune >= 0.8.4, < 0.9
mistune >= 2.0.0, < 3.0
pymediainfo >= 4.2.1, < 5
plyer >= 1.4.3, < 2
sortedcontainers >= 2.2.2, < 3
@ -14,9 +14,8 @@ redbaron >= 0.9.2, < 1
hsluv >= 5.0.0, < 6
simpleaudio >= 1.0.4, < 2
dbus-python >= 1.2.16, < 2; platform_system == "Linux"
matrix-nio[e2e] >= 0.20.1, < 1.0.0
async_generator >= 1.10, < 2; python_version < "3.7"
dataclasses >= 0.6, < 0.7; python_version < "3.7"
pyfastcopy >= 1.0.3, < 2; python_version < "3.8"
git+https://github.com/MRAAGH/matrix-nio#egg=matrix-nio[e2e]

View File

@ -41,8 +41,11 @@ from .user_files import (
# Logging configuration
log.getLogger().setLevel(log.INFO)
nio.logger_group.level = nio.log.logbook.WARNING
nio.log.logbook.StreamHandler(sys.stderr).push_application()
if hasattr(nio, 'log'):
nio.logger_group.level = nio.log.logbook.WARNING
nio.log.logbook.StreamHandler(sys.stderr).push_application()
else:
log.getLogger('nio').setLevel(log.WARNING)
class Backend:

View File

@ -18,84 +18,32 @@ from lxml.html import HtmlElement, etree # nosec
from .color import SVGColor
class MarkdownInlineGrammar(mistune.InlineGrammar):
"""Markdown inline elements syntax modifications for the Mistune parser.
def parse_colour(inline, m, state):
colour = m.group(1)
text = m.group(2)
return "colour", colour, text
- Disable underscores for bold/italics (e.g. `__bold__`)
- Add syntax for coloring text: `<color>(text)`,
e.g. `<red>(Lorem ipsum)` or `<#000040>(sit dolor amet...)`
"""
def render_html_colour(colour, text):
return f'<span data-mx-color="{colour}">{text}</span>'
escape = re.compile(r"^\\([\\`*{}\[\]()#+\-.!_<>~|])") # Add <
emphasis = re.compile(r"^\*((?:\*\*|[^\*])+?)\*(?!\*)")
double_emphasis = re.compile(r"^\*{2}([\s\S]+?)\*{2}(?!\*)")
def plugin_matrix(md):
# test string: r"<b>(x) <r>(x) \<a>b>(x) <a\>b>(x) <b>(\(z) <c>(foo\)xyz)"
color = re.compile(
r"^<(.+?)>" # capture the color in `<color>`
colour = (
r"^<(.+?)>" # capture the colour in `<colour>`
r"\((.+?)" # capture text in `(text`
r"(?<!\\)(?:\\\\)*" # ignore the next `)` if it's \escaped
r"\)", # finish on a `)`
r"\)" # finish on a `)`
)
# Mark colour as high priority as otherwise e.g. <red>(hi) matches the
# inline_html rule instead of the colour rule.
md.inline.rules.insert(1, "colour")
md.inline.register_rule("colour", colour, parse_colour)
class MarkdownBlockGrammar(mistune.BlockGrammar):
"""Markdown block elements syntax modifications for the Mistune parser.
- Require a space after # for titles
"""
heading = re.compile(r"^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)")
class MarkdownInlineLexer(mistune.InlineLexer):
"""Apply the changes from `MarkdownInlineGrammar` for Mistune."""
grammar_class = MarkdownInlineGrammar
default_rules = [
"escape", "color", "autolink", "url", # Add color
"footnote", "link", "reflink", "nolink",
"double_emphasis", "emphasis", "code",
"linebreak", "strikethrough", "text",
]
inline_html_rules = [
"escape", "color", "autolink", "url", "link", "reflink", # Add color
"nolink", "double_emphasis", "emphasis", "code",
"linebreak", "strikethrough", "text",
]
def output_double_emphasis(self, m):
return self.renderer.double_emphasis(self.output(m.group(1)))
def output_emphasis(self, m):
return self.renderer.emphasis(self.output(m.group(1)))
def output_color(self, m):
color = m.group(1)
text = self.output(m.group(2))
return self.renderer.color(color, text)
class MarkdownBlockLexer(mistune.BlockLexer):
"""Apply the changes from `MarkdownBlockGrammar` for Mistune."""
grammar_class = MarkdownBlockGrammar
class MarkdownRenderer(mistune.Renderer):
def color(self, color: str, text: str) -> str:
"""Render given text with a color using `<span data-mx-color=#hex>`."""
# This may be a SVG color name, try to get a #hex code from it:
with suppress(KeyError):
color = SVGColor[color.lower().replace(" ", "")].value.hex
return f'<span data-mx-color="{color}">{text}</span>'
if md.renderer.NAME == "html":
md.renderer.register("colour", render_html_colour)
class HTMLProcessor:
@ -201,19 +149,13 @@ class HTMLProcessor:
# hard_wrap: convert all \n to <br> without required two spaces
# escape: escape HTML characters in the input string, e.g. tags
self._markdown_to_html = mistune.Markdown(
self._markdown_to_html = mistune.create_markdown(
hard_wrap = True,
escape = True,
inline = MarkdownInlineLexer,
block = MarkdownBlockLexer,
renderer = MarkdownRenderer(),
renderer = "html",
plugins = ['strikethrough', plugin_matrix],
)
self._markdown_to_html.block.default_rules = [
rule for rule in self._markdown_to_html.block.default_rules
if rule != "block_quote"
]
def mentions_in_html(self, html: str) -> List[Tuple[str, str]]:
"""Return list of (text, href) tuples for all mention links in html."""