| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- // custom mode
- 'use strict'
- import CodeMirror from 'codemirror'
- export default function () {
- CodeMirror.defineMode('hosts', function () {
- function tokenBase (stream) {
- if (stream.eatSpace()) return null
- let sol = stream.sol()
- let ch = stream.next()
- let s = stream.string
- if (ch === '#') {
- stream.skipToEnd()
- return 'comment'
- }
- if (!s.match(/^\s*([\d.]+|[\da-f:.%lo]+)\s+\w/i)) {
- return 'error'
- }
- if (sol && ch.match(/[\w.:%]/)) {
- stream.eatWhile(/[\w.:%]/)
- return 'ip'
- }
- return null
- }
- function tokenize (stream, state) {
- return (state.tokens[0] || tokenBase)(stream, state)
- }
- return {
- startState: function () {
- return {tokens: []}
- },
- token: function (stream, state) {
- return tokenize(stream, state)
- },
- lineComment: '#'
- }
- })
- //CodeMirror.defineMIME('text/x-hosts', 'hosts');
- }
|