Skip to content

Commit

Permalink
style: reformatted using pre-commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
redimp committed Nov 17, 2024
1 parent 1ed697e commit 187e7fb
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 32 deletions.
1 change: 0 additions & 1 deletion docs/custom_css_example/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ services:
- ./custom:/app/otterwiki/static/custom:ro
# For this example we do not persist any data
# - ./app-data:/app-data

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

from otterwiki.plugins import hookimpl


@hookimpl
def page_view_htmlcontent_postprocess(html, page):
if page.metadata is not None:
html += \
f"""
html += f"""
<div style="margin-top: 5rem; padding-top: .5rem; border-top: 1px dashed rgba(128,128,128,0.2); color: rgba(128,128,128,0.5);" class="text-small">
Last modified {page.metadata["datetime"].strftime("%Y-%m-%d %H:%M:%S")} by {page.metadata["author_name"]}
</div>
Expand Down
6 changes: 5 additions & 1 deletion docs/plugin_examples/plugin_noemojis/otterwiki_noemojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class NoEmojiPlugin:
def renderer_markdown_preprocess(self, md):
return self.emojis.sub('', md)


# this is ne
plugin_manager.register(NoEmojiPlugin())


def test_noemoji():
noemoji = NoEmojiPlugin()
assert noemoji.preprocess_markdown("👴") == ""
assert noemoji.preprocess_markdown("🕶H🦴ello, W🎲orld😇!") == "Hello, World!"
assert (
noemoji.preprocess_markdown("🕶H🦴ello, W🎲orld😇!") == "Hello, World!"
)
2 changes: 0 additions & 2 deletions otterwiki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@
def fatal_error(msg):
print("\nError: {}\n".format(msg), file=sys.stderr)
sys.exit(1)


1 change: 0 additions & 1 deletion otterwiki/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,3 @@ def has_permission(permission, user=current_user):
app.jinja_env.globals.update(
auth_supported_features=auth_manager.supported_features()
)

1 change: 1 addition & 0 deletions otterwiki/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SerializeError(ValueError):
# initiliaze serializer
_serializer = URLSafeTimedSerializer(app.config["SECRET_KEY"])


def serialize(str, salt=None):
return _serializer.dumps(str, salt=salt)

Expand Down
23 changes: 16 additions & 7 deletions otterwiki/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def parse_std_link(self, m, state):
link = link[1:-1]
elif link.startswith("./"):
if self.env.get("PAGE_URL", None) is not None:
link = self.env["PAGE_URL"]+"/"+link
link = self.env["PAGE_URL"] + "/" + link

title = m.group(3)
if title:
Expand All @@ -280,18 +280,26 @@ def parse_std_link(self, m, state):

return self.tokenize_link(line, link, text, title, state)


class OtterwikiMdParser(mistune.Markdown):
def __init__(self, renderer, block=None, inline=None, plugins=None, env={}):
def __init__(
self, renderer, block=None, inline=None, plugins=None, env={}
):
self.env = env
super().__init__(renderer=renderer, block=block, inline=inline, plugins=plugins)
super().__init__(
renderer=renderer, block=block, inline=inline, plugins=plugins
)


