Site Notice

hello, world

MediaWiki:Gadget-Highlight.js

From Project-EPB Commons
Revision as of 19:38, 29 October 2020 by 机智的小鱼君 (talk | contribs) ([InPageEdit] 没有编辑摘要)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Invoke this: https://common.wjghj.cn/

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/** highlight.js **/
!(function () {
  var pageName = mw.config.get('wgPageName')
  if (pageName.substr(pageName.length - 3, 3) === '.js') {
    $('#mw-content-text pre').addClass('lang-js hightlight linenums')
  } else if (pageName.substr(pageName.length - 4, 4) === '.css') {
    $('#mw-content-text pre').addClass('lang-css hightlight linenums')
  } else if (mw.config.get('wgNamespaceNumber') === 828) {
    $('#mw-content-text pre').addClass('lang-lua hightlight linenums')
  }
  $.ajax({
    url: 'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js',
    dataType: 'script',
    cache: true
  }).then(function () {
    $('#mw-content-text .hightlight').each(function (_, item) {
      hljs.highlightBlock(item)
      if ($(item).hasClass('linenums')) {
        $(item).html(function () {
          var html = $(this).html()
          html = html.split('\n')
          var $content = $('<div>', { class: 'line-all' })
          $.each(html, function (line, lineContent) {
            $content.append(
              $('<div>', { class: 'line-container' }).append(
                $('<div>', { class: 'line-num', text: line + 1 }),
                $('<div>', { class: 'line-content', html: lineContent })
              )
            )
          })
          return $content
        })
      }
    })
  })
  mw.loader.load('https://cdn.jsdelivr.net/npm/[email protected]/styles/solarized-light.css', 'text/css')
})()