forked from Mirrors/apostrophe
Added handling of alternate form of urls
parent
26077831fa
commit
300c386631
|
@ -168,6 +168,7 @@ class InlinePreview:
|
||||||
markup_regex.MATH: self.get_view_for_math,
|
markup_regex.MATH: self.get_view_for_math,
|
||||||
markup_regex.IMAGE: self.get_view_for_image,
|
markup_regex.IMAGE: self.get_view_for_image,
|
||||||
markup_regex.LINK: self.get_view_for_link,
|
markup_regex.LINK: self.get_view_for_link,
|
||||||
|
markup_regex.LINK_ALT: self.get_view_for_link,
|
||||||
markup_regex.FOOTNOTE_ID: self.get_view_for_footnote,
|
markup_regex.FOOTNOTE_ID: self.get_view_for_footnote,
|
||||||
re.compile(r"(?P<text>\w+)"): self.get_view_for_lexikon
|
re.compile(r"(?P<text>\w+)"): self.get_view_for_lexikon
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ CODE = re.compile(
|
||||||
r"`(?P<text>[^`].+?)`")
|
r"`(?P<text>[^`].+?)`")
|
||||||
LINK = re.compile(
|
LINK = re.compile(
|
||||||
r"\[(?P<text>.*)\]\((?P<url>.+?)(?: \"(?P<title>.+)\")?\)")
|
r"\[(?P<text>.*)\]\((?P<url>.+?)(?: \"(?P<title>.+)\")?\)")
|
||||||
|
LINK_ALT = re.compile(
|
||||||
|
r"(?:<)(?P<url>http://[^\s]+)(?:>)")
|
||||||
IMAGE = re.compile(
|
IMAGE = re.compile(
|
||||||
r"!\[(?P<text>.*)\]\((?P<url>.+?)(?: \"(?P<title>.+)\")?\)")
|
r"!\[(?P<text>.*)\]\((?P<url>.+?)(?: \"(?P<title>.+)\")?\)")
|
||||||
HORIZONTAL_RULE = re.compile(
|
HORIZONTAL_RULE = re.compile(
|
||||||
|
|
|
@ -3,7 +3,7 @@ from multiprocessing import Process, Pipe
|
||||||
|
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
from uberwriter.markup_regex import ITALIC, BOLD_ITALIC, BOLD, STRIKETHROUGH, IMAGE, LINK, \
|
from uberwriter.markup_regex import ITALIC, BOLD_ITALIC, BOLD, STRIKETHROUGH, IMAGE, LINK, LINK_ALT,\
|
||||||
HORIZONTAL_RULE, LIST, MATH, TABLE, CODE_BLOCK, HEADER_UNDER, HEADER, BLOCK_QUOTE, ORDERED_LIST, \
|
HORIZONTAL_RULE, LIST, MATH, TABLE, CODE_BLOCK, HEADER_UNDER, HEADER, BLOCK_QUOTE, ORDERED_LIST, \
|
||||||
FOOTNOTE_ID, FOOTNOTE
|
FOOTNOTE_ID, FOOTNOTE
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ class StatsCounter:
|
||||||
BOLD_ITALIC, ITALIC, BOLD, STRIKETHROUGH, IMAGE, LINK, LIST, ORDERED_LIST, BLOCK_QUOTE,
|
BOLD_ITALIC, ITALIC, BOLD, STRIKETHROUGH, IMAGE, LINK, LIST, ORDERED_LIST, BLOCK_QUOTE,
|
||||||
HEADER, HEADER_UNDER, CODE_BLOCK, TABLE, MATH, FOOTNOTE_ID, FOOTNOTE
|
HEADER, HEADER_UNDER, CODE_BLOCK, TABLE, MATH, FOOTNOTE_ID, FOOTNOTE
|
||||||
)
|
)
|
||||||
|
MARKUP_REGEXP_URL_REPLACE = (
|
||||||
|
LINK_ALT,
|
||||||
|
)
|
||||||
|
|
||||||
# List of regexp whose matches should be removed. Order is important.
|
# List of regexp whose matches should be removed. Order is important.
|
||||||
MARKUP_REGEXP_REMOVE = (
|
MARKUP_REGEXP_REMOVE = (
|
||||||
|
@ -75,6 +78,8 @@ class StatsCounter:
|
||||||
child_conn.close()
|
child_conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for regexp in self.MARKUP_REGEXP_URL_REPLACE:
|
||||||
|
text = re.sub(regexp, r"\g<url>", text)
|
||||||
for regexp in self.MARKUP_REGEXP_REPLACE:
|
for regexp in self.MARKUP_REGEXP_REPLACE:
|
||||||
text = re.sub(regexp, r"\g<text>", text)
|
text = re.sub(regexp, r"\g<text>", text)
|
||||||
for regexp in self.MARKUP_REGEXP_REMOVE:
|
for regexp in self.MARKUP_REGEXP_REMOVE:
|
||||||
|
|
|
@ -20,7 +20,7 @@ from multiprocessing import Pipe, Process
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
from uberwriter import helpers, markup_regex
|
from uberwriter import helpers, markup_regex
|
||||||
from uberwriter.markup_regex import STRIKETHROUGH, BOLD_ITALIC, BOLD, ITALIC, IMAGE, LINK, \
|
from uberwriter.markup_regex import STRIKETHROUGH, BOLD_ITALIC, BOLD, ITALIC, IMAGE, LINK, LINK_ALT, \
|
||||||
HORIZONTAL_RULE, LIST, ORDERED_LIST, BLOCK_QUOTE, HEADER, HEADER_UNDER, TABLE, MATH, CODE
|
HORIZONTAL_RULE, LIST, ORDERED_LIST, BLOCK_QUOTE, HEADER, HEADER_UNDER, TABLE, MATH, CODE
|
||||||
|
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
|
@ -203,6 +203,12 @@ class MarkupHandler:
|
||||||
result.append((tag_name, (), match.start(), match.start("text")))
|
result.append((tag_name, (), match.start(), match.start("text")))
|
||||||
result.append((tag_name, (), match.end("text"), match.end()))
|
result.append((tag_name, (), match.end("text"), match.end()))
|
||||||
|
|
||||||
|
# - "<url>" (gray out)
|
||||||
|
matches = re.finditer(LINK_ALT, text)
|
||||||
|
for match in matches:
|
||||||
|
result.append((
|
||||||
|
self.TAG_NAME_GRAY_TEXT, (), match.start("url"), match.end("url")))
|
||||||
|
|
||||||
# Find "---" horizontal rule (center).
|
# Find "---" horizontal rule (center).
|
||||||
matches = re.finditer(HORIZONTAL_RULE, text)
|
matches = re.finditer(HORIZONTAL_RULE, text)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
|
|
Loading…
Reference in New Issue