class OtterwikiRenderer:
def __init__(self, config={}):
self.env = {
"config" : config,
"config": config,
}
self.md_renderer = OtterwikiMdRenderer(env=self.env)
self.inline_renderer = OtterwikiInlineParser(env=self.env, renderer=self.md_renderer, hard_wrap=False)
self.inline_renderer = OtterwikiInlineParser(
env=self.env, renderer=self.md_renderer, hard_wrap=False
)
self.mistune = OtterwikiMdParser(
renderer=self.md_renderer,
inline=self.inline_renderer,
Expand Down Expand Up @@ -343,11 +351,11 @@ def markdown(self, text, cursor=None, **kwargs):
line = 0

# store extra kwargs in environment
for k,v in kwargs.items():
for k, v in kwargs.items():
self.env[k.upper()] = v
html = self.mistune(text)
# clean extra kwargs from environment
for k,v in kwargs.items():
for k, v in kwargs.items():
del self.env[k.upper()]
# generate the toc
toc = self.md_renderer.toc_tree.copy()
Expand Down Expand Up @@ -379,5 +387,6 @@ def markdown(self, text, cursor=None, **kwargs):

return html, toc


# unconfigured renderer for testing and rendering about()
render = OtterwikiRenderer()
7 changes: 5 additions & 2 deletions otterwiki/renderer_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ class mistunePluginWikiLink:
def parse_wikilink(self, inline, m, state):
title, link = m.group(2), m.group(4) or ""

WIKILINK_STYLE = inline.env.get("config",{}).get("WIKILINK_STYLE","")
if WIKILINK_STYLE.upper().replace("_","").strip() in ["LINKTITLE", "PAGENAMETITLE"]:
WIKILINK_STYLE = inline.env.get("config", {}).get("WIKILINK_STYLE", "")
if WIKILINK_STYLE.upper().replace("_", "").strip() in [
"LINKTITLE",
"PAGENAMETITLE",
]:
title, link = link, title

if link == '':
Expand Down
1 change: 0 additions & 1 deletion otterwiki/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,3 @@ def format_datetime(value, format="medium"):
githttpserver = otterwiki.remote.GitHttpServer(path=app.config["REPOSITORY"])

import otterwiki.views

1 change: 0 additions & 1 deletion otterwiki/templates/blame.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ <h2>Blame {#{pagename}#}</h2>
{%- endfor %}{# l in lines #}
</table>
{% endblock %}

1 change: 0 additions & 1 deletion otterwiki/templates/draft.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ <h2 class="card-title">Continue editing draft?</h2>
</tbody>
</table>
{% endblock %}

1 change: 0 additions & 1 deletion otterwiki/templates/syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ <h2>An Otter Wiki - Markdown Guide</h2>
{% include "snippets/syntax.html" %}
</div>
{% endblock %}

2 changes: 0 additions & 2 deletions otterwiki/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,3 @@ def strfdelta_round(tdelta, round_period='second'):
break

return s


2 changes: 0 additions & 2 deletions otterwiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,3 @@ def git_upload_pack():
@app.route("/.git/git-receive-pack", methods=["POST"])
def git_receive_pack():
return githttpserver.git_receive_pack(request.stream)


10 changes: 6 additions & 4 deletions otterwiki/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ def view(self):
]

# render markdown
htmlcontent, toc = app_renderer.markdown(self.content, page_url=self.page_url)
htmlcontent, toc = app_renderer.markdown(
self.content, page_url=self.page_url
)

if len(toc) > 0:
# use first headline to overwrite pagename
Expand Down Expand Up @@ -590,7 +592,9 @@ def preview(self, content=None, cursor_line=None):
content = self.content

# render preview html from markdown
content_html, toc = app_renderer.markdown(content, cursor=cursor_line, page_url=self.page_url)
content_html, toc = app_renderer.markdown(
content, cursor=cursor_line, page_url=self.page_url
)
# update pagename from toc
if len(toc) > 0:
# use first headline to overwrite pagename
Expand Down Expand Up @@ -1598,5 +1602,3 @@ def view(self):
return pi.render()
# default to Page view
return p.view()


2 changes: 0 additions & 2 deletions tests/test_gitstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,3 @@ def test_get_parent_revision(storage):
filename=filename1, revision=revision3
)
assert parent_revision == revision1


5 changes: 3 additions & 2 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ def test_wiki_link_subspace(req_ctx):


def test_wiki_link_compatibilty_mode(req_ctx):
configured_renderer = OtterwikiRenderer(config={"WIKILINK_STYLE":"LinkTitle"})
configured_renderer = OtterwikiRenderer(
config={"WIKILINK_STYLE": "LinkTitle"}
)
text = "[[people/Paul|Paul]]"
html, _ = configured_renderer.markdown(text)
assert '<a href="/people/Paul">Paul</a>' in html



def test_wiki_link_in_table(req_ctx):
text = """| name | date | link |
| -------- | -------- | -------- |
Expand Down

0 comments on commit 187e7fb

Please sign in to comment.