Merge pull request #1552 from dpvc/issue1022

Handle hrefs during line breaking.  #1022
This commit is contained in:
Davide P. Cervone 2016-07-23 15:59:56 -04:00 committed by GitHub
commit f5e818cc21
4 changed files with 31 additions and 19 deletions

View File

@ -312,6 +312,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
if (this.CHTML.R && margin !== "marginRight") state.bbox.w += this.CHTML.R; if (this.CHTML.R && margin !== "marginRight") state.bbox.w += this.CHTML.R;
if (end.length === 0) { if (end.length === 0) {
node = this.CHTMLnodeElement(); node = this.CHTMLnodeElement();
if (this.href) node = node.parentNode;
node.parentNode.removeChild(node); node.parentNode.removeChild(node);
node.nextMathJaxNode.id = node.id; node.nextMathJaxNode.id = node.id;
} }
@ -326,6 +327,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
// //
CHTMLcreateSliceNode: function (node) { CHTMLcreateSliceNode: function (node) {
var NODE = this.CHTMLnodeElement(), n = 0; var NODE = this.CHTMLnodeElement(), n = 0;
if (this.href) NODE = NODE.parentNode;
var LAST = NODE; while (LAST.nextMathJaxNode) {LAST = LAST.nextMathJaxNode; n++} var LAST = NODE; while (LAST.nextMathJaxNode) {LAST = LAST.nextMathJaxNode; n++}
var SLICE = NODE.cloneNode(false); LAST.nextMathJaxNode = SLICE; SLICE.nextMathJaxNode = null; var SLICE = NODE.cloneNode(false); LAST.nextMathJaxNode = SLICE; SLICE.nextMathJaxNode = null;
SLICE.id += "-MJX-Continue-"+n; SLICE.id += "-MJX-Continue-"+n;
@ -347,6 +349,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
// Move node // Move node
// //
var node = this.CHTMLnodeElement(); var node = this.CHTMLnodeElement();
if (this.href) node = node.parentNode;
line.appendChild(node); line.appendChild(node);
if (this.CHTML.pwidth && !line.style.width) line.style.width = this.CHTML.pwidth; if (this.CHTML.pwidth && !line.style.width) line.style.width = this.CHTML.pwidth;
// //
@ -565,7 +568,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
}, },
CHTMLmoveLine: function (start,end,node,state,values) { CHTMLmoveLine: function (start,end,node,state,values) {
var NODE = this.CHTMLnodeElement(), BOX = this.CHTMLbbox, w; var NODE, BOX = this.CHTMLbbox, w;
// //
// If this is the start, move the prescripts, if any. // If this is the start, move the prescripts, if any.
// //

View File

@ -315,10 +315,13 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
this.HTMLcleanBBox(slice.bbox); this.HTMLcleanBBox(slice.bbox);
if (end.length === 0) { if (end.length === 0) {
span = this.HTMLspanElement(); span = this.HTMLspanElement();
if (this.href) span = span.parentNode;
span.parentNode.removeChild(span); span.parentNode.removeChild(span);
span.nextMathJaxSpan.id = span.id; var n = 0; span.nextMathJaxSpan.id = span.id; var n = 0;
while (span = span.nextMathJaxSpan) { while (span = span.nextMathJaxSpan) {
var color = this.HTMLhandleColor(span); var SPAN = span;
if (SPAN.nodeName.toLowerCase() === "a") SPAN = SPAN.firstChild;
var color = this.HTMLhandleColor(SPAN);
if (color) {color.id += "-MathJax-Continue-"+n; n++} if (color) {color.id += "-MathJax-Continue-"+n; n++}
} }
} }
@ -333,6 +336,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
// //
HTMLcreateSliceSpan: function (span) { HTMLcreateSliceSpan: function (span) {
var SPAN = this.HTMLspanElement(), n = 0; var SPAN = this.HTMLspanElement(), n = 0;
if (this.href) SPAN = SPAN.parentNode;
var LAST = SPAN; while (LAST.nextMathJaxSpan) {LAST = LAST.nextMathJaxSpan; n++} var LAST = SPAN; while (LAST.nextMathJaxSpan) {LAST = LAST.nextMathJaxSpan; n++}
var SLICE = SPAN.cloneNode(false); LAST.nextMathJaxSpan = SLICE; SLICE.nextMathJaxSpan = null; var SLICE = SPAN.cloneNode(false); LAST.nextMathJaxSpan = SLICE; SLICE.nextMathJaxSpan = null;
SLICE.id += "-MathJax-Continue-"+n; SLICE.id += "-MathJax-Continue-"+n;
@ -357,6 +361,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var color = document.getElementById("MathJax-Color-"+this.spanID+HTMLCSS.idPostfix); var color = document.getElementById("MathJax-Color-"+this.spanID+HTMLCSS.idPostfix);
if (color) {line.appendChild(color)} if (color) {line.appendChild(color)}
var span = this.HTMLspanElement(); var span = this.HTMLspanElement();
if (this.href) span = span.parentNode;
line.appendChild(span); line.appendChild(span);
// //
// If it is last, remove right padding // If it is last, remove right padding
@ -515,7 +520,9 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
if (end.length === 0) { if (end.length === 0) {
var s = this.data[this.sup] || this.data[this.sub]; var s = this.data[this.sup] || this.data[this.sub];
if (s && this.HTMLnotEmpty(s)) { if (s && this.HTMLnotEmpty(s)) {
var box = s.HTMLspanElement().parentNode, stack = box.parentNode; var box = s.HTMLspanElement().parentNode;
if (s.href) box = box.parentNode;
var stack = box.parentNode;
if (this.data[this.base]) {stack.removeChild(stack.firstChild)} if (this.data[this.base]) {stack.removeChild(stack.firstChild)}
for (box = stack.firstChild; box; box = box.nextSibling) for (box = stack.firstChild; box; box = box.nextSibling)
{box.style.left = HTMLCSS.Em(HTMLCSS.unEm(box.style.left)-this.HTMLbaseW)} {box.style.left = HTMLCSS.Em(HTMLCSS.unEm(box.style.left)-this.HTMLbaseW)}

View File

@ -308,6 +308,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
var slice = BBOX(); var slice = BBOX();
this.SVGmoveLine(start,end,slice,state,values); this.SVGmoveLine(start,end,slice,state,values);
slice.Clean(); slice.Clean();
if (this.href) {this.SVGaddHref(slice)}
this.SVGhandleColor(slice); this.SVGhandleColor(slice);
svg.Add(slice,svg.w,0,true); svg.Add(slice,svg.w,0,true);
return slice; return slice;

View File

@ -1130,22 +1130,7 @@
// FIXME: if an element is split by linebreaking, the ID will be the same on both parts // FIXME: if an element is split by linebreaking, the ID will be the same on both parts
// FIXME: if an element has an id, its zoomed copy will have the same ID // FIXME: if an element has an id, its zoomed copy will have the same ID
if (this.id) {svg.removeable = false; SVG.Element(svg.element,{"id":this.id})} if (this.id) {svg.removeable = false; SVG.Element(svg.element,{"id":this.id})}
if (this.href) { if (this.href) {this.SVGaddHref(svg)}
var a = SVG.Element("a",{"class":"mjx-svg-href"});
a.setAttributeNS(XLINKNS,"href",this.href);
a.onclick = this.SVGlink;
SVG.addElement(a,"rect",{width:svg.w, height:svg.h+svg.d, y:-svg.d,
fill:"none", stroke:"none", "pointer-events":"all"});
if (svg.type === "svg") {
// for svg element, put <a> inside the main <g> element
var g = svg.element.firstChild;
while (g.firstChild) {a.appendChild(g.firstChild)}
g.appendChild(a);
} else {
a.appendChild(svg.element); svg.element = a;
}
svg.removeable = false;
}
if (SVG.config.addMMLclasses) { if (SVG.config.addMMLclasses) {
this.SVGaddClass(svg.element,"mjx-svg-"+this.type); this.SVGaddClass(svg.element,"mjx-svg-"+this.type);
svg.removeable = false; svg.removeable = false;
@ -1185,6 +1170,22 @@
} }
} }
}, },
SVGaddHref: function (svg) {
var a = SVG.Element("a",{"class":"mjx-svg-href"});
a.setAttributeNS(XLINKNS,"href",this.href);
a.onclick = this.SVGlink;
SVG.addElement(a,"rect",{width:svg.w, height:svg.h+svg.d, y:-svg.d,
fill:"none", stroke:"none", "pointer-events":"all"});
if (svg.type === "svg") {
// for svg element, put <a> inside the main <g> element
var g = svg.element.firstChild;
while (g.firstChild) {a.appendChild(g.firstChild)}
g.appendChild(a);
} else {
a.appendChild(svg.element); svg.element = a;
}
svg.removeable = false;
},
// //
// WebKit currently scrolls to the BOTTOM of an svg element if it contains the // WebKit currently scrolls to the BOTTOM of an svg element if it contains the
// target of the link, so implement link by hand, to the containing span element. // target of the link, so implement link by hand, to the containing span element.