Skip to content

Commit

Permalink
Minor external link fix
Browse files Browse the repository at this point in the history
* Added support for "javascript:" URIs in external links, and fixed
"mailto:" syntax highlighting.
* Also fixed it so that 'state' is undefined while script passages are
executed. This should fix a bug with some popular old scripts.
  • Loading branch information
webbedspace committed Dec 17, 2013
1 parent 0dc3e61 commit 0dea8c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions targets/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ Wikifier.formatters = [
}),
{
name: "urlLink",
match: "(?:http|https|mailto|ftp):[^\\s'\"]+(?:/|\\b)",
match: "(?:http|https|mailto|javascript|ftp):[^\\s'\"]+(?:/|\\b)",
handler: function (w) {
var e = Wikifier.createExternalLink(w.output, w.matchText);
w.outputText(e, w.matchStart, w.nextMatch);
Expand Down Expand Up @@ -1795,15 +1795,14 @@ function main() {
$ = window.$ || function(a) {
return (typeof a == "string" ? document.getElementById(a) : a);
}
var imgs, scripts, macro, style, styleText = "", i, p = document.getElementById("passages");
var imgs, scripts, macro, style, styleText = "", i, passages = document.getElementById("passages");

if (!window.JSON) {
return (p.innerHTML = "This story requires a newer web browser. Sorry.");
return (passages.innerHTML = "This story requires a newer web browser. Sorry.");
} else {
p.innerHTML = "";
}
passages.innerHTML = "";
}
tale = window.tale = new Tale();
state = window.state = new History();
document.title = tale.title;

if (~document.documentElement.className.indexOf("lt-ie9")) {
Expand Down Expand Up @@ -1848,5 +1847,7 @@ function main() {
}
}
style.styleSheet ? (style.styleSheet.cssText = styleText) : (style.innerHTML = styleText);

state = window.state = new History();
state.init();
}
2 changes: 1 addition & 1 deletion tweelexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def applyMacroStyle(pos, m):
def badLinkStyle(dest, external = False):
# Apply style for a link destination which does not seem to be an existent passage
if external:
for t in ['http://', 'https://', 'ftp://']:
for t in ['http://', 'https://', 'ftp://', 'mailto:', 'javascript:']:
if t in dest.lower():
return self.EXTERNAL
iscode = re.search(self.MACRO_PARAMS_VAR_REGEX+"|"+self.MACRO_PARAMS_FUNC_REGEX, dest, re.U)
Expand Down

0 comments on commit 0dea8c5

Please sign in to comment.