Skip to content

Commit

Permalink
apply autolatex and mathjax
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Oct 9, 2019
1 parent 83d3e77 commit 004c55b
Show file tree
Hide file tree
Showing 6 changed files with 898 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/javascript/mastodon/components/autosuggest_textarea.js
Expand Up @@ -8,6 +8,7 @@ import { isRtl } from '../rtl';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import Textarea from 'react-textarea-autosize'; import Textarea from 'react-textarea-autosize';
import classNames from 'classnames'; import classNames from 'classnames';
import try_replace from '../features/compose/util/autolatex.js';


const textAtCursorMatchesToken = (str, caretPosition) => { const textAtCursorMatchesToken = (str, caretPosition) => {
let word; let word;
Expand Down Expand Up @@ -77,6 +78,10 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
this.props.onChange(e); this.props.onChange(e);
} }


onInput = (e) => {
try_replace(e.target);
}

onKeyDown = (e) => { onKeyDown = (e) => {
const { suggestions, disabled } = this.props; const { suggestions, disabled } = this.props;
const { selectedSuggestion, suggestionsHidden } = this.state; const { selectedSuggestion, suggestionsHidden } = this.state;
Expand Down Expand Up @@ -216,6 +221,7 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
value={value} value={value}
onChange={this.onChange} onChange={this.onChange}
onKeyDown={this.onKeyDown} onKeyDown={this.onKeyDown}
onInput={this.onInput}
onKeyUp={onKeyUp} onKeyUp={onKeyUp}
onFocus={this.onFocus} onFocus={this.onFocus}
onBlur={this.onBlur} onBlur={this.onBlur}
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/mastodon/components/status_content.js
Expand Up @@ -94,9 +94,15 @@ export default class StatusContent extends React.PureComponent {
} }
} }


_renderMathJax () {
const node = this.node;
MathJax.Hub.Queue(["Typeset", MathJax.Hub, node]);
}

componentDidMount () { componentDidMount () {
this._updateStatusLinks(); this._updateStatusLinks();
this._updateStatusEmojis(); this._updateStatusEmojis();
this._renderMathJax();
} }


componentDidUpdate () { componentDidUpdate () {
Expand Down

0 comments on commit 004c55b

Please sign in to comment.