Add Markdown processing to HTML snippet text, and convert FontWarnings to use it.

This commit is contained in:
Davide P. Cervone 2013-04-10 16:28:18 -04:00
parent 07123709c3
commit 03f6e8537a
6 changed files with 116 additions and 47 deletions

View File

@ -1161,7 +1161,7 @@ MathJax.Localization = {
if (typeof data[1] === "string") { // [id,string,args] if (typeof data[1] === "string") { // [id,string,args]
var id = data[0]; if (!(id instanceof Array)) {id = [domain,id]} var id = data[0]; if (!(id instanceof Array)) {id = [domain,id]}
var phrase = this.lookupPhrase(id,data[1]); var phrase = this.lookupPhrase(id,data[1]);
result = result.concat(this.processString(phrase,data.slice(2),domain)); result = result.concat(this.processMarkdown(phrase,data.slice(2),domain));
} else if (data[1] instanceof Array) { // [domain,snippet] } else if (data[1] instanceof Array) { // [domain,snippet]
result = result.concat(this.processSnippet.apply(this,data)); result = result.concat(this.processSnippet.apply(this,data));
} else if (data.length >= 3) { // ["tag",{properties},snippet] } else if (data.length >= 3) { // ["tag",{properties},snippet]
@ -1176,6 +1176,85 @@ MathJax.Localization = {
return result; return result;
}, },
markdownPattern: /(%.)|(\*{1,3})((?:%.|.)+?)\2|(`+)((?:%.|.)+?)\4|\[((?:%.|.)+?)\]\(([^\s\)]+)\)/,
// %c or *bold*, **italics**, ***bold-italics***, or `code`, or [link](url)
processMarkdown: function (phrase,args,domain) {
var result = [], data;
//
// Split the string by the Markdown pattern
// (the text blocks are separated by
// c,stars,star-text,backtics,code-text,link-text,URL).
// Start with teh first text string from the split.
//
var parts = phrase.split(this.markdownPattern);
var string = parts[0];
//
// Loop through the matches and process them
//
for (var i = 1, m = parts.length; i < m; i += 8) {
if (parts[i+1]) { // stars (for bold/italic)
//
// Select the tag to use by number of stars (three stars requires two tags)
//
data = this.processString(parts[i+2],args,domain);
if (!(data instanceof Array)) {data = [data]}
data = [["b","i","i"][parts[i+1].length-1],{},data]; // number of stars determines type
if (parts[i+1].length === 3) {data = ["b",{},data]} // bold-italic
} else if (parts[i+3]) { // backtics (for code)
//
// Remove one leading or trailing space, and process substitutions
// Make a <code> tag
//
data = this.processString(parts[i+4].replace(/^\s/,"").replace(/\s$/,""),args,domain);
if (!(data instanceof Array)) {data = [data]}
data = ["code",{},data];
} else if (parts[i+5]) { // hyperlink
//
// Process the link text, and make an <a> tag with the URL
//
data = this.processString(parts[i+5],args,domain);
if (!(data instanceof Array)) {data = [data]}
data = ["a",{href:parts[i+6],target:"_blank"},data];
} else {
//
// Escaped character (%c) gets added into the string.
//
string += parts[i]; data = null;
}
//
// If there is a tag to insert,
// Add any pending string, then push the tag
//
if (data) {
result = this.concatString(result,string,args,domain);
result.push(data); string = "";
}
//
// Process the string that follows matches pattern
//
if (parts[i+7] !== "") {string += parts[i+7]}
};
//
// Add any pending string and return the resulting snippet
//
result = this.concatString(result,string,args,domain);
return result;
},
concatString: function (result,string,args,domain) {
if (string != "") {
//
// Process the substutions.
// If the result is not a snippet, turn it into one.
// Then concatenate the snippet to the current one
//
string = this.processString(string,args,domain);
if (!(string instanceof Array)) {string = [string]}
result = result.concat(string);
}
return result;
},
lookupPhrase: function (id,phrase,domain) { lookupPhrase: function (id,phrase,domain) {
// //
// Get the domain and messageID // Get the domain and messageID

View File

@ -190,35 +190,27 @@
fonts: [ fonts: [
["p"], ["p"],
["fonts", ["fonts",
"MathJax can use either the %1 or the %2. " + "MathJax can use either the [STIX fonts](%1) or the [MathJax TeX fonts](%2). " +
"Download and install one of those fonts to improve your MathJax experience.", "Download and install one of those fonts to improve your MathJax experience.",
[["a",{href:STIXURL,target:"_blank"},[["STIXfonts","STIX fonts"]]]], STIXURL,MATHJAXURL
[["a",{href:MATHJAXURL,target:"_blank"},[["TeXfonts","MathJax TeX fonts"]]]]
] ]
], ],
// fonts: [
// ["p"],
// ["fonts",
// "MathJax can use either the [STIX fonts](%1) or the [MathJax TeX fonts](%2)",
// "http://www.stixfonts.org/","http://www.mathjax.org/help-v2/fonts/"]
// ],
STIXfonts: [ STIXfonts: [
["p"], ["p"],
["PageDesigned", ["STIXPage",
"This page is designed to use the %1. " + "This page is designed to use the [STIX fonts](%1). " +
"Download and install those fonts to improve your MathJax experience.", "Download and install those fonts to improve your MathJax experience.",
[["a",{href:STIXURL,target:"_blank"},[["STIXfonts","STIX fonts"]]]] STIXURL
] ]
], ],
TeXfonts: [ TeXfonts: [
["p"], ["p"],
["PageDesigned", ["TeXPage",
"This page is designed to use the %1. " + "This page is designed to use the [MathJax TeX fonts](%1). " +
"Download and install those fonts to improve your MathJax experience.", "Download and install those fonts to improve your MathJax experience.",
[["a",{href:MATHJAXURL,target:"_blank"},[["TeXfonts","MathJax TeX fonts"]]]] MATHJAXURL
] ]
] ]

View File

@ -85,7 +85,7 @@
"you must specify such files explicitly. " + "you must specify such files explicitly. " +
"This page seems to use the older default %1 " + "This page seems to use the older default %1 " +
"file, and so needs to be updated. This is explained further at %2", "file, and so needs to be updated. This is explained further at %2",
[["code",{},["config/MathJax.js"]]], [["code",{},"config/MathJax.js"]],
[["p",{style:{"text-align":"center"}},[ [["p",{style:{"text-align":"center"}},[
["a", ["a",
{href:"http://www.mathjax.org/help-v2/configuration"}, {href:"http://www.mathjax.org/help-v2/configuration"},

View File

@ -40,24 +40,22 @@ MathJax.Localization.addTranslation("de","FontWarnings",{
// "browsers) could improve the quality of the mathematics on this page.", // "browsers) could improve the quality of the mathematics on this page.",
fonts: fonts:
"MathJax kann %1 oder %2 verwenden. "+ "MathJax kann [STIX Fonts](%1) oder [MathJax TeX Fonts](%2) verwenden. "+
"Herunterladen und installieren dieser Fonts wird Ihre MathJax-Erfahrung verbessern.", //TODO ???? "Herunterladen und installieren dieser Fonts wird Ihre MathJax-Erfahrung verbessern.", //TODO ????
// "MathJax can use either the %1 or the %2. " + // "MathJax can use either the [STIX Fonts](%1) or the [MathJax TeX fonts](%2). " +
// "Download and install one of those fonts to improve your MathJax experience.", // "Download and install one of those fonts to improve your MathJax experience.",
PageDesigned: STIXPage:
"Diese Seite ist optimiert fuer %1. " + "Diese Seite ist optimiert fuer [STIX Fonts](%1). " +
"Herunterladen und installieren dieser Fonts wird Ihre MathJax-Erfahrung verbessern.", //TODO ???? "Herunterladen und installieren dieser Fonts wird Ihre MathJax-Erfahrung verbessern.", //TODO ????
// "This page is designed to use the %1. " + // "This page is designed to use the %1. " +
// "Download and install those fonts to improve your MathJax experience.", // "Download and install those fonts to improve your MathJax experience.",
STIXfonts: TeXPage:
"STIX Fonts", "Diese Seite ist optimiert fuer [MathJax TeX Fonts](%1). " +
// "STIX fonts", "Herunterladen und installieren dieser Fonts wird Ihre MathJax-Erfahrung verbessern." //TODO ????
// "This page is designed to use the %1. " +
TeXfonts: // "Download and install those fonts to improve your MathJax experience."
"MathJax TeX Fonts"
// "MathJax TeX fonts"
} }
}); });

View File

@ -26,18 +26,17 @@ MathJax.Localization.addTranslation("en","FontWarnings",{
"browsers) could improve the quality of the mathematics on this page.", "browsers) could improve the quality of the mathematics on this page.",
fonts: fonts:
"MathJax can use either the %1 or the %2. " + "MathJax can use either the [STIX fonts](%1) or the [MathJax TeX fonts](%2). " +
"Download and install one of those fonts to improve your MathJax experience.", "Download and install one of those fonts to improve your MathJax experience.",
PageDesigned: STIXPage:
"This page is designed to use the %1. " + "This page is designed to use the [STIX fonts](%1). " +
"Download and install those fonts to improve your MathJax experience.", "Download and install those fonts to improve your MathJax experience.",
STIXfonts: TeXPage:
"STIX fonts", "This page is designed to use the [MathJax TeX fonts](%1). " +
"Download and install those fonts to improve your MathJax experience."
TeXfonts:
"MathJax TeX fonts"
} }
}); });

View File

@ -31,20 +31,21 @@ MathJax.Localization.addTranslation("fr","FontWarnings",{
"être améliorée.", "être améliorée.",
fonts: fonts:
"MathJax peut utiliser les %1 ou bien les %2. Téléchargez et"+ "MathJax peut utiliser les [Polices STIX](%1) ou bien les " +
"installez l'une de ces familles de polices pour améliorer votre"+ "[Polices TeX de MathJax](%2). Téléchargez et installez " +
"l'une de ces familles de polices pour améliorer votre "+
"expérience avec MathJax.", "expérience avec MathJax.",
PageDesigned: TeXPage:
"Cette page est conçue pour utiliser les %1. Téléchargez "+ "Cette page est conçue pour utiliser les [Polices STIX](%1). " +
" et installez ces polices pour améliorer votre expérience "+ "Téléchargez et installez ces polices pour améliorer votre " +
"avec MathJax", "expérience avec MathJax",
STIXfonts: TeXPage:
"Polices STIX", "Cette page est conçue pour utiliser les [Polices TeX de MathJax](%1). " +
"Téléchargez et installez ces polices pour améliorer votre " +
"expérience avec MathJax"
TeXfonts:
"Polices TeX de MathJax"
} }
}); });