[ckan-changes] commit/ckan: 6 new changesets
Bitbucket
commits-noreply at bitbucket.org
Tue Oct 4 12:14:59 UTC 2011
6 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/7457aeb00834/
changeset: 7457aeb00834
branch: feature-1320-markdown
user: zephod
date: 2011-10-03 16:57:27
summary: [markdown editor][s]: Compiled an extra regex to turn http:// literals into links automatically. CKAN-flavoured markdown.
affected #: 3 files (-1 bytes)
--- a/ckan/config/routing.py Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/config/routing.py Mon Oct 03 15:57:27 2011 +0100
@@ -104,8 +104,6 @@
map.connect('/api/search/{register}', controller='api', action='search')
map.connect('/api/tag_counts', controller='api', action='tag_counts')
-
- map.connect('/api/markdown', controller='api', action='markdown')
map.connect('/api/rest', controller='api', action='index')
@@ -167,6 +165,8 @@
map.connect('/api/2/util/authorizationgroup/autocomplete', controller='api',
action='authorizationgroup_autocomplete')
+ map.connect('/api/util/markdown', controller='api', action='markdown')
+
###########
## /END API
###########
--- a/ckan/misc.py Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/misc.py Mon Oct 03 15:57:27 2011 +0100
@@ -13,7 +13,7 @@
class MarkdownFormat(TextFormat):
- internal_link = re.compile('(package|tag|group):([a-z0-9\-_]+)')
+ internal_link = re.compile('(dataset|package|tag|group):([a-z0-9\-_]+)')
normal_link = re.compile('<(http:[^>]+)>')
html_whitelist = 'b center li ol p table td tr ul'.split(' ')
@@ -24,6 +24,7 @@
any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
+ web_address = re.compile(r'([^\[\<\(]|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
def to_html(self, text):
if text is None:
@@ -31,6 +32,9 @@
# Encode whitelist elements.
text = self.whitelist_elem.sub(r'\\\\xfc\\\\xfd\1\\\\xfd\\\\xfc', text)
+ # Discover external addresses and make them links
+ text = self.web_address.sub(r'\1<\2>', text)
+
# Encode links only in an acceptable format (guard against spammers)
text = self.normal_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc', text)
text = self.abbrev_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc\1</a>', text)
@@ -45,7 +49,7 @@
# Convert <link> to markdown format.
text = self.normal_link.sub(r'[\1] (\1)', text)
-
+
# Markdown to HTML.
text = webhelpers.markdown.markdown(text, safe_mode=True)
--- a/ckan/public/scripts/application.js Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/public/scripts/application.js Mon Oct 03 15:57:27 2011 +0100
@@ -226,7 +226,7 @@
if (action=='preview') {
raw_markdown=textarea.val();
preview.html("<em>"+CKAN.Strings.loading+"<em>");
- $.post("/api/markdown", { q: raw_markdown },
+ $.post("/api/util/markdown", { q: raw_markdown },
function(data) { preview.html(data); }
);
preview.width(textarea.width())
http://bitbucket.org/okfn/ckan/changeset/e379b4b0edce/
changeset: e379b4b0edce
branch: feature-1320-markdown
user: zephod
date: 2011-10-03 16:57:35
summary: [close-branch]:
affected #: 0 files (-1 bytes)
http://bitbucket.org/okfn/ckan/changeset/114fdebbb0da/
changeset: 114fdebbb0da
user: zephod
date: 2011-10-04 12:21:09
summary: [merge,from-branch]: Fixed markdown editor issues.
affected #: 3 files (-1 bytes)
--- a/ckan/config/routing.py Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/config/routing.py Tue Oct 04 11:21:09 2011 +0100
@@ -104,8 +104,6 @@
map.connect('/api/search/{register}', controller='api', action='search')
map.connect('/api/tag_counts', controller='api', action='tag_counts')
-
- map.connect('/api/markdown', controller='api', action='markdown')
map.connect('/api/rest', controller='api', action='index')
@@ -167,6 +165,8 @@
map.connect('/api/2/util/authorizationgroup/autocomplete', controller='api',
action='authorizationgroup_autocomplete')
+ map.connect('/api/util/markdown', controller='api', action='markdown')
+
###########
## /END API
###########
--- a/ckan/misc.py Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/misc.py Tue Oct 04 11:21:09 2011 +0100
@@ -13,7 +13,7 @@
class MarkdownFormat(TextFormat):
- internal_link = re.compile('(package|tag|group):([a-z0-9\-_]+)')
+ internal_link = re.compile('(dataset|package|tag|group):([a-z0-9\-_]+)')
normal_link = re.compile('<(http:[^>]+)>')
html_whitelist = 'b center li ol p table td tr ul'.split(' ')
@@ -24,6 +24,7 @@
any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
+ web_address = re.compile(r'([^\[\<\(]|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
def to_html(self, text):
if text is None:
@@ -31,6 +32,9 @@
# Encode whitelist elements.
text = self.whitelist_elem.sub(r'\\\\xfc\\\\xfd\1\\\\xfd\\\\xfc', text)
+ # Discover external addresses and make them links
+ text = self.web_address.sub(r'\1<\2>', text)
+
# Encode links only in an acceptable format (guard against spammers)
text = self.normal_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc', text)
text = self.abbrev_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc\1</a>', text)
@@ -45,7 +49,7 @@
# Convert <link> to markdown format.
text = self.normal_link.sub(r'[\1] (\1)', text)
-
+
# Markdown to HTML.
text = webhelpers.markdown.markdown(text, safe_mode=True)
--- a/ckan/public/scripts/application.js Mon Oct 03 10:32:58 2011 +0100
+++ b/ckan/public/scripts/application.js Tue Oct 04 11:21:09 2011 +0100
@@ -226,7 +226,7 @@
if (action=='preview') {
raw_markdown=textarea.val();
preview.html("<em>"+CKAN.Strings.loading+"<em>");
- $.post("/api/markdown", { q: raw_markdown },
+ $.post("/api/util/markdown", { q: raw_markdown },
function(data) { preview.html(data); }
);
preview.width(textarea.width())
http://bitbucket.org/okfn/ckan/changeset/79060594b3d8/
changeset: 79060594b3d8
branch: feature-1320-markdown
user: zephod
date: 2011-10-04 14:13:13
summary: [markdown][s]: Tests to verify CKAN flavoured markdown.
affected #: 2 files (-1 bytes)
--- a/ckan/misc.py Mon Oct 03 15:57:35 2011 +0100
+++ b/ckan/misc.py Tue Oct 04 13:13:13 2011 +0100
@@ -24,7 +24,7 @@
any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
- web_address = re.compile(r'([^\[\<\(]|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
+ web_address = re.compile(r'(\s|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
def to_html(self, text):
if text is None:
@@ -49,7 +49,7 @@
# Convert <link> to markdown format.
text = self.normal_link.sub(r'[\1] (\1)', text)
-
+
# Markdown to HTML.
text = webhelpers.markdown.markdown(text, safe_mode=True)
--- a/ckan/tests/misc/test_format_text.py Mon Oct 03 15:57:35 2011 +0100
+++ b/ckan/tests/misc/test_format_text.py Tue Oct 04 13:13:13 2011 +0100
@@ -46,6 +46,20 @@
out = format.to_html(instr)
assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+ def test_auto_link(self):
+ instr = 'http://somelink.com'
+ exp = '<a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+ format = MarkdownFormat()
+ out = format.to_html(instr)
+ assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
+ def test_auto_link_after_whitespace(self):
+ instr = 'go to http://somelink.com'
+ exp = 'go to <a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+ format = MarkdownFormat()
+ out = format.to_html(instr)
+ assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
def test_malformed_link_1(self):
instr = u'<a href=\u201dsomelink\u201d>somelink</a>'
exp = '<a href="TAG MALFORMED" target="_blank" rel="nofollow">somelink</a>'
http://bitbucket.org/okfn/ckan/changeset/8669c25b4af5/
changeset: 8669c25b4af5
branch: feature-1320-markdown
user: zephod
date: 2011-10-04 14:13:36
summary: [close-branch]:
affected #: 0 files (-1 bytes)
http://bitbucket.org/okfn/ckan/changeset/f9dfb0506594/
changeset: f9dfb0506594
user: zephod
date: 2011-10-04 14:14:14
summary: [merge,from-branch]: Markdown editor changes.
affected #: 2 files (-1 bytes)
--- a/ckan/misc.py Tue Oct 04 11:21:09 2011 +0100
+++ b/ckan/misc.py Tue Oct 04 13:14:14 2011 +0100
@@ -24,7 +24,7 @@
any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
- web_address = re.compile(r'([^\[\<\(]|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
+ web_address = re.compile(r'(\s|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
def to_html(self, text):
if text is None:
@@ -49,7 +49,7 @@
# Convert <link> to markdown format.
text = self.normal_link.sub(r'[\1] (\1)', text)
-
+
# Markdown to HTML.
text = webhelpers.markdown.markdown(text, safe_mode=True)
--- a/ckan/tests/misc/test_format_text.py Tue Oct 04 11:21:09 2011 +0100
+++ b/ckan/tests/misc/test_format_text.py Tue Oct 04 13:14:14 2011 +0100
@@ -46,6 +46,20 @@
out = format.to_html(instr)
assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+ def test_auto_link(self):
+ instr = 'http://somelink.com'
+ exp = '<a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+ format = MarkdownFormat()
+ out = format.to_html(instr)
+ assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
+ def test_auto_link_after_whitespace(self):
+ instr = 'go to http://somelink.com'
+ exp = 'go to <a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+ format = MarkdownFormat()
+ out = format.to_html(instr)
+ assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
def test_malformed_link_1(self):
instr = u'<a href=\u201dsomelink\u201d>somelink</a>'
exp = '<a href="TAG MALFORMED" target="_blank" rel="nofollow">somelink</a>'
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list