The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

6 years ago
  1. /*
  2. Based on the markdown-it-wikilinks, which is distributed under the MIT license.
  3. https://github.com/jsepia/markdown-it-wikilinks @ 79fe609a03917f7df11128231118a66a559076d0
  4. Copyright (c) 2016 Julio Sepia
  5. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  7. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  8. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  9. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  10. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  11. SOFTWARE.
  12. */
  13. const Plugin = require('markdown-it-regexp')
  14. module.exports = new Plugin(/\[\[([\w'\s/]+)(\|([\w'\s/]+))?\]\]/, match => {
  15. let label = ""
  16. let page = ""
  17. if (match[3] != null) {
  18. label = match[3]
  19. page = encodeURIComponent(match[1])
  20. } else {
  21. label = match[1]
  22. page = encodeURIComponent(label)
  23. }
  24. if (label == "" || page == "") {
  25. return match.input
  26. }
  27. return `<a class="wiki-link" href="https://wiki.aiterp.net?title=${page}">${label}</a>`
  28. }
  29. )