Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SpeedJack committed Mar 24, 2021
0 parents commit e58ae54
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hashes.json
_build/
_releases/
_data/
29 changes: 29 additions & 0 deletions BbCode/Math.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Inforge\BbMath\BbCode;

class Math
{
private static function loadMathjax(\XF\BbCode\Renderer\AbstractRenderer $renderer)
{
$renderer->getTemplater()->includeJs([
'src' => 'inforge/bbmath/mathjax-loader.js',
'addon' => 'Inforge/BbMath',
'min' => true,
]);
}

public static function renderMathTag($tagChildren, $tagOption, $tag,
array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
{
self::loadMathjax($renderer);
return '$$\[' . $tagChildren[0] . '$$\]';
}

public static function renderInlineMathTag($tagChildren, $tagOption, $tag,
array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
{
self::loadMathjax($renderer);
return '$$\(' . $tagChildren[0] . '$$\)';
}
}
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Contributing to BbMath

## First setup

1. You need [XenForo 2.x](https://xenforo.com/). You can setup a Scotch Box
environment as described in the [Xenforo 2.x Development
Documentation](https://xenforo.com/xf2-docs/dev/scotchbox/)
2. Fork TwitchPiper
3. Move in the `src/addon/` folder of your development enviroment and `mkdir Inforge && cd Inforge`
4. `git clone https://github.com/<your-username>/BbMath && cd BbMath`
5. `git remote add upstream https://github.com/InforgeNet/BbMath`

## Pull request

Each time you want to submit a pull request, do the following:

1. Download latest upstream modifications: `git fetch upstream`
2. Ceate a new branch: `git checkout -b whatever-you-want-feature upstream/master`
3. Make you changes, add them and commit
4. `git push -u origin whatever-you-want-feature`
5. Visit `https://github.com/<your-username>/BbMath` and create a new pull request

### Commit message

Follow these guidelines to write a proper commit message: [How to Write a Git
Commit Message](https://chris.beams.io/posts/git-commit/).

### Code style

General guidelines:

* Indent code with a **single tab**
* Avoid brackets when they are not necessary
* Try to keep lines under 80 columns, assuming a tab width equal to 8 spaces
(yes!)
* Follow the [XenForo 2.x](https://xenforo.com/xf2-docs/dev/) code style
conventions
* In general, I like the [Linux Kernel Coding
Style](https://www.kernel.org/doc/html/latest/process/coding-style.html) and
try to adapt it to PHP, JS and every other C-like language
* Check out the code already in the repository and try to follow the same style
* Use common sense
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Niccolò Scatena (Inforge)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# BbMath
26 changes: 26 additions & 0 deletions _files/js/inforge/bbmath/mathjax-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
window.MathJax = {
loader: {
load: ['ui/safe']
},
options: {
enableMenu: false
},
tex: {
inlineMath: [['$$\\(', '$$\\)']],
displayMath: [['$$\\[', '$$\\]']],
processEscapes: false,
processRefs: true,
processEnvironments: false,
tags: 'ams'
},
svg: {
fontCache: 'global'
}
};

(function() {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';
script.async = true;
document.head.appendChild(script);
})();
8 changes: 8 additions & 0 deletions _output/bb_codes/_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"imath.json": {
"hash": "2608cc85133fd555483293fb02c28a5a"
},
"math.json": {
"hash": "0e73d0c917ba4a663b3fb8481e3e5287"
}
}
20 changes: 20 additions & 0 deletions _output/bb_codes/imath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bb_code_mode": "callback",
"has_option": "no",
"replace_html": "",
"replace_html_email": "",
"replace_text": "",
"callback_class": "Inforge\\BbMath\\BbCode\\Math",
"callback_method": "renderInlineMathTag",
"option_regex": "",
"trim_lines_after": 1,
"plain_children": true,
"disable_smilies": false,
"disable_nl2br": false,
"disable_autolink": true,
"allow_empty": false,
"allow_signature": false,
"editor_icon_type": "fa",
"editor_icon_value": "fas fa-function",
"active": true
}
20 changes: 20 additions & 0 deletions _output/bb_codes/math.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bb_code_mode": "callback",
"has_option": "no",
"replace_html": "",
"replace_html_email": "",
"replace_text": "",
"callback_class": "Inforge\\BbMath\\BbCode\\Math",
"callback_method": "renderMathTag",
"option_regex": "",
"trim_lines_after": 1,
"plain_children": true,
"disable_smilies": false,
"disable_nl2br": false,
"disable_autolink": true,
"allow_empty": false,
"allow_signature": false,
"editor_icon_type": "fa",
"editor_icon_value": "fas fa-sigma",
"active": true
}
50 changes: 50 additions & 0 deletions _output/phrases/_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"custom_bb_code_desc.imath.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "25e1a125b615656d98e1e9a0d86aed23"
},
"custom_bb_code_desc.math.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "a57476785e78e7548ee37d0dac689b89"
},
"custom_bb_code_example.imath.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "8c7879343f05c33e441c866208774770"
},
"custom_bb_code_example.math.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "29cdf8f73f4470841a427c6c1567d148"
},
"custom_bb_code_output.imath.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "d41d8cd98f00b204e9800998ecf8427e"
},
"custom_bb_code_output.math.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "d41d8cd98f00b204e9800998ecf8427e"
},
"custom_bb_code_title.imath.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "f6b210b4351f3ce4b04695f8b3b122ce"
},
"custom_bb_code_title.math.txt": {
"global_cache": false,
"version_id": 1000070,
"version_string": "1.0.0",
"hash": "aa8a105043d90127c760e67170853c2c"
}
}
1 change: 1 addition & 0 deletions _output/phrases/custom_bb_code_desc.imath.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shows an inline LaTeX formula.
1 change: 1 addition & 0 deletions _output/phrases/custom_bb_code_desc.math.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shows a LaTeX equation.
1 change: 1 addition & 0 deletions _output/phrases/custom_bb_code_example.imath.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some text [IMATH]\left(\frac{1}{\sqrt{x}}\right)[/IMATH] some text
6 changes: 6 additions & 0 deletions _output/phrases/custom_bb_code_example.math.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MATH]
\begin{cases}
x'(t) = \sin x(t), & t\in\mathbb{R}\\
x(0)=x_0
\end{cases}
[/MATH]
Empty file.
Empty file.
1 change: 1 addition & 0 deletions _output/phrases/custom_bb_code_title.imath.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inline Math
1 change: 1 addition & 0 deletions _output/phrases/custom_bb_code_title.math.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Equation
22 changes: 22 additions & 0 deletions addon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"legacy_addon_id": "",
"title": "[Inforge] BbMath",
"description": "Add BBCode to support equations and inline math.",
"version_id": 1000070,
"version_string": "1.0.0",
"dev": "Inforge",
"dev_url": "https://www.inforge.net",
"faq_url": "https://github.com/InforgeNet/BbMath/wiki/Frequently-Asked-Questions",
"support_url": "https://github.com/InforgeNet/BbMath/issues",
"extra_urls": {
"Forum": "https://www.inforge.net/forum",
"GitHub": "https://github.com/InforgeNet/BbMath"
},
"require": {
"XF": [
2020010,
"XenForo 2.2.0+"
]
},
"icon": "far fa-function"
}
8 changes: 8 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"additional_files": [
"js/inforge/bbmath"
],
"minify": [
"js/inforge/bbmath/mathjax-loader.js"
]
}

0 comments on commit e58ae54

Please sign in to comment.