Skip to content

Commit

Permalink
Merge pull request #6269 from akatsoulas/extra-space-wiki-links
Browse files Browse the repository at this point in the history
Trim extra spaces from wiki links
  • Loading branch information
akatsoulas authored Oct 1, 2024
2 parents ce5d56e + 6e3119e commit e0c7dff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions kitsune/sumo/parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import re
from os.path import basename
from urllib.parse import urlparse, parse_qs
from urllib.parse import parse_qs, urlparse

from django.conf import settings
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _lazy, gettext as _

from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _lazy
from sentry_sdk import capture_exception
from wikimarkup.parser import Parser, ALLOWED_TAGS
from wikimarkup.parser import ALLOWED_TAGS, Parser

from kitsune.gallery.models import Image, Video
from kitsune.sumo import email_utils
Expand Down Expand Up @@ -332,6 +333,7 @@ def _hook_internal_link(self, parser, space, name):
# Split on pipe -- [[href|name]]
if "|" in name:
title, text = title.split("|", 1)
title = re.sub(r"\s+", " ", title).strip()

hash = ""
if "#" in title:
Expand Down
9 changes: 6 additions & 3 deletions kitsune/wiki/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from bleach.css_sanitizer import CSSSanitizer
from django.conf import settings
from django.utils import translation
from django.utils.translation import gettext as _, gettext_lazy as _lazy
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _lazy
from html5lib import HTMLParser
from html5lib.filters.alphabeticalattributes import Filter as sortAttributes
from html5lib.serializer import HTMLSerializer
Expand Down Expand Up @@ -496,13 +497,15 @@ def __init__(self, doc_id, **kwargs):
def _hook_internal_link(self, parser, space, name):
"""Records links between documents, and then calls super()."""

title = name.split("|")[0]
title, *rest = map(str.strip, name.split("|"))
title = re.sub(r"\s+", " ", title)
locale = self.current_doc.locale
link_text = rest[0] if rest else ""
name = f"{title}|{link_text}" if link_text else title

linked_doc = get_object_fallback(Document, title, locale)
if linked_doc is not None:
self.current_doc.add_link_to(linked_doc, "link")

return super(WhatLinksHereParser, self)._hook_internal_link(parser, space, name)

def _hook_template(self, parser, space, name):
Expand Down

0 comments on commit e0c7dff

Please sign in to comment.