Skip to content

Commit 67edee6

Browse files
committed
Support for \boxed{} and \slash{} in Chrome.
Chrome doesn't support <menclose>. Thanks to Monica Kang with the styling of \slash{}.
1 parent f6393ff commit 67edee6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

public/javascripts/page_helper.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ function hrefShim() {
364364
}
365365

366366
function replaceWithName(node, name) {
367-
newNode = document.createElement(name);
367+
var newNode = document.createElement(name);
368368
var children = node.childNodes;
369369
for (var i = 0; i < children.length; i++){
370370
var child = document.importNode(children[i], true);
@@ -377,6 +377,34 @@ function replaceWithName(node, name) {
377377
node.parentNode.replaceChild(newNode, node);
378378
}
379379

380+
function mencloseShim() {
381+
var div = document.createElement('div');
382+
var menc = document.createElementNS('http://www.w3.org/1998/Math/MathML', 'menclose');
383+
var mi = document.createElementNS('http://www.w3.org/1998/Math/MathML', 'mi');
384+
menc.setAttribute('notation', 'box');
385+
mi.textContent = '1';
386+
menc.appendChild(mi);
387+
div.appendChild(menc);
388+
document.body.appendChild(div);
389+
mencloseSupported = (div.getBoundingClientRect().height > mi.getBoundingClientRect().height);
390+
document.body.removeChild(div);
391+
if (!mencloseSupported) {
392+
var boxes = document.querySelectorAll('menclose[notation=box]');
393+
if (boxes[0]) {
394+
for (var i = 0; i < boxes.length; i++){
395+
boxes[i].style.border = '1px solid';
396+
boxes[i].style.padding = '3px';
397+
}
398+
}
399+
var slashed = document.querySelectorAll('menclose[notation=updiagonalstrike]');
400+
if (slashed[0]) {
401+
for (var i = 0; i < slashed.length; i++){
402+
slashed[i].className = 'strikediag';
403+
}
404+
}
405+
}
406+
}
407+
380408
function minMathWidth() {
381409
var maths = document.querySelectorAll('math[display=block], table');
382410
if (maths && maths.length > 0) {
@@ -405,4 +433,5 @@ document.observe("dom:loaded", function (){
405433
tableAlignShim();
406434
minMathWidth();
407435
hrefShim();
436+
mencloseShim();
408437
});

public/stylesheets/instiki.css

+15
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,21 @@ annotation-xml[encoding="SVG1.1"] {
537537
[actiontype="toggle"]:hover {text-shadow: #ccc 2px 2px 5px;}
538538
.maruku_toc ul { list-style: none; }
539539

540+
.strikediag {
541+
display: inline-block;
542+
position: relative;
543+
}
544+
.strikediag:before {
545+
position: absolute;
546+
content: "";
547+
left: 2.5px;
548+
padding: 10px 15px 10px 5px;
549+
top: 20%;
550+
right: 0;
551+
border-top: 1px solid;
552+
border-color: inherit;
553+
transform:rotate(-50deg);}
554+
540555
/* The STIX Two fonts are licensed under the SIL Open Font License, Version 1.1, http://scripts.sil.org/OFL */
541556
math {font-family: STIX Two Math;}
542557
mtext {font-family: STIX Two Text;}

0 commit comments

Comments
 (0)