Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyoho committed Aug 25, 2024
1 parent 65c482d commit ea71bd6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 113 deletions.
2 changes: 1 addition & 1 deletion app/javascript/mastodon/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const isMathjaxifyable = str => {
return [ /\$\$(.*?)\$\$/g, /\$(.*?)\$/g, /\\\((.*?)\\\)/g, /\\\[(.*?)\\\]/g, /\\begin\{.+?\}(.*?)\\end\{.+?\}/g]
.map( r => str.match(r))
.reduce((prev, elem) => prev || elem, null);
}
};

export const textForScreenReader = (intl, status, rebloggedByText = false) => {
const displayName = status.getIn(['account', 'display_name']);
Expand Down
110 changes: 35 additions & 75 deletions app/javascript/mastodon/components/status_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,9 @@ import PollContainer from 'mastodon/containers/poll_container';
import Icon from 'mastodon/components/icon';
import { autoPlayGif, languages as preloadedLanguages, translationEnabled } from 'mastodon/initial_state';

/* global MathJax */
const loadScriptOnce = require('load-script-once');

function mapAlternate(array, fn1, fn2, thisArg) {
var fn = fn1, output = [];
for (var i=0; i<array.length; i++){
output[i] = fn.call(thisArg, array[i], i, array);
fn = fn === fn1 ? fn2 : fn1;
}
return output;
}

const componentToString = c => {
let aDom = document.createElement('span');
var finished = false;
ReactDOM.render(c, aDom, () => {
finished = true;
});
while(finished == false) { }

const s = aDom.outerHTML;
console.log([aDom,s]);
result = s;

return s;
};

const mathjaxify = str => {
var s = mapAlternate(str.split(/\$\$/g),
x => x,
x => componentToString(<MathJax.Context><MathJax.Node>{x}</MathJax.Node></MathJax.Context>)).join("");
s = mapAlternate(s.split(/\$/g),
x => x,
x => componentToString(<MathJax.Context><MathJax.Node inline>{x}</MathJax.Node></MathJax.Context>)).join("");
s = s.replace(/\\\((.*?)\\\)/g,
componentToString(<MathJax.Context><MathJax.Node inline>{"$1"}</MathJax.Node></MathJax.Context>))
.replace(/\\\[(.*?)\\\]/g,
componentToString(<MathJax.Context><MathJax.Node>{"$1"}</MathJax.Node></MathJax.Context>));
console.log(s);
return s;
};

const MAX_HEIGHT = 706; // 22px * 32 (+ 2px padding at the top)

class TranslateButton extends React.PureComponent {
Expand Down Expand Up @@ -147,42 +109,40 @@ class StatusContent extends React.PureComponent {
}
}

loadScriptOnce('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
(err, script) => {
if (err) {
} else {
const options = {
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
},
TeX: {
extensions: ["AMScd.js"]
},
skipStartupTypeset: true,
showProcessingMessages: false,
messageStyle: "none",
showMathMenu: true,
showMathMenuMSIE: true,
"SVG": {
font:
"TeX"
// "STIX-Web"
// "Asana-Math"
// "Neo-Euler"
// "Gyre-Pagella"
// "Gyre-Termes"
// "Latin-Modern"
},
"HTML-CSS": {
availableFonts: ["TeX"],
preferredFont: "TeX",
webFont: "TeX"
}
};
MathJax.Hub.Config(options);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, node]);
}
});
loadScriptOnce('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML')
.then(() => {
const options = {
tex2jax: {
inlineMath: [ ['$', '$'], ['\\(', '\\)'] ],
},
TeX: {
extensions: ['AMScd.js'],
},
skipStartupTypeset: true,
showProcessingMessages: false,
messageStyle: 'none',
showMathMenu: true,
showMathMenuMSIE: true,
'SVG': {
font:
'TeX',
// "STIX-Web"
// "Asana-Math"
// "Neo-Euler"
// "Gyre-Pagella"
// "Gyre-Termes"
// "Latin-Modern"
},
'HTML-CSS': {
availableFonts: ['TeX'],
preferredFont: 'TeX',
webFont: 'TeX',
},
};
MathJax.Hub.Config(options);
MathJax.Hub.Queue(['Typeset', MathJax.Hub, node]);
})
.catch(err => console.error('failed to load!', err));


if (status.get('collapsed', null) === null && onCollapsedToggle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import Icon from 'mastodon/components/icon';
import { Spring } from 'react-spring/renderprops';

const isMathjaxifyable = str =>
[ /\$\$([\s\S]+?)\$\$/g, /\$([\s\S]+?)\$/g, /\\\(([\s\S]+?)\\\)/g, /\\\[([\s\S]+?)\\\]/g]
.map( r => str.match(r))
.reduce((prev, elem) => prev || elem, false);
[ /\$\$([\s\S]+?)\$\$/g, /\$([\s\S]+?)\$/g, /\\\(([\s\S]+?)\\\)/g, /\\\[([\s\S]+?)\\\]/g]
.map( r => str.match(r))
.reduce((prev, elem) => prev || elem, false);

const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';

Expand Down Expand Up @@ -304,12 +304,13 @@ class ComposeForm extends ImmutablePureComponent {
</div>
</div>
<Spring
config={{tension: 273, friction: 17, mass: 0.8 }}
config={{ tension: 273, friction: 17, mass: 0.8 }}
from={{ opacity: flag ? 0 : 1, transform: flag ? 'scale(0)' : 'scale(1)' }}
to= {{ opacity: flag ? 1 : 0, transform: flag ? 'scale(1)' : 'scale(0)' }}>
{props => <div style={props} className='compose-form__live-preview'>
<LivePreview text={this.props.text} />
</div>
to={{ opacity: flag ? 1 : 0, transform: flag ? 'scale(1)' : 'scale(0)' }}
>
{props => (<div style={props} className='compose-form__live-preview'>
<LivePreview text={this.props.text} />
</div>)
}
</Spring>
</form>
Expand Down
25 changes: 14 additions & 11 deletions app/javascript/mastodon/features/compose/components/live_preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import emojify from '../../emoji/emoji';
import { debounce } from 'react-decoration';
const loadScriptOnce = require('load-script-once');

/* global MathJax */
// const loadScriptOnce = require('load-script-once');

class LivePreview extends React.PureComponent {

constructor (props, context) {
super(props, context);
this.nodeRef = React.createRef();
this.state = {
textToRender: ''
textToRender: '',
};
}

Expand All @@ -19,28 +22,28 @@ class LivePreview extends React.PureComponent {

this.setState({ textToRender: text });
this.render();
const node = ReactDOM.findDOMNode(this);
if (MathJax != undefined) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, node]);
const node = this.nodeRef.current;
if (MathJax !== undefined) {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, node]);
}
}

componentWillUpdate() {
}

componentDidUpdate() {
this.changeTextToRender();
}

render () {
const text = this.state.textToRender;
return <div dangerouslySetInnerHTML={{ __html: emojify(text)}} />
return <div dangerouslySetInnerHTML={{ __html: emojify(text) }} />;
}

}

LivePreview.propTypes = {
text: PropTypes.string.isRequired,
}
};

export default LivePreview;
38 changes: 20 additions & 18 deletions app/javascript/packs/public.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './public-path';
import escapeTextContentForBrowser from 'escape-html';
import loadPolyfills from '../mastodon/load_polyfills';

var loadScript = require('load-script');

import ready from '../mastodon/ready';
Expand Down Expand Up @@ -37,37 +38,38 @@ function main() {
const ReactDOM = require('react-dom');
const { createBrowserHistory } = require('history');

/* global MathJax */
loadScript('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML', function () {
const options = {
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
inlineMath: [ ['$', '$'], ['\\(', '\\)'] ],
},
TeX: {
extensions: ["AMScd.js"]
extensions: ['AMScd.js'],
},
skipStartupTypeset: true,
showProcessingMessages: false,
messageStyle: "none",
messageStyle: 'none',
showMathMenu: true,
showMathMenuMSIE: true,
"SVG": {
font:
"TeX"
// "STIX-Web"
// "Asana-Math"
// "Neo-Euler"
// "Gyre-Pagella"
// "Gyre-Termes"
// "Latin-Modern"
'SVG': {
font:
'TeX',
// 'STIX-Web'
// 'Asana-Math'
// 'Neo-Euler'
// 'Gyre-Pagella'
// 'Gyre-Termes'
// 'Latin-Modern'
},
'HTML-CSS': {
availableFonts: ['TeX'],
preferredFont: 'TeX',
webFont: 'TeX',
},
"HTML-CSS": {
availableFonts: ["TeX"],
preferredFont: "TeX",
webFont: "TeX"
}
};
MathJax.Hub.Config(options);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, ""]);
MathJax.Hub.Queue(['Typeset', MathJax.Hub, '']);
});

const scrollToDetailedStatus = () => {
Expand Down

0 comments on commit ea71bd6

Please sign in to comment.