From e58ae541d165b2ab5f0b9f2086fab49d66ddfcf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Scatena?= Date: Thu, 25 Mar 2021 00:17:41 +0100 Subject: [PATCH] Initial commit --- .gitignore | 4 ++ BbCode/Math.php | 29 +++++++++++ CONTRIBUTING.md | 42 ++++++++++++++++ LICENSE | 21 ++++++++ README.md | 1 + _files/js/inforge/bbmath/mathjax-loader.js | 26 ++++++++++ _output/bb_codes/_metadata.json | 8 +++ _output/bb_codes/imath.json | 20 ++++++++ _output/bb_codes/math.json | 20 ++++++++ _output/phrases/_metadata.json | 50 +++++++++++++++++++ _output/phrases/custom_bb_code_desc.imath.txt | 1 + _output/phrases/custom_bb_code_desc.math.txt | 1 + .../phrases/custom_bb_code_example.imath.txt | 1 + .../phrases/custom_bb_code_example.math.txt | 6 +++ .../phrases/custom_bb_code_output.imath.txt | 0 .../phrases/custom_bb_code_output.math.txt | 0 .../phrases/custom_bb_code_title.imath.txt | 1 + _output/phrases/custom_bb_code_title.math.txt | 1 + addon.json | 22 ++++++++ build.json | 8 +++ 20 files changed, 262 insertions(+) create mode 100644 .gitignore create mode 100644 BbCode/Math.php create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 _files/js/inforge/bbmath/mathjax-loader.js create mode 100644 _output/bb_codes/_metadata.json create mode 100644 _output/bb_codes/imath.json create mode 100644 _output/bb_codes/math.json create mode 100644 _output/phrases/_metadata.json create mode 100644 _output/phrases/custom_bb_code_desc.imath.txt create mode 100644 _output/phrases/custom_bb_code_desc.math.txt create mode 100644 _output/phrases/custom_bb_code_example.imath.txt create mode 100644 _output/phrases/custom_bb_code_example.math.txt create mode 100644 _output/phrases/custom_bb_code_output.imath.txt create mode 100644 _output/phrases/custom_bb_code_output.math.txt create mode 100644 _output/phrases/custom_bb_code_title.imath.txt create mode 100644 _output/phrases/custom_bb_code_title.math.txt create mode 100644 addon.json create mode 100644 build.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20fdb0e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +hashes.json +_build/ +_releases/ +_data/ diff --git a/BbCode/Math.php b/BbCode/Math.php new file mode 100644 index 0000000..d495d0f --- /dev/null +++ b/BbCode/Math.php @@ -0,0 +1,29 @@ +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] . '$$\)'; + } +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9fb9dd3 --- /dev/null +++ b/CONTRIBUTING.md @@ -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//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//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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6421549 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8cf08ff --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# BbMath diff --git a/_files/js/inforge/bbmath/mathjax-loader.js b/_files/js/inforge/bbmath/mathjax-loader.js new file mode 100644 index 0000000..19d8fd2 --- /dev/null +++ b/_files/js/inforge/bbmath/mathjax-loader.js @@ -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); +})(); diff --git a/_output/bb_codes/_metadata.json b/_output/bb_codes/_metadata.json new file mode 100644 index 0000000..3b8b591 --- /dev/null +++ b/_output/bb_codes/_metadata.json @@ -0,0 +1,8 @@ +{ + "imath.json": { + "hash": "2608cc85133fd555483293fb02c28a5a" + }, + "math.json": { + "hash": "0e73d0c917ba4a663b3fb8481e3e5287" + } +} \ No newline at end of file diff --git a/_output/bb_codes/imath.json b/_output/bb_codes/imath.json new file mode 100644 index 0000000..bd5cc9c --- /dev/null +++ b/_output/bb_codes/imath.json @@ -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 +} \ No newline at end of file diff --git a/_output/bb_codes/math.json b/_output/bb_codes/math.json new file mode 100644 index 0000000..d634b4a --- /dev/null +++ b/_output/bb_codes/math.json @@ -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 +} \ No newline at end of file diff --git a/_output/phrases/_metadata.json b/_output/phrases/_metadata.json new file mode 100644 index 0000000..942f5b2 --- /dev/null +++ b/_output/phrases/_metadata.json @@ -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" + } +} \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_desc.imath.txt b/_output/phrases/custom_bb_code_desc.imath.txt new file mode 100644 index 0000000..4a51975 --- /dev/null +++ b/_output/phrases/custom_bb_code_desc.imath.txt @@ -0,0 +1 @@ +Shows an inline LaTeX formula. \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_desc.math.txt b/_output/phrases/custom_bb_code_desc.math.txt new file mode 100644 index 0000000..bb3fac4 --- /dev/null +++ b/_output/phrases/custom_bb_code_desc.math.txt @@ -0,0 +1 @@ +Shows a LaTeX equation. \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_example.imath.txt b/_output/phrases/custom_bb_code_example.imath.txt new file mode 100644 index 0000000..e607a65 --- /dev/null +++ b/_output/phrases/custom_bb_code_example.imath.txt @@ -0,0 +1 @@ +some text [IMATH]\left(\frac{1}{\sqrt{x}}\right)[/IMATH] some text \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_example.math.txt b/_output/phrases/custom_bb_code_example.math.txt new file mode 100644 index 0000000..71af3fe --- /dev/null +++ b/_output/phrases/custom_bb_code_example.math.txt @@ -0,0 +1,6 @@ +[MATH] +\begin{cases} +x'(t) = \sin x(t), & t\in\mathbb{R}\\ +x(0)=x_0 +\end{cases} +[/MATH] \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_output.imath.txt b/_output/phrases/custom_bb_code_output.imath.txt new file mode 100644 index 0000000..e69de29 diff --git a/_output/phrases/custom_bb_code_output.math.txt b/_output/phrases/custom_bb_code_output.math.txt new file mode 100644 index 0000000..e69de29 diff --git a/_output/phrases/custom_bb_code_title.imath.txt b/_output/phrases/custom_bb_code_title.imath.txt new file mode 100644 index 0000000..bce3281 --- /dev/null +++ b/_output/phrases/custom_bb_code_title.imath.txt @@ -0,0 +1 @@ +Inline Math \ No newline at end of file diff --git a/_output/phrases/custom_bb_code_title.math.txt b/_output/phrases/custom_bb_code_title.math.txt new file mode 100644 index 0000000..308461d --- /dev/null +++ b/_output/phrases/custom_bb_code_title.math.txt @@ -0,0 +1 @@ +Equation \ No newline at end of file diff --git a/addon.json b/addon.json new file mode 100644 index 0000000..8b843f9 --- /dev/null +++ b/addon.json @@ -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" +} diff --git a/build.json b/build.json new file mode 100644 index 0000000..5f36ae2 --- /dev/null +++ b/build.json @@ -0,0 +1,8 @@ +{ + "additional_files": [ + "js/inforge/bbmath" + ], + "minify": [ + "js/inforge/bbmath/mathjax-loader.js" + ] +}