new: [localtools] Integration of codemirror of tools parameters
parent
256b39691c
commit
bc7e2baf83
|
@ -23,12 +23,16 @@ class LocalToolsController extends AppController
|
||||||
$this->set('metaGroup', 'Administration');
|
$this->set('metaGroup', 'Administration');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connectorIndex()
|
public function connectorIndex($connectorName)
|
||||||
{
|
{
|
||||||
$this->set('metaGroup', 'Admin');
|
$this->set('metaGroup', 'Admin');
|
||||||
$this->CRUD->index([
|
$this->CRUD->index([
|
||||||
'filters' => ['name', 'connector'],
|
'filters' => ['name', 'connector'],
|
||||||
'quickFilters' => ['name', 'connector'],
|
'quickFilters' => ['name', 'connector'],
|
||||||
|
'filterFunction' => function($query) use ($connectorName) {
|
||||||
|
$query->where(['connector' => $connectorName]);
|
||||||
|
return $query;
|
||||||
|
},
|
||||||
'afterFind' => function($data) {
|
'afterFind' => function($data) {
|
||||||
foreach ($data as $connector) {
|
foreach ($data as $connector) {
|
||||||
$connector['health'] = [$this->LocalTools->healthCheckIndividual($connector)];
|
$connector['health'] = [$this->LocalTools->healthCheckIndividual($connector)];
|
||||||
|
@ -41,6 +45,7 @@ class LocalToolsController extends AppController
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Administration');
|
$this->set('metaGroup', 'Administration');
|
||||||
|
$this->set('connector', $connectorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action($connectionId, $actionName)
|
public function action($connectionId, $actionName)
|
||||||
|
@ -100,18 +105,25 @@ class LocalToolsController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($connector = false)
|
public function add($connectorName = false)
|
||||||
{
|
{
|
||||||
$this->CRUD->add();
|
$this->CRUD->add();
|
||||||
$responsePayload = $this->CRUD->getResponsePayload();
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
if (!empty($responsePayload)) {
|
if (!empty($responsePayload)) {
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$connectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
$localConnectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
||||||
$dropdownData = ['connectors' => []];
|
$dropdownData = ['connectors' => []];
|
||||||
foreach ($connectors as $connector) {
|
$connector = false;
|
||||||
$dropdownData['connectors'][$connector['connector']] = $connector['name'];
|
$connectors = [];
|
||||||
|
foreach ($localConnectors as $c) {
|
||||||
|
if (empty($connectorName) || $c['connector'] == $connectorName) {
|
||||||
|
$dropdownData['connectors'][$c['connector']] = $c['name'];
|
||||||
|
$connectors[] = $c;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$this->set('connectorName', $connectorName);
|
||||||
|
$this->set('connectors', $connectors);
|
||||||
$this->set(compact('dropdownData'));
|
$this->set(compact('dropdownData'));
|
||||||
$this->set('metaGroup', 'Administration');
|
$this->set('metaGroup', 'Administration');
|
||||||
}
|
}
|
||||||
|
@ -121,7 +133,7 @@ class LocalToolsController extends AppController
|
||||||
$connectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
$connectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
||||||
$connector = false;
|
$connector = false;
|
||||||
foreach ($connectors as $c) {
|
foreach ($connectors as $c) {
|
||||||
if ($connector === false || version_compare($c['version'], $connectors['version']) > 0) {
|
if ($connector_name == $c['connector'] && ($connector === false || version_compare($c['version'], $connectors['version']) > 0)) {
|
||||||
$connector = $c;
|
$connector = $c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,6 +146,7 @@ class LocalToolsController extends AppController
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
|
$localTool = $this->LocalTools->get($id);
|
||||||
$this->CRUD->edit($id);
|
$this->CRUD->edit($id);
|
||||||
$responsePayload = $this->CRUD->getResponsePayload();
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
if (!empty($responsePayload)) {
|
if (!empty($responsePayload)) {
|
||||||
|
@ -142,12 +155,19 @@ class LocalToolsController extends AppController
|
||||||
if ($this->ParamHandler->isAjax() && !empty($this->ajaxResponsePayload)) {
|
if ($this->ParamHandler->isAjax() && !empty($this->ajaxResponsePayload)) {
|
||||||
return $this->ajaxResponsePayload;
|
return $this->ajaxResponsePayload;
|
||||||
}
|
}
|
||||||
$connectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
$localConnectors = $this->LocalTools->extractMeta($this->LocalTools->getConnectors());
|
||||||
$dropdownData = ['connectors' => []];
|
$dropdownData = ['connectors' => []];
|
||||||
foreach ($connectors as $connector) {
|
$connector = false;
|
||||||
$dropdownData['connectors'][$connector['connector']] = $connector['name'];
|
$connectors = [];
|
||||||
|
foreach ($localConnectors as $c) {
|
||||||
|
if (empty($localTool->connector) || $c['connector'] == $localTool->connector) {
|
||||||
|
$dropdownData['connectors'][$c['connector']] = $c['name'];
|
||||||
|
$connectors[] = $c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->set(compact('dropdownData'));
|
$this->set(compact('dropdownData'));
|
||||||
|
$this->set('connectorName', $localTool->connector);
|
||||||
|
$this->set('connectors', $connectors);
|
||||||
$this->set('metaGroup', 'Administration');
|
$this->set('metaGroup', 'Administration');
|
||||||
$this->render('add');
|
$this->render('add');
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,25 @@ class MispConnector extends CommonConnectorTools
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
public $version = '0.1';
|
public $version = '0.1';
|
||||||
|
public $parameters = [
|
||||||
|
'url' => [
|
||||||
|
'required' => true,
|
||||||
|
// 'validation' => 'url',
|
||||||
|
],
|
||||||
|
'authkey' => [
|
||||||
|
'required' => true,
|
||||||
|
// 'validation' => 'authkeyLength',
|
||||||
|
],
|
||||||
|
'skip_ssl' => [
|
||||||
|
// 'validation' => 'boolean',
|
||||||
|
],
|
||||||
|
'test_param' => [
|
||||||
|
'options' => [
|
||||||
|
'John',
|
||||||
|
'Doe'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
public function addExposedFunction(string $functionName): void
|
public function addExposedFunction(string $functionName): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,7 +132,8 @@ class LocalToolsTable extends AppTable
|
||||||
'name' => $connector_class->name,
|
'name' => $connector_class->name,
|
||||||
'connector' => $connector_type,
|
'connector' => $connector_type,
|
||||||
'connector_version' => $connector_class->version,
|
'connector_version' => $connector_class->version,
|
||||||
'connector_description' => $connector_class->description
|
'connector_description' => $connector_class->description,
|
||||||
|
'connector_parameters' => $connector_class->parameters ?? []
|
||||||
];
|
];
|
||||||
if ($includeConnections) {
|
if ($includeConnections) {
|
||||||
$connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
$connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
||||||
|
|
|
@ -4,21 +4,25 @@
|
||||||
'description' => __('Add connections to local tools via any of the available connectors below.'),
|
'description' => __('Add connections to local tools via any of the available connectors below.'),
|
||||||
'model' => 'LocalTools',
|
'model' => 'LocalTools',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
[
|
|
||||||
'field' => 'name'
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'field' => 'connector',
|
'field' => 'connector',
|
||||||
'options' => $dropdownData['connectors'],
|
'options' => $dropdownData['connectors'],
|
||||||
'type' => 'dropdown'
|
'type' => 'dropdown'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'field' => 'name'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'field' => 'exposed',
|
'field' => 'exposed',
|
||||||
'type' => 'checkbox'
|
'type' => 'checkbox'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'settings',
|
'field' => 'settings',
|
||||||
'type' => 'textarea'
|
'type' => 'codemirror',
|
||||||
|
'codemirror' => [
|
||||||
|
'height' => '10rem',
|
||||||
|
'hints' => $connectors[0]['connector_parameters']
|
||||||
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'description',
|
'field' => 'description',
|
||||||
|
|
|
@ -4,6 +4,16 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'top_bar' => [
|
'top_bar' => [
|
||||||
'children' => [
|
'children' => [
|
||||||
|
[
|
||||||
|
'type' => 'simple',
|
||||||
|
'children' => [
|
||||||
|
'data' => [
|
||||||
|
'type' => 'simple',
|
||||||
|
'text' => __('Add connection'),
|
||||||
|
'popover_url' => sprintf('/localTools/add/%s', h($connector))
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'type' => 'search',
|
'type' => 'search',
|
||||||
'button' => __('Filter'),
|
'button' => __('Filter'),
|
||||||
|
@ -53,7 +63,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
],
|
],
|
||||||
'title' => false,
|
'title' => false,
|
||||||
'description' => false,
|
'description' => false,
|
||||||
'pull' => 'right',
|
|
||||||
'actions' => [
|
'actions' => [
|
||||||
[
|
[
|
||||||
'url' => '/localTools/view',
|
'url' => '/localTools/view',
|
||||||
|
@ -63,16 +72,19 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
[
|
[
|
||||||
'open_modal' => '/localTools/connectLocal/[onclick_params_data_path]',
|
'open_modal' => '/localTools/connectLocal/[onclick_params_data_path]',
|
||||||
'modal_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
|
'reload_url' => sprintf('/localTools/connectorIndex/%s', h($connector)),
|
||||||
'icon' => 'plug'
|
'icon' => 'plug'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/localTools/edit/[onclick_params_data_path]',
|
'open_modal' => '/localTools/edit/[onclick_params_data_path]',
|
||||||
'modal_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
|
'reload_url' => sprintf('/localTools/connectorIndex/%s', h($connector)),
|
||||||
'icon' => 'edit'
|
'icon' => 'edit'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/localTools/delete/[onclick_params_data_path]',
|
'open_modal' => '/localTools/delete/[onclick_params_data_path]',
|
||||||
'modal_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
|
'reload_url' => sprintf('/localTools/connectorIndex/%s', h($connector)),
|
||||||
'icon' => 'trash'
|
'icon' => 'trash'
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
|
@ -24,7 +24,7 @@ echo $this->element(
|
||||||
],
|
],
|
||||||
'children' => [
|
'children' => [
|
||||||
[
|
[
|
||||||
'url' => '/localTools/connectorIndex/',
|
'url' => '/localTools/connectorIndex/{{0}}',
|
||||||
'url_params' => ['connector'],
|
'url_params' => ['connector'],
|
||||||
'title' => __('Connections')
|
'title' => __('Connections')
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
// $randomVal = Cake\Utility\Security::randomString(8);
|
||||||
|
// $params['type'] = 'textarea';
|
||||||
|
// $textareaClass = "area-for-codemirror-{$randomVal}";
|
||||||
|
// $params['class'] = [$textareaClass];
|
||||||
|
// echo $this->FormFieldMassage->prepareFormElement($this->Form, $params, $fieldData);
|
||||||
|
echo $this->element('genericElements/codemirror', [
|
||||||
|
'data' => $fieldData,
|
||||||
|
'params' => $params,
|
||||||
|
]);
|
|
@ -0,0 +1,159 @@
|
||||||
|
<?php
|
||||||
|
if (empty($textareaClass)) {
|
||||||
|
$params['type'] = 'textarea';
|
||||||
|
$randomVal = Cake\Utility\Security::randomString(8);
|
||||||
|
$textareaClass = "area-for-codemirror-{$randomVal}";
|
||||||
|
$params['class'] = [
|
||||||
|
$textareaClass
|
||||||
|
];
|
||||||
|
echo $this->FormFieldMassage->prepareFormElement($this->Form, $params, $data);
|
||||||
|
} else {
|
||||||
|
echo sprintf('<textarea class="%s"></textarea>', $textareaClass);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
const $textArea = $('.<?= $textareaClass ?>')
|
||||||
|
const cmDefaultOptions = {
|
||||||
|
mode: {
|
||||||
|
name: 'javascript',
|
||||||
|
json: true
|
||||||
|
},
|
||||||
|
gutters: ["CodeMirror-lint-markers"],
|
||||||
|
lint: true,
|
||||||
|
showCursorWhenSelecting: true,
|
||||||
|
indentUnit: 4,
|
||||||
|
autoCloseBrackets: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
smartIndent: true,
|
||||||
|
lineNumbers: true,
|
||||||
|
lineWrapping: true,
|
||||||
|
extraKeys: {
|
||||||
|
"Ctrl-Space": "autocomplete",
|
||||||
|
},
|
||||||
|
hintOptions: {
|
||||||
|
completeSingle: false,
|
||||||
|
hint: jsonHints,
|
||||||
|
maxHints: 100
|
||||||
|
},
|
||||||
|
hintData: {}
|
||||||
|
}
|
||||||
|
const passedOptions = <?= json_encode($data['codemirror'] ?? $data['codemirror']) ?>;
|
||||||
|
const cmOptions = Object.assign({}, cmDefaultOptions, passedOptions)
|
||||||
|
let cm
|
||||||
|
init()
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
cm = CodeMirror.fromTextArea($textArea[0], cmOptions);
|
||||||
|
if (cmOptions['height'] || cmOptions['width']) {
|
||||||
|
cm.setSize(
|
||||||
|
cmOptions['width'] ? cmOptions['width'] : null,
|
||||||
|
cmOptions['height'] ? cmOptions['height'] : null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (cmOptions.hints) {
|
||||||
|
for (const key in cmOptions.hints) {
|
||||||
|
if (Object.hasOwnProperty.call(cmOptions.hints, key)) {
|
||||||
|
const element = cmOptions.hints[key];
|
||||||
|
cmOptions.hintData[key] = element.options ? element.options: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cm.on("keyup", function (cm, event) {
|
||||||
|
if (!cm.state.completionActive && /*Enables keyboard navigation in autocomplete list*/
|
||||||
|
event.keyCode != 13) { /*Enter - do not open autocomplete list just after item has been selected in it*/
|
||||||
|
cm.showHint()
|
||||||
|
}
|
||||||
|
cm.save()
|
||||||
|
})
|
||||||
|
postInit()
|
||||||
|
}
|
||||||
|
|
||||||
|
function postInit() {
|
||||||
|
if ($(cm.getInputField()).closest('.modal').length) { // editor is in modal
|
||||||
|
setTimeout(() => {
|
||||||
|
cm.refresh()
|
||||||
|
}, 200); // modal takes 150ms to be displayed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function jsonHints() {
|
||||||
|
const cur = cm.getCursor()
|
||||||
|
const token = cm.getTokenAt(cur)
|
||||||
|
if (token.type != 'string property' && token.type != 'string') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (cm.getMode().helperType !== "json") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
token.state = cm.state;
|
||||||
|
token.line = cur.line
|
||||||
|
|
||||||
|
if (/\"([^\"]*)\"/.test(token.string)) {
|
||||||
|
token.end = cur.ch;
|
||||||
|
token.string = token.string.slice(1, cur.ch - token.start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
list: getCompletions(token, token.type == 'string property'),
|
||||||
|
from: CodeMirror.Pos(cur.line, token.start+1),
|
||||||
|
to: CodeMirror.Pos(cur.line, token.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCompletions(token, isJSONKey) {
|
||||||
|
let hints = []
|
||||||
|
if (isJSONKey) {
|
||||||
|
hints = findMatchingHints(token.string, Object.keys(cmOptions.hintData))
|
||||||
|
} else {
|
||||||
|
const jsonKey = findPropertyForValue(token)
|
||||||
|
if (cmOptions.hintData[jsonKey]) {
|
||||||
|
hints = findMatchingHints(token.string, cmOptions.hintData[jsonKey])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hints
|
||||||
|
}
|
||||||
|
|
||||||
|
function findMatchingHints(str, hints) {
|
||||||
|
hints = hints.map(function(str) {
|
||||||
|
var strArray = typeof str === "object" ? String(str.value).split('"') : str.split('"')
|
||||||
|
return {
|
||||||
|
text: strArray.join('\\\"'), // transforms quoted elements into escaped quote
|
||||||
|
displayText: typeof str === "object" ? str.label : strArray.join('\"'),
|
||||||
|
render: function(elem, self, data) {
|
||||||
|
$(elem).append(data.displayText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (str.length > 0) {
|
||||||
|
let validHints = []
|
||||||
|
let hint
|
||||||
|
for (let i = 0; hints.length < cmOptions.hintOptions.maxHints && i < validHints.length; i++) {
|
||||||
|
if (hints[i].text.startsWith(str)) {
|
||||||
|
validHints.push(hints[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validHints
|
||||||
|
} else {
|
||||||
|
return hints.slice(0, cmOptions.hintOptions.maxHints)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findPropertyForValue(token) {
|
||||||
|
const absoluteIndex = cm.indexFromPos(CodeMirror.Pos(token.line, token.start))
|
||||||
|
const rawText = cm.getValue()
|
||||||
|
for (let index = absoluteIndex; index > 0; index--) {
|
||||||
|
const ch = rawText[index];
|
||||||
|
if (ch == ':') {
|
||||||
|
const token = cm.getTokenAt(cm.posFromIndex(index-2))
|
||||||
|
if (token.type == 'string property') {
|
||||||
|
return token.string.slice(1, token.string.length-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}())
|
||||||
|
</script>
|
|
@ -41,6 +41,18 @@ $cakeDescription = 'Cerebrate';
|
||||||
<?= $this->Html->script('main.js') ?>
|
<?= $this->Html->script('main.js') ?>
|
||||||
<?= $this->Html->script('bootstrap-helper.js') ?>
|
<?= $this->Html->script('bootstrap-helper.js') ?>
|
||||||
<?= $this->Html->script('api-helper.js') ?>
|
<?= $this->Html->script('api-helper.js') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/codemirror.js') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/mode/javascript/javascript') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/hint/show-hint') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/lint/lint') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/lint/jsonlint') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/lint/json-lint') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/edit/matchbrackets') ?>
|
||||||
|
<?= $this->Html->script('CodeMirror/addon/edit/closebrackets') ?>
|
||||||
|
<?= $this->Html->css('CodeMirror/codemirror') ?>
|
||||||
|
<?= $this->Html->css('CodeMirror/codemirror-additional') ?>
|
||||||
|
<?= $this->Html->css('CodeMirror/addon/hint/show-hint') ?>
|
||||||
|
<?= $this->Html->css('CodeMirror/addon/lint/lint') ?>
|
||||||
<?= $this->fetch('meta') ?>
|
<?= $this->fetch('meta') ?>
|
||||||
<?= $this->fetch('css') ?>
|
<?= $this->fetch('css') ?>
|
||||||
<?= $this->fetch('script') ?>
|
<?= $this->fetch('script') ?>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
.CodeMirror-hints {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10;
|
||||||
|
overflow: hidden;
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
margin: 0;
|
||||||
|
padding: 2px;
|
||||||
|
|
||||||
|
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||||
|
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||||
|
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid silver;
|
||||||
|
|
||||||
|
background: white;
|
||||||
|
font-size: 90%;
|
||||||
|
font-family: monospace;
|
||||||
|
|
||||||
|
max-height: 20em;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-hint {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 4px;
|
||||||
|
border-radius: 2px;
|
||||||
|
white-space: pre;
|
||||||
|
color: black;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.CodeMirror-hint-active {
|
||||||
|
background: #08f;
|
||||||
|
color: white;
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* The lint marker gutter */
|
||||||
|
.CodeMirror-lint-markers {
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-tooltip {
|
||||||
|
background-color: #ffd;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 4px 4px 4px 4px;
|
||||||
|
color: black;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 10pt;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 2px 5px;
|
||||||
|
position: fixed;
|
||||||
|
white-space: pre;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
z-index: 100;
|
||||||
|
max-width: 600px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity .4s;
|
||||||
|
-moz-transition: opacity .4s;
|
||||||
|
-webkit-transition: opacity .4s;
|
||||||
|
-o-transition: opacity .4s;
|
||||||
|
-ms-transition: opacity .4s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-mark {
|
||||||
|
background-position: left bottom;
|
||||||
|
background-repeat: repeat-x;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-mark-warning {
|
||||||
|
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-mark-error {
|
||||||
|
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==");
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-marker {
|
||||||
|
background-position: center center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
vertical-align: middle;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-message {
|
||||||
|
padding-left: 18px;
|
||||||
|
background-position: top left;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
|
||||||
|
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
|
||||||
|
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-marker-multiple {
|
||||||
|
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: right bottom;
|
||||||
|
width: 100%; height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-line-error {
|
||||||
|
background-color: rgba(183, 76, 81, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lint-line-warning {
|
||||||
|
background-color: rgba(255, 211, 0, 0.1);
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
.cm-s-default {
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-gutters {
|
||||||
|
border-radius: 0.25rem 0 0 0.25rem;
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
/* BASICS */
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
/* Set height, width, borders, and global font properties here */
|
||||||
|
font-family: monospace;
|
||||||
|
height: 300px;
|
||||||
|
color: black;
|
||||||
|
direction: ltr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PADDING */
|
||||||
|
|
||||||
|
.CodeMirror-lines {
|
||||||
|
padding: 4px 0; /* Vertical padding around content */
|
||||||
|
}
|
||||||
|
.CodeMirror pre.CodeMirror-line,
|
||||||
|
.CodeMirror pre.CodeMirror-line-like {
|
||||||
|
padding: 0 4px; /* Horizontal padding of content */
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||||
|
background-color: white; /* The little square between H and V scrollbars */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GUTTER */
|
||||||
|
|
||||||
|
.CodeMirror-gutters {
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
background-color: #f7f7f7;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.CodeMirror-linenumbers {}
|
||||||
|
.CodeMirror-linenumber {
|
||||||
|
padding: 0 3px 0 5px;
|
||||||
|
min-width: 20px;
|
||||||
|
text-align: right;
|
||||||
|
color: #999;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-guttermarker { color: black; }
|
||||||
|
.CodeMirror-guttermarker-subtle { color: #999; }
|
||||||
|
|
||||||
|
/* CURSOR */
|
||||||
|
|
||||||
|
.CodeMirror-cursor {
|
||||||
|
border-left: 1px solid black;
|
||||||
|
border-right: none;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
/* Shown when moving in bi-directional text */
|
||||||
|
.CodeMirror div.CodeMirror-secondarycursor {
|
||||||
|
border-left: 1px solid silver;
|
||||||
|
}
|
||||||
|
.cm-fat-cursor .CodeMirror-cursor {
|
||||||
|
width: auto;
|
||||||
|
border: 0 !important;
|
||||||
|
background: #7e7;
|
||||||
|
}
|
||||||
|
.cm-fat-cursor div.CodeMirror-cursors {
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.cm-fat-cursor-mark {
|
||||||
|
background-color: rgba(20, 255, 20, 0.5);
|
||||||
|
-webkit-animation: blink 1.06s steps(1) infinite;
|
||||||
|
-moz-animation: blink 1.06s steps(1) infinite;
|
||||||
|
animation: blink 1.06s steps(1) infinite;
|
||||||
|
}
|
||||||
|
.cm-animate-fat-cursor {
|
||||||
|
width: auto;
|
||||||
|
border: 0;
|
||||||
|
-webkit-animation: blink 1.06s steps(1) infinite;
|
||||||
|
-moz-animation: blink 1.06s steps(1) infinite;
|
||||||
|
animation: blink 1.06s steps(1) infinite;
|
||||||
|
background-color: #7e7;
|
||||||
|
}
|
||||||
|
@-moz-keyframes blink {
|
||||||
|
0% {}
|
||||||
|
50% { background-color: transparent; }
|
||||||
|
100% {}
|
||||||
|
}
|
||||||
|
@-webkit-keyframes blink {
|
||||||
|
0% {}
|
||||||
|
50% { background-color: transparent; }
|
||||||
|
100% {}
|
||||||
|
}
|
||||||
|
@keyframes blink {
|
||||||
|
0% {}
|
||||||
|
50% { background-color: transparent; }
|
||||||
|
100% {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Can style cursor different in overwrite (non-insert) mode */
|
||||||
|
.CodeMirror-overwrite .CodeMirror-cursor {}
|
||||||
|
|
||||||
|
.cm-tab { display: inline-block; text-decoration: inherit; }
|
||||||
|
|
||||||
|
.CodeMirror-rulers {
|
||||||
|
position: absolute;
|
||||||
|
left: 0; right: 0; top: -50px; bottom: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.CodeMirror-ruler {
|
||||||
|
border-left: 1px solid #ccc;
|
||||||
|
top: 0; bottom: 0;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DEFAULT THEME */
|
||||||
|
|
||||||
|
.cm-s-default .cm-header {color: blue;}
|
||||||
|
.cm-s-default .cm-quote {color: #090;}
|
||||||
|
.cm-negative {color: #d44;}
|
||||||
|
.cm-positive {color: #292;}
|
||||||
|
.cm-header, .cm-strong {font-weight: bold;}
|
||||||
|
.cm-em {font-style: italic;}
|
||||||
|
.cm-link {text-decoration: underline;}
|
||||||
|
.cm-strikethrough {text-decoration: line-through;}
|
||||||
|
|
||||||
|
.cm-s-default .cm-keyword {color: #708;}
|
||||||
|
.cm-s-default .cm-atom {color: #219;}
|
||||||
|
.cm-s-default .cm-number {color: #164;}
|
||||||
|
.cm-s-default .cm-def {color: #00f;}
|
||||||
|
.cm-s-default .cm-variable,
|
||||||
|
.cm-s-default .cm-punctuation,
|
||||||
|
.cm-s-default .cm-property,
|
||||||
|
.cm-s-default .cm-operator {}
|
||||||
|
.cm-s-default .cm-variable-2 {color: #05a;}
|
||||||
|
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
|
||||||
|
.cm-s-default .cm-comment {color: #a50;}
|
||||||
|
.cm-s-default .cm-string {color: #a11;}
|
||||||
|
.cm-s-default .cm-string-2 {color: #f50;}
|
||||||
|
.cm-s-default .cm-meta {color: #555;}
|
||||||
|
.cm-s-default .cm-qualifier {color: #555;}
|
||||||
|
.cm-s-default .cm-builtin {color: #30a;}
|
||||||
|
.cm-s-default .cm-bracket {color: #997;}
|
||||||
|
.cm-s-default .cm-tag {color: #170;}
|
||||||
|
.cm-s-default .cm-attribute {color: #00c;}
|
||||||
|
.cm-s-default .cm-hr {color: #999;}
|
||||||
|
.cm-s-default .cm-link {color: #00c;}
|
||||||
|
|
||||||
|
.cm-s-default .cm-error {color: #f00;}
|
||||||
|
.cm-invalidchar {color: #f00;}
|
||||||
|
|
||||||
|
.CodeMirror-composing { border-bottom: 2px solid; }
|
||||||
|
|
||||||
|
/* Default styles for common addons */
|
||||||
|
|
||||||
|
div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
|
||||||
|
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
|
||||||
|
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
||||||
|
.CodeMirror-activeline-background {background: #e8f2ff;}
|
||||||
|
|
||||||
|
/* STOP */
|
||||||
|
|
||||||
|
/* The rest of this file contains styles related to the mechanics of
|
||||||
|
the editor. You probably shouldn't touch them. */
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
overflow: scroll !important; /* Things will break if this is overridden */
|
||||||
|
/* 50px is the magic margin used to hide the element's real scrollbars */
|
||||||
|
/* See overflow: hidden in .CodeMirror */
|
||||||
|
margin-bottom: -50px; margin-right: -50px;
|
||||||
|
padding-bottom: 50px;
|
||||||
|
height: 100%;
|
||||||
|
outline: none; /* Prevent dragging from highlighting the element */
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.CodeMirror-sizer {
|
||||||
|
position: relative;
|
||||||
|
border-right: 50px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
||||||
|
before actual scrolling happens, thus preventing shaking and
|
||||||
|
flickering artifacts. */
|
||||||
|
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 6;
|
||||||
|
display: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.CodeMirror-vscrollbar {
|
||||||
|
right: 0; top: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
.CodeMirror-hscrollbar {
|
||||||
|
bottom: 0; left: 0;
|
||||||
|
overflow-y: hidden;
|
||||||
|
overflow-x: scroll;
|
||||||
|
}
|
||||||
|
.CodeMirror-scrollbar-filler {
|
||||||
|
right: 0; bottom: 0;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-filler {
|
||||||
|
left: 0; bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-gutters {
|
||||||
|
position: absolute; left: 0; top: 0;
|
||||||
|
min-height: 100%;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter {
|
||||||
|
white-space: normal;
|
||||||
|
height: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: top;
|
||||||
|
margin-bottom: -50px;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 4;
|
||||||
|
background: none !important;
|
||||||
|
border: none !important;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-background {
|
||||||
|
position: absolute;
|
||||||
|
top: 0; bottom: 0;
|
||||||
|
z-index: 4;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-elt {
|
||||||
|
position: absolute;
|
||||||
|
cursor: default;
|
||||||
|
z-index: 4;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
|
||||||
|
.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
|
||||||
|
|
||||||
|
.CodeMirror-lines {
|
||||||
|
cursor: text;
|
||||||
|
min-height: 1px; /* prevents collapsing before first draw */
|
||||||
|
}
|
||||||
|
.CodeMirror pre.CodeMirror-line,
|
||||||
|
.CodeMirror pre.CodeMirror-line-like {
|
||||||
|
/* Reset some styles that the rest of the page might have set */
|
||||||
|
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
||||||
|
border-width: 0;
|
||||||
|
background: transparent;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
margin: 0;
|
||||||
|
white-space: pre;
|
||||||
|
word-wrap: normal;
|
||||||
|
line-height: inherit;
|
||||||
|
color: inherit;
|
||||||
|
z-index: 2;
|
||||||
|
position: relative;
|
||||||
|
overflow: visible;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
-webkit-font-variant-ligatures: contextual;
|
||||||
|
font-variant-ligatures: contextual;
|
||||||
|
}
|
||||||
|
.CodeMirror-wrap pre.CodeMirror-line,
|
||||||
|
.CodeMirror-wrap pre.CodeMirror-line-like {
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-linebackground {
|
||||||
|
position: absolute;
|
||||||
|
left: 0; right: 0; top: 0; bottom: 0;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-linewidget {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
padding: 0.1px; /* Force widget margins to stay inside of the container */
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-widget {}
|
||||||
|
|
||||||
|
.CodeMirror-rtl pre { direction: rtl; }
|
||||||
|
|
||||||
|
.CodeMirror-code {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Force content-box sizing for the elements where we expect it */
|
||||||
|
.CodeMirror-scroll,
|
||||||
|
.CodeMirror-sizer,
|
||||||
|
.CodeMirror-gutter,
|
||||||
|
.CodeMirror-gutters,
|
||||||
|
.CodeMirror-linenumber {
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
box-sizing: content-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-measure {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-cursor {
|
||||||
|
position: absolute;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.CodeMirror-measure pre { position: static; }
|
||||||
|
|
||||||
|
div.CodeMirror-cursors {
|
||||||
|
visibility: hidden;
|
||||||
|
position: relative;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
div.CodeMirror-dragcursors {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-focused div.CodeMirror-cursors {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-selected { background: #d9d9d9; }
|
||||||
|
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
||||||
|
.CodeMirror-crosshair { cursor: crosshair; }
|
||||||
|
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
|
||||||
|
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
|
||||||
|
|
||||||
|
.cm-searching {
|
||||||
|
background-color: #ffa;
|
||||||
|
background-color: rgba(255, 255, 0, .4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Used to force a border model for a node */
|
||||||
|
.cm-force-border { padding-right: .1px; }
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
/* Hide the cursor when printing */
|
||||||
|
.CodeMirror div.CodeMirror-cursors {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See issue #2901 */
|
||||||
|
.cm-tab-wrap-hack:after { content: ''; }
|
||||||
|
|
||||||
|
/* Help users use markselection to safely style text background */
|
||||||
|
span.CodeMirror-selectedtext { background: none; }
|
|
@ -0,0 +1,201 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
var defaults = {
|
||||||
|
pairs: "()[]{}''\"\"",
|
||||||
|
closeBefore: ")]}'\":;>",
|
||||||
|
triples: "",
|
||||||
|
explode: "[]{}"
|
||||||
|
};
|
||||||
|
|
||||||
|
var Pos = CodeMirror.Pos;
|
||||||
|
|
||||||
|
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
||||||
|
if (old && old != CodeMirror.Init) {
|
||||||
|
cm.removeKeyMap(keyMap);
|
||||||
|
cm.state.closeBrackets = null;
|
||||||
|
}
|
||||||
|
if (val) {
|
||||||
|
ensureBound(getOption(val, "pairs"))
|
||||||
|
cm.state.closeBrackets = val;
|
||||||
|
cm.addKeyMap(keyMap);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getOption(conf, name) {
|
||||||
|
if (name == "pairs" && typeof conf == "string") return conf;
|
||||||
|
if (typeof conf == "object" && conf[name] != null) return conf[name];
|
||||||
|
return defaults[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
|
||||||
|
function ensureBound(chars) {
|
||||||
|
for (var i = 0; i < chars.length; i++) {
|
||||||
|
var ch = chars.charAt(i), key = "'" + ch + "'"
|
||||||
|
if (!keyMap[key]) keyMap[key] = handler(ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensureBound(defaults.pairs + "`")
|
||||||
|
|
||||||
|
function handler(ch) {
|
||||||
|
return function(cm) { return handleChar(cm, ch); };
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConfig(cm) {
|
||||||
|
var deflt = cm.state.closeBrackets;
|
||||||
|
if (!deflt || deflt.override) return deflt;
|
||||||
|
var mode = cm.getModeAt(cm.getCursor());
|
||||||
|
return mode.closeBrackets || deflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBackspace(cm) {
|
||||||
|
var conf = getConfig(cm);
|
||||||
|
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||||
|
|
||||||
|
var pairs = getOption(conf, "pairs");
|
||||||
|
var ranges = cm.listSelections();
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
if (!ranges[i].empty()) return CodeMirror.Pass;
|
||||||
|
var around = charsAround(cm, ranges[i].head);
|
||||||
|
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
||||||
|
}
|
||||||
|
for (var i = ranges.length - 1; i >= 0; i--) {
|
||||||
|
var cur = ranges[i].head;
|
||||||
|
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEnter(cm) {
|
||||||
|
var conf = getConfig(cm);
|
||||||
|
var explode = conf && getOption(conf, "explode");
|
||||||
|
if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||||
|
|
||||||
|
var ranges = cm.listSelections();
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
if (!ranges[i].empty()) return CodeMirror.Pass;
|
||||||
|
var around = charsAround(cm, ranges[i].head);
|
||||||
|
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
||||||
|
}
|
||||||
|
cm.operation(function() {
|
||||||
|
var linesep = cm.lineSeparator() || "\n";
|
||||||
|
cm.replaceSelection(linesep + linesep, null);
|
||||||
|
moveSel(cm, -1)
|
||||||
|
ranges = cm.listSelections();
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
var line = ranges[i].head.line;
|
||||||
|
cm.indentLine(line, null, true);
|
||||||
|
cm.indentLine(line + 1, null, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveSel(cm, dir) {
|
||||||
|
var newRanges = [], ranges = cm.listSelections(), primary = 0
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
var range = ranges[i]
|
||||||
|
if (range.head == cm.getCursor()) primary = i
|
||||||
|
var pos = range.head.ch || dir > 0 ? {line: range.head.line, ch: range.head.ch + dir} : {line: range.head.line - 1}
|
||||||
|
newRanges.push({anchor: pos, head: pos})
|
||||||
|
}
|
||||||
|
cm.setSelections(newRanges, primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
function contractSelection(sel) {
|
||||||
|
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
|
||||||
|
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
|
||||||
|
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))};
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChar(cm, ch) {
|
||||||
|
var conf = getConfig(cm);
|
||||||
|
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
|
||||||
|
|
||||||
|
var pairs = getOption(conf, "pairs");
|
||||||
|
var pos = pairs.indexOf(ch);
|
||||||
|
if (pos == -1) return CodeMirror.Pass;
|
||||||
|
|
||||||
|
var closeBefore = getOption(conf,"closeBefore");
|
||||||
|
|
||||||
|
var triples = getOption(conf, "triples");
|
||||||
|
|
||||||
|
var identical = pairs.charAt(pos + 1) == ch;
|
||||||
|
var ranges = cm.listSelections();
|
||||||
|
var opening = pos % 2 == 0;
|
||||||
|
|
||||||
|
var type;
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
var range = ranges[i], cur = range.head, curType;
|
||||||
|
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
|
||||||
|
if (opening && !range.empty()) {
|
||||||
|
curType = "surround";
|
||||||
|
} else if ((identical || !opening) && next == ch) {
|
||||||
|
if (identical && stringStartsAfter(cm, cur))
|
||||||
|
curType = "both";
|
||||||
|
else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
|
||||||
|
curType = "skipThree";
|
||||||
|
else
|
||||||
|
curType = "skip";
|
||||||
|
} else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
|
||||||
|
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch) {
|
||||||
|
if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass;
|
||||||
|
curType = "addFour";
|
||||||
|
} else if (identical) {
|
||||||
|
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur)
|
||||||
|
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";
|
||||||
|
else return CodeMirror.Pass;
|
||||||
|
} else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) {
|
||||||
|
curType = "both";
|
||||||
|
} else {
|
||||||
|
return CodeMirror.Pass;
|
||||||
|
}
|
||||||
|
if (!type) type = curType;
|
||||||
|
else if (type != curType) return CodeMirror.Pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
|
||||||
|
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
|
||||||
|
cm.operation(function() {
|
||||||
|
if (type == "skip") {
|
||||||
|
moveSel(cm, 1)
|
||||||
|
} else if (type == "skipThree") {
|
||||||
|
moveSel(cm, 3)
|
||||||
|
} else if (type == "surround") {
|
||||||
|
var sels = cm.getSelections();
|
||||||
|
for (var i = 0; i < sels.length; i++)
|
||||||
|
sels[i] = left + sels[i] + right;
|
||||||
|
cm.replaceSelections(sels, "around");
|
||||||
|
sels = cm.listSelections().slice();
|
||||||
|
for (var i = 0; i < sels.length; i++)
|
||||||
|
sels[i] = contractSelection(sels[i]);
|
||||||
|
cm.setSelections(sels);
|
||||||
|
} else if (type == "both") {
|
||||||
|
cm.replaceSelection(left + right, null);
|
||||||
|
cm.triggerElectric(left + right);
|
||||||
|
moveSel(cm, -1)
|
||||||
|
} else if (type == "addFour") {
|
||||||
|
cm.replaceSelection(left + left + left + left, "before");
|
||||||
|
moveSel(cm, 1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function charsAround(cm, pos) {
|
||||||
|
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
|
||||||
|
Pos(pos.line, pos.ch + 1));
|
||||||
|
return str.length == 2 ? str : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringStartsAfter(cm, pos) {
|
||||||
|
var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1))
|
||||||
|
return /\bstring/.test(token.type) && token.start == pos.ch &&
|
||||||
|
(pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos)))
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,160 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
|
||||||
|
(document.documentMode == null || document.documentMode < 8);
|
||||||
|
|
||||||
|
var Pos = CodeMirror.Pos;
|
||||||
|
|
||||||
|
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<", "<": ">>", ">": "<<"};
|
||||||
|
|
||||||
|
function bracketRegex(config) {
|
||||||
|
return config && config.bracketRegex || /[(){}[\]]/
|
||||||
|
}
|
||||||
|
|
||||||
|
function findMatchingBracket(cm, where, config) {
|
||||||
|
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
|
||||||
|
var afterCursor = config && config.afterCursor
|
||||||
|
if (afterCursor == null)
|
||||||
|
afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className)
|
||||||
|
var re = bracketRegex(config)
|
||||||
|
|
||||||
|
// A cursor is defined as between two characters, but in in vim command mode
|
||||||
|
// (i.e. not insert mode), the cursor is visually represented as a
|
||||||
|
// highlighted box on top of the 2nd character. Otherwise, we allow matches
|
||||||
|
// from before or after the cursor.
|
||||||
|
var match = (!afterCursor && pos >= 0 && re.test(line.text.charAt(pos)) && matching[line.text.charAt(pos)]) ||
|
||||||
|
re.test(line.text.charAt(pos + 1)) && matching[line.text.charAt(++pos)];
|
||||||
|
if (!match) return null;
|
||||||
|
var dir = match.charAt(1) == ">" ? 1 : -1;
|
||||||
|
if (config && config.strict && (dir > 0) != (pos == where.ch)) return null;
|
||||||
|
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
|
||||||
|
|
||||||
|
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style, config);
|
||||||
|
if (found == null) return null;
|
||||||
|
return {from: Pos(where.line, pos), to: found && found.pos,
|
||||||
|
match: found && found.ch == match.charAt(0), forward: dir > 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
// bracketRegex is used to specify which type of bracket to scan
|
||||||
|
// should be a regexp, e.g. /[[\]]/
|
||||||
|
//
|
||||||
|
// Note: If "where" is on an open bracket, then this bracket is ignored.
|
||||||
|
//
|
||||||
|
// Returns false when no bracket was found, null when it reached
|
||||||
|
// maxScanLines and gave up
|
||||||
|
function scanForBracket(cm, where, dir, style, config) {
|
||||||
|
var maxScanLen = (config && config.maxScanLineLength) || 10000;
|
||||||
|
var maxScanLines = (config && config.maxScanLines) || 1000;
|
||||||
|
|
||||||
|
var stack = [];
|
||||||
|
var re = bracketRegex(config)
|
||||||
|
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
|
||||||
|
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
|
||||||
|
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
|
||||||
|
var line = cm.getLine(lineNo);
|
||||||
|
if (!line) continue;
|
||||||
|
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
|
||||||
|
if (line.length > maxScanLen) continue;
|
||||||
|
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
|
||||||
|
for (; pos != end; pos += dir) {
|
||||||
|
var ch = line.charAt(pos);
|
||||||
|
if (re.test(ch) && (style === undefined ||
|
||||||
|
(cm.getTokenTypeAt(Pos(lineNo, pos + 1)) || "") == (style || ""))) {
|
||||||
|
var match = matching[ch];
|
||||||
|
if (match && (match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
|
||||||
|
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
|
||||||
|
else stack.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchBrackets(cm, autoclear, config) {
|
||||||
|
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
||||||
|
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000,
|
||||||
|
highlightNonMatching = config && config.highlightNonMatching;
|
||||||
|
var marks = [], ranges = cm.listSelections();
|
||||||
|
for (var i = 0; i < ranges.length; i++) {
|
||||||
|
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
|
||||||
|
if (match && (match.match || highlightNonMatching !== false) && cm.getLine(match.from.line).length <= maxHighlightLen) {
|
||||||
|
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
||||||
|
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
|
||||||
|
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
|
||||||
|
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (marks.length) {
|
||||||
|
// Kludge to work around the IE bug from issue #1193, where text
|
||||||
|
// input stops going to the textarea whenever this fires.
|
||||||
|
if (ie_lt8 && cm.state.focused) cm.focus();
|
||||||
|
|
||||||
|
var clear = function() {
|
||||||
|
cm.operation(function() {
|
||||||
|
for (var i = 0; i < marks.length; i++) marks[i].clear();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (autoclear) setTimeout(clear, 800);
|
||||||
|
else return clear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doMatchBrackets(cm) {
|
||||||
|
cm.operation(function() {
|
||||||
|
if (cm.state.matchBrackets.currentlyHighlighted) {
|
||||||
|
cm.state.matchBrackets.currentlyHighlighted();
|
||||||
|
cm.state.matchBrackets.currentlyHighlighted = null;
|
||||||
|
}
|
||||||
|
cm.state.matchBrackets.currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearHighlighted(cm) {
|
||||||
|
if (cm.state.matchBrackets && cm.state.matchBrackets.currentlyHighlighted) {
|
||||||
|
cm.state.matchBrackets.currentlyHighlighted();
|
||||||
|
cm.state.matchBrackets.currentlyHighlighted = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
|
||||||
|
if (old && old != CodeMirror.Init) {
|
||||||
|
cm.off("cursorActivity", doMatchBrackets);
|
||||||
|
cm.off("focus", doMatchBrackets)
|
||||||
|
cm.off("blur", clearHighlighted)
|
||||||
|
clearHighlighted(cm);
|
||||||
|
}
|
||||||
|
if (val) {
|
||||||
|
cm.state.matchBrackets = typeof val == "object" ? val : {};
|
||||||
|
cm.on("cursorActivity", doMatchBrackets);
|
||||||
|
cm.on("focus", doMatchBrackets)
|
||||||
|
cm.on("blur", clearHighlighted)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
||||||
|
CodeMirror.defineExtension("findMatchingBracket", function(pos, config, oldConfig){
|
||||||
|
// Backwards-compatibility kludge
|
||||||
|
if (oldConfig || typeof config == "boolean") {
|
||||||
|
if (!oldConfig) {
|
||||||
|
config = config ? {strict: true} : null
|
||||||
|
} else {
|
||||||
|
oldConfig.strict = config
|
||||||
|
config = oldConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return findMatchingBracket(this, pos, config)
|
||||||
|
});
|
||||||
|
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
|
||||||
|
return scanForBracket(this, pos, dir, style, config);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,511 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
// declare global: DOMRect
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||||
|
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||||
|
|
||||||
|
// This is the old interface, kept around for now to stay
|
||||||
|
// backwards-compatible.
|
||||||
|
CodeMirror.showHint = function(cm, getHints, options) {
|
||||||
|
if (!getHints) return cm.showHint(options);
|
||||||
|
if (options && options.async) getHints.async = true;
|
||||||
|
var newOpts = {hint: getHints};
|
||||||
|
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
||||||
|
return cm.showHint(newOpts);
|
||||||
|
};
|
||||||
|
|
||||||
|
CodeMirror.defineExtension("showHint", function(options) {
|
||||||
|
options = parseOptions(this, this.getCursor("start"), options);
|
||||||
|
var selections = this.listSelections()
|
||||||
|
if (selections.length > 1) return;
|
||||||
|
// By default, don't allow completion when something is selected.
|
||||||
|
// A hint function can have a `supportsSelection` property to
|
||||||
|
// indicate that it can handle selections.
|
||||||
|
if (this.somethingSelected()) {
|
||||||
|
if (!options.hint.supportsSelection) return;
|
||||||
|
// Don't try with cross-line selections
|
||||||
|
for (var i = 0; i < selections.length; i++)
|
||||||
|
if (selections[i].head.line != selections[i].anchor.line) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.state.completionActive) this.state.completionActive.close();
|
||||||
|
var completion = this.state.completionActive = new Completion(this, options);
|
||||||
|
if (!completion.options.hint) return;
|
||||||
|
|
||||||
|
CodeMirror.signal(this, "startCompletion", this);
|
||||||
|
completion.update(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.defineExtension("closeHint", function() {
|
||||||
|
if (this.state.completionActive) this.state.completionActive.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
function Completion(cm, options) {
|
||||||
|
this.cm = cm;
|
||||||
|
this.options = options;
|
||||||
|
this.widget = null;
|
||||||
|
this.debounce = 0;
|
||||||
|
this.tick = 0;
|
||||||
|
this.startPos = this.cm.getCursor("start");
|
||||||
|
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
|
||||||
|
|
||||||
|
if (this.options.updateOnCursorActivity) {
|
||||||
|
var self = this;
|
||||||
|
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
||||||
|
return setTimeout(fn, 1000/60);
|
||||||
|
};
|
||||||
|
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
|
||||||
|
|
||||||
|
Completion.prototype = {
|
||||||
|
close: function() {
|
||||||
|
if (!this.active()) return;
|
||||||
|
this.cm.state.completionActive = null;
|
||||||
|
this.tick = null;
|
||||||
|
if (this.options.updateOnCursorActivity) {
|
||||||
|
this.cm.off("cursorActivity", this.activityFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
|
||||||
|
if (this.widget) this.widget.close();
|
||||||
|
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
||||||
|
},
|
||||||
|
|
||||||
|
active: function() {
|
||||||
|
return this.cm.state.completionActive == this;
|
||||||
|
},
|
||||||
|
|
||||||
|
pick: function(data, i) {
|
||||||
|
var completion = data.list[i], self = this;
|
||||||
|
this.cm.operation(function() {
|
||||||
|
if (completion.hint)
|
||||||
|
completion.hint(self.cm, data, completion);
|
||||||
|
else
|
||||||
|
self.cm.replaceRange(getText(completion), completion.from || data.from,
|
||||||
|
completion.to || data.to, "complete");
|
||||||
|
CodeMirror.signal(data, "pick", completion);
|
||||||
|
self.cm.scrollIntoView();
|
||||||
|
});
|
||||||
|
if (this.options.closeOnPick) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
cursorActivity: function() {
|
||||||
|
if (this.debounce) {
|
||||||
|
cancelAnimationFrame(this.debounce);
|
||||||
|
this.debounce = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var identStart = this.startPos;
|
||||||
|
if(this.data) {
|
||||||
|
identStart = this.data.from;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
|
||||||
|
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
|
||||||
|
pos.ch < identStart.ch || this.cm.somethingSelected() ||
|
||||||
|
(!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
|
||||||
|
this.close();
|
||||||
|
} else {
|
||||||
|
var self = this;
|
||||||
|
this.debounce = requestAnimationFrame(function() {self.update();});
|
||||||
|
if (this.widget) this.widget.disable();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function(first) {
|
||||||
|
if (this.tick == null) return
|
||||||
|
var self = this, myTick = ++this.tick
|
||||||
|
fetchHints(this.options.hint, this.cm, this.options, function(data) {
|
||||||
|
if (self.tick == myTick) self.finishUpdate(data, first)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
finishUpdate: function(data, first) {
|
||||||
|
if (this.data) CodeMirror.signal(this.data, "update");
|
||||||
|
|
||||||
|
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
|
||||||
|
if (this.widget) this.widget.close();
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
|
||||||
|
if (data && data.list.length) {
|
||||||
|
if (picked && data.list.length == 1) {
|
||||||
|
this.pick(data, 0);
|
||||||
|
} else {
|
||||||
|
this.widget = new Widget(this, data);
|
||||||
|
CodeMirror.signal(data, "shown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function parseOptions(cm, pos, options) {
|
||||||
|
var editor = cm.options.hintOptions;
|
||||||
|
var out = {};
|
||||||
|
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
|
||||||
|
if (editor) for (var prop in editor)
|
||||||
|
if (editor[prop] !== undefined) out[prop] = editor[prop];
|
||||||
|
if (options) for (var prop in options)
|
||||||
|
if (options[prop] !== undefined) out[prop] = options[prop];
|
||||||
|
if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getText(completion) {
|
||||||
|
if (typeof completion == "string") return completion;
|
||||||
|
else return completion.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildKeyMap(completion, handle) {
|
||||||
|
var baseMap = {
|
||||||
|
Up: function() {handle.moveFocus(-1);},
|
||||||
|
Down: function() {handle.moveFocus(1);},
|
||||||
|
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
||||||
|
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
||||||
|
Home: function() {handle.setFocus(0);},
|
||||||
|
End: function() {handle.setFocus(handle.length - 1);},
|
||||||
|
Enter: handle.pick,
|
||||||
|
Tab: handle.pick,
|
||||||
|
Esc: handle.close
|
||||||
|
};
|
||||||
|
|
||||||
|
var mac = /Mac/.test(navigator.platform);
|
||||||
|
|
||||||
|
if (mac) {
|
||||||
|
baseMap["Ctrl-P"] = function() {handle.moveFocus(-1);};
|
||||||
|
baseMap["Ctrl-N"] = function() {handle.moveFocus(1);};
|
||||||
|
}
|
||||||
|
|
||||||
|
var custom = completion.options.customKeys;
|
||||||
|
var ourMap = custom ? {} : baseMap;
|
||||||
|
function addBinding(key, val) {
|
||||||
|
var bound;
|
||||||
|
if (typeof val != "string")
|
||||||
|
bound = function(cm) { return val(cm, handle); };
|
||||||
|
// This mechanism is deprecated
|
||||||
|
else if (baseMap.hasOwnProperty(val))
|
||||||
|
bound = baseMap[val];
|
||||||
|
else
|
||||||
|
bound = val;
|
||||||
|
ourMap[key] = bound;
|
||||||
|
}
|
||||||
|
if (custom)
|
||||||
|
for (var key in custom) if (custom.hasOwnProperty(key))
|
||||||
|
addBinding(key, custom[key]);
|
||||||
|
var extra = completion.options.extraKeys;
|
||||||
|
if (extra)
|
||||||
|
for (var key in extra) if (extra.hasOwnProperty(key))
|
||||||
|
addBinding(key, extra[key]);
|
||||||
|
return ourMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHintElement(hintsElement, el) {
|
||||||
|
while (el && el != hintsElement) {
|
||||||
|
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
|
||||||
|
el = el.parentNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Widget(completion, data) {
|
||||||
|
this.completion = completion;
|
||||||
|
this.data = data;
|
||||||
|
this.picked = false;
|
||||||
|
var widget = this, cm = completion.cm;
|
||||||
|
var ownerDocument = cm.getInputField().ownerDocument;
|
||||||
|
var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow;
|
||||||
|
|
||||||
|
var hints = this.hints = ownerDocument.createElement("ul");
|
||||||
|
var theme = completion.cm.options.theme;
|
||||||
|
hints.className = "CodeMirror-hints " + theme;
|
||||||
|
this.selectedHint = data.selectedHint || 0;
|
||||||
|
|
||||||
|
var completions = data.list;
|
||||||
|
for (var i = 0; i < completions.length; ++i) {
|
||||||
|
var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i];
|
||||||
|
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
||||||
|
if (cur.className != null) className = cur.className + " " + className;
|
||||||
|
elt.className = className;
|
||||||
|
if (cur.render) cur.render(elt, data, cur);
|
||||||
|
else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur)));
|
||||||
|
elt.hintId = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var container = completion.options.container || ownerDocument.body;
|
||||||
|
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
||||||
|
var left = pos.left, top = pos.bottom, below = true;
|
||||||
|
var offsetLeft = 0, offsetTop = 0;
|
||||||
|
if (container !== ownerDocument.body) {
|
||||||
|
// We offset the cursor position because left and top are relative to the offsetParent's top left corner.
|
||||||
|
var isContainerPositioned = ['absolute', 'relative', 'fixed'].indexOf(parentWindow.getComputedStyle(container).position) !== -1;
|
||||||
|
var offsetParent = isContainerPositioned ? container : container.offsetParent;
|
||||||
|
var offsetParentPosition = offsetParent.getBoundingClientRect();
|
||||||
|
var bodyPosition = ownerDocument.body.getBoundingClientRect();
|
||||||
|
offsetLeft = (offsetParentPosition.left - bodyPosition.left - offsetParent.scrollLeft);
|
||||||
|
offsetTop = (offsetParentPosition.top - bodyPosition.top - offsetParent.scrollTop);
|
||||||
|
}
|
||||||
|
hints.style.left = (left - offsetLeft) + "px";
|
||||||
|
hints.style.top = (top - offsetTop) + "px";
|
||||||
|
|
||||||
|
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||||
|
var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth);
|
||||||
|
var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
|
||||||
|
container.appendChild(hints);
|
||||||
|
|
||||||
|
var box = completion.options.moveOnOverlap ? hints.getBoundingClientRect() : new DOMRect();
|
||||||
|
var scrolls = completion.options.paddingForScrollbar ? hints.scrollHeight > hints.clientHeight + 1 : false;
|
||||||
|
|
||||||
|
// Compute in the timeout to avoid reflow on init
|
||||||
|
var startScroll;
|
||||||
|
setTimeout(function() { startScroll = cm.getScrollInfo(); });
|
||||||
|
|
||||||
|
var overlapY = box.bottom - winH;
|
||||||
|
if (overlapY > 0) {
|
||||||
|
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
|
||||||
|
if (curTop - height > 0) { // Fits above cursor
|
||||||
|
hints.style.top = (top = pos.top - height - offsetTop) + "px";
|
||||||
|
below = false;
|
||||||
|
} else if (height > winH) {
|
||||||
|
hints.style.height = (winH - 5) + "px";
|
||||||
|
hints.style.top = (top = pos.bottom - box.top - offsetTop) + "px";
|
||||||
|
var cursor = cm.getCursor();
|
||||||
|
if (data.from.ch != cursor.ch) {
|
||||||
|
pos = cm.cursorCoords(cursor);
|
||||||
|
hints.style.left = (left = pos.left - offsetLeft) + "px";
|
||||||
|
box = hints.getBoundingClientRect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var overlapX = box.right - winW;
|
||||||
|
if (scrolls) overlapX += cm.display.nativeBarWidth;
|
||||||
|
if (overlapX > 0) {
|
||||||
|
if (box.right - box.left > winW) {
|
||||||
|
hints.style.width = (winW - 5) + "px";
|
||||||
|
overlapX -= (box.right - box.left) - winW;
|
||||||
|
}
|
||||||
|
hints.style.left = (left = pos.left - overlapX - offsetLeft) + "px";
|
||||||
|
}
|
||||||
|
if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
|
||||||
|
node.style.paddingRight = cm.display.nativeBarWidth + "px"
|
||||||
|
|
||||||
|
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
||||||
|
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||||
|
setFocus: function(n) { widget.changeActive(n); },
|
||||||
|
menuSize: function() { return widget.screenAmount(); },
|
||||||
|
length: completions.length,
|
||||||
|
close: function() { completion.close(); },
|
||||||
|
pick: function() { widget.pick(); },
|
||||||
|
data: data
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (completion.options.closeOnUnfocus) {
|
||||||
|
var closingOnBlur;
|
||||||
|
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||||
|
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||||
|
}
|
||||||
|
|
||||||
|
cm.on("scroll", this.onScroll = function() {
|
||||||
|
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
||||||
|
if (!startScroll) startScroll = cm.getScrollInfo();
|
||||||
|
var newTop = top + startScroll.top - curScroll.top;
|
||||||
|
var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop);
|
||||||
|
if (!below) point += hints.offsetHeight;
|
||||||
|
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
||||||
|
hints.style.top = newTop + "px";
|
||||||
|
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.on(hints, "dblclick", function(e) {
|
||||||
|
var t = getHintElement(hints, e.target || e.srcElement);
|
||||||
|
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.on(hints, "click", function(e) {
|
||||||
|
var t = getHintElement(hints, e.target || e.srcElement);
|
||||||
|
if (t && t.hintId != null) {
|
||||||
|
widget.changeActive(t.hintId);
|
||||||
|
if (completion.options.completeOnSingleClick) widget.pick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.on(hints, "mousedown", function() {
|
||||||
|
setTimeout(function(){cm.focus();}, 20);
|
||||||
|
});
|
||||||
|
|
||||||
|
// The first hint doesn't need to be scrolled to on init
|
||||||
|
var selectedHintRange = this.getSelectedHintRange();
|
||||||
|
if (selectedHintRange.from !== 0 || selectedHintRange.to !== 0) {
|
||||||
|
this.scrollToActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget.prototype = {
|
||||||
|
close: function() {
|
||||||
|
if (this.completion.widget != this) return;
|
||||||
|
this.completion.widget = null;
|
||||||
|
if (this.hints.parentNode) this.hints.parentNode.removeChild(this.hints);
|
||||||
|
this.completion.cm.removeKeyMap(this.keyMap);
|
||||||
|
|
||||||
|
var cm = this.completion.cm;
|
||||||
|
if (this.completion.options.closeOnUnfocus) {
|
||||||
|
cm.off("blur", this.onBlur);
|
||||||
|
cm.off("focus", this.onFocus);
|
||||||
|
}
|
||||||
|
cm.off("scroll", this.onScroll);
|
||||||
|
},
|
||||||
|
|
||||||
|
disable: function() {
|
||||||
|
this.completion.cm.removeKeyMap(this.keyMap);
|
||||||
|
var widget = this;
|
||||||
|
this.keyMap = {Enter: function() { widget.picked = true; }};
|
||||||
|
this.completion.cm.addKeyMap(this.keyMap);
|
||||||
|
},
|
||||||
|
|
||||||
|
pick: function() {
|
||||||
|
this.completion.pick(this.data, this.selectedHint);
|
||||||
|
},
|
||||||
|
|
||||||
|
changeActive: function(i, avoidWrap) {
|
||||||
|
if (i >= this.data.list.length)
|
||||||
|
i = avoidWrap ? this.data.list.length - 1 : 0;
|
||||||
|
else if (i < 0)
|
||||||
|
i = avoidWrap ? 0 : this.data.list.length - 1;
|
||||||
|
if (this.selectedHint == i) return;
|
||||||
|
var node = this.hints.childNodes[this.selectedHint];
|
||||||
|
if (node) node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
||||||
|
node = this.hints.childNodes[this.selectedHint = i];
|
||||||
|
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
||||||
|
this.scrollToActive()
|
||||||
|
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollToActive: function() {
|
||||||
|
var selectedHintRange = this.getSelectedHintRange();
|
||||||
|
var node1 = this.hints.childNodes[selectedHintRange.from];
|
||||||
|
var node2 = this.hints.childNodes[selectedHintRange.to];
|
||||||
|
var firstNode = this.hints.firstChild;
|
||||||
|
if (node1.offsetTop < this.hints.scrollTop)
|
||||||
|
this.hints.scrollTop = node1.offsetTop - firstNode.offsetTop;
|
||||||
|
else if (node2.offsetTop + node2.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
||||||
|
this.hints.scrollTop = node2.offsetTop + node2.offsetHeight - this.hints.clientHeight + firstNode.offsetTop;
|
||||||
|
},
|
||||||
|
|
||||||
|
screenAmount: function() {
|
||||||
|
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSelectedHintRange: function() {
|
||||||
|
var margin = this.completion.options.scrollMargin || 0;
|
||||||
|
return {
|
||||||
|
from: Math.max(0, this.selectedHint - margin),
|
||||||
|
to: Math.min(this.data.list.length - 1, this.selectedHint + margin),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function applicableHelpers(cm, helpers) {
|
||||||
|
if (!cm.somethingSelected()) return helpers
|
||||||
|
var result = []
|
||||||
|
for (var i = 0; i < helpers.length; i++)
|
||||||
|
if (helpers[i].supportsSelection) result.push(helpers[i])
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchHints(hint, cm, options, callback) {
|
||||||
|
if (hint.async) {
|
||||||
|
hint(cm, callback, options)
|
||||||
|
} else {
|
||||||
|
var result = hint(cm, options)
|
||||||
|
if (result && result.then) result.then(callback)
|
||||||
|
else callback(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveAutoHints(cm, pos) {
|
||||||
|
var helpers = cm.getHelpers(pos, "hint"), words
|
||||||
|
if (helpers.length) {
|
||||||
|
var resolved = function(cm, callback, options) {
|
||||||
|
var app = applicableHelpers(cm, helpers);
|
||||||
|
function run(i) {
|
||||||
|
if (i == app.length) return callback(null)
|
||||||
|
fetchHints(app[i], cm, options, function(result) {
|
||||||
|
if (result && result.list.length > 0) callback(result)
|
||||||
|
else run(i + 1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
run(0)
|
||||||
|
}
|
||||||
|
resolved.async = true
|
||||||
|
resolved.supportsSelection = true
|
||||||
|
return resolved
|
||||||
|
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
||||||
|
return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
|
||||||
|
} else if (CodeMirror.hint.anyword) {
|
||||||
|
return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
|
||||||
|
} else {
|
||||||
|
return function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.registerHelper("hint", "auto", {
|
||||||
|
resolve: resolveAutoHints
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
|
||||||
|
var cur = cm.getCursor(), token = cm.getTokenAt(cur)
|
||||||
|
var term, from = CodeMirror.Pos(cur.line, token.start), to = cur
|
||||||
|
if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) {
|
||||||
|
term = token.string.substr(0, cur.ch - token.start)
|
||||||
|
} else {
|
||||||
|
term = ""
|
||||||
|
from = cur
|
||||||
|
}
|
||||||
|
var found = [];
|
||||||
|
for (var i = 0; i < options.words.length; i++) {
|
||||||
|
var word = options.words[i];
|
||||||
|
if (word.slice(0, term.length) == term)
|
||||||
|
found.push(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found.length) return {list: found, from: from, to: to};
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
||||||
|
|
||||||
|
var defaultOptions = {
|
||||||
|
hint: CodeMirror.hint.auto,
|
||||||
|
completeSingle: true,
|
||||||
|
alignWithWord: true,
|
||||||
|
closeCharacters: /[\s()\[\]{};:>,]/,
|
||||||
|
closeOnPick: true,
|
||||||
|
closeOnUnfocus: true,
|
||||||
|
updateOnCursorActivity: true,
|
||||||
|
completeOnSingleClick: true,
|
||||||
|
container: null,
|
||||||
|
customKeys: null,
|
||||||
|
extraKeys: null,
|
||||||
|
paddingForScrollbar: true,
|
||||||
|
moveOnOverlap: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
CodeMirror.defineOption("hintOptions", null);
|
||||||
|
});
|
|
@ -0,0 +1,40 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
// Depends on jsonlint.js from https://github.com/zaach/jsonlint
|
||||||
|
|
||||||
|
// declare global: jsonlint
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
CodeMirror.registerHelper("lint", "json", function(text) {
|
||||||
|
var found = [];
|
||||||
|
if (!window.jsonlint) {
|
||||||
|
if (window.console) {
|
||||||
|
window.console.error("Error: window.jsonlint not defined, CodeMirror JSON linting cannot run.");
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
// for jsonlint's web dist jsonlint is exported as an object with a single property parser, of which parseError
|
||||||
|
// is a subproperty
|
||||||
|
var jsonlint = window.jsonlint.parser || window.jsonlint
|
||||||
|
jsonlint.parseError = function(str, hash) {
|
||||||
|
var loc = hash.loc;
|
||||||
|
found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
||||||
|
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
||||||
|
message: str});
|
||||||
|
};
|
||||||
|
try { jsonlint.parse(text); }
|
||||||
|
catch(e) {}
|
||||||
|
return found;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,279 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
var GUTTER_ID = "CodeMirror-lint-markers";
|
||||||
|
var LINT_LINE_ID = "CodeMirror-lint-line-";
|
||||||
|
|
||||||
|
function showTooltip(cm, e, content) {
|
||||||
|
var tt = document.createElement("div");
|
||||||
|
tt.className = "CodeMirror-lint-tooltip cm-s-" + cm.options.theme;
|
||||||
|
tt.appendChild(content.cloneNode(true));
|
||||||
|
if (cm.state.lint.options.selfContain)
|
||||||
|
cm.getWrapperElement().appendChild(tt);
|
||||||
|
else
|
||||||
|
document.body.appendChild(tt);
|
||||||
|
|
||||||
|
function position(e) {
|
||||||
|
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
|
||||||
|
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
|
||||||
|
tt.style.left = (e.clientX + 5) + "px";
|
||||||
|
}
|
||||||
|
CodeMirror.on(document, "mousemove", position);
|
||||||
|
position(e);
|
||||||
|
if (tt.style.opacity != null) tt.style.opacity = 1;
|
||||||
|
return tt;
|
||||||
|
}
|
||||||
|
function rm(elt) {
|
||||||
|
if (elt.parentNode) elt.parentNode.removeChild(elt);
|
||||||
|
}
|
||||||
|
function hideTooltip(tt) {
|
||||||
|
if (!tt.parentNode) return;
|
||||||
|
if (tt.style.opacity == null) rm(tt);
|
||||||
|
tt.style.opacity = 0;
|
||||||
|
setTimeout(function() { rm(tt); }, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showTooltipFor(cm, e, content, node) {
|
||||||
|
var tooltip = showTooltip(cm, e, content);
|
||||||
|
function hide() {
|
||||||
|
CodeMirror.off(node, "mouseout", hide);
|
||||||
|
if (tooltip) { hideTooltip(tooltip); tooltip = null; }
|
||||||
|
}
|
||||||
|
var poll = setInterval(function() {
|
||||||
|
if (tooltip) for (var n = node;; n = n.parentNode) {
|
||||||
|
if (n && n.nodeType == 11) n = n.host;
|
||||||
|
if (n == document.body) return;
|
||||||
|
if (!n) { hide(); break; }
|
||||||
|
}
|
||||||
|
if (!tooltip) return clearInterval(poll);
|
||||||
|
}, 400);
|
||||||
|
CodeMirror.on(node, "mouseout", hide);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LintState(cm, options, hasGutter) {
|
||||||
|
this.marked = [];
|
||||||
|
this.options = options;
|
||||||
|
this.timeout = null;
|
||||||
|
this.hasGutter = hasGutter;
|
||||||
|
this.onMouseOver = function(e) { onMouseOver(cm, e); };
|
||||||
|
this.waitingFor = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseOptions(_cm, options) {
|
||||||
|
if (options instanceof Function) return {getAnnotations: options};
|
||||||
|
if (!options || options === true) options = {};
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearMarks(cm) {
|
||||||
|
var state = cm.state.lint;
|
||||||
|
if (state.hasGutter) cm.clearGutter(GUTTER_ID);
|
||||||
|
if (isHighlightErrorLinesEnabled(state)) clearErrorLines(cm);
|
||||||
|
for (var i = 0; i < state.marked.length; ++i)
|
||||||
|
state.marked[i].clear();
|
||||||
|
state.marked.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearErrorLines(cm) {
|
||||||
|
cm.eachLine(function(line) {
|
||||||
|
var has = line.wrapClass && /\bCodeMirror-lint-line-\w+\b/.exec(line.wrapClass);
|
||||||
|
if (has) cm.removeLineClass(line, "wrap", has[0]);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function isHighlightErrorLinesEnabled(state) {
|
||||||
|
return state.options.highlightLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeMarker(cm, labels, severity, multiple, tooltips) {
|
||||||
|
var marker = document.createElement("div"), inner = marker;
|
||||||
|
marker.className = "CodeMirror-lint-marker CodeMirror-lint-marker-" + severity;
|
||||||
|
if (multiple) {
|
||||||
|
inner = marker.appendChild(document.createElement("div"));
|
||||||
|
inner.className = "CodeMirror-lint-marker CodeMirror-lint-marker-multiple";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
|
||||||
|
showTooltipFor(cm, e, labels, inner);
|
||||||
|
});
|
||||||
|
|
||||||
|
return marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMaxSeverity(a, b) {
|
||||||
|
if (a == "error") return a;
|
||||||
|
else return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function groupByLine(annotations) {
|
||||||
|
var lines = [];
|
||||||
|
for (var i = 0; i < annotations.length; ++i) {
|
||||||
|
var ann = annotations[i], line = ann.from.line;
|
||||||
|
(lines[line] || (lines[line] = [])).push(ann);
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
function annotationTooltip(ann) {
|
||||||
|
var severity = ann.severity;
|
||||||
|
if (!severity) severity = "error";
|
||||||
|
var tip = document.createElement("div");
|
||||||
|
tip.className = "CodeMirror-lint-message CodeMirror-lint-message-" + severity;
|
||||||
|
if (typeof ann.messageHTML != 'undefined') {
|
||||||
|
tip.innerHTML = ann.messageHTML;
|
||||||
|
} else {
|
||||||
|
tip.appendChild(document.createTextNode(ann.message));
|
||||||
|
}
|
||||||
|
return tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lintAsync(cm, getAnnotations, passOptions) {
|
||||||
|
var state = cm.state.lint
|
||||||
|
var id = ++state.waitingFor
|
||||||
|
function abort() {
|
||||||
|
id = -1
|
||||||
|
cm.off("change", abort)
|
||||||
|
}
|
||||||
|
cm.on("change", abort)
|
||||||
|
getAnnotations(cm.getValue(), function(annotations, arg2) {
|
||||||
|
cm.off("change", abort)
|
||||||
|
if (state.waitingFor != id) return
|
||||||
|
if (arg2 && annotations instanceof CodeMirror) annotations = arg2
|
||||||
|
cm.operation(function() {updateLinting(cm, annotations)})
|
||||||
|
}, passOptions, cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startLinting(cm) {
|
||||||
|
var state = cm.state.lint;
|
||||||
|
if (!state) return;
|
||||||
|
var options = state.options;
|
||||||
|
/*
|
||||||
|
* Passing rules in `options` property prevents JSHint (and other linters) from complaining
|
||||||
|
* about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc.
|
||||||
|
*/
|
||||||
|
var passOptions = options.options || options;
|
||||||
|
var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
|
||||||
|
if (!getAnnotations) return;
|
||||||
|
if (options.async || getAnnotations.async) {
|
||||||
|
lintAsync(cm, getAnnotations, passOptions)
|
||||||
|
} else {
|
||||||
|
var annotations = getAnnotations(cm.getValue(), passOptions, cm);
|
||||||
|
if (!annotations) return;
|
||||||
|
if (annotations.then) annotations.then(function(issues) {
|
||||||
|
cm.operation(function() {updateLinting(cm, issues)})
|
||||||
|
});
|
||||||
|
else cm.operation(function() {updateLinting(cm, annotations)})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLinting(cm, annotationsNotSorted) {
|
||||||
|
var state = cm.state.lint;
|
||||||
|
if (!state) return;
|
||||||
|
var options = state.options;
|
||||||
|
clearMarks(cm);
|
||||||
|
|
||||||
|
var annotations = groupByLine(annotationsNotSorted);
|
||||||
|
|
||||||
|
for (var line = 0; line < annotations.length; ++line) {
|
||||||
|
var anns = annotations[line];
|
||||||
|
if (!anns) continue;
|
||||||
|
|
||||||
|
// filter out duplicate messages
|
||||||
|
var message = [];
|
||||||
|
anns = anns.filter(function(item) { return message.indexOf(item.message) > -1 ? false : message.push(item.message) });
|
||||||
|
|
||||||
|
var maxSeverity = null;
|
||||||
|
var tipLabel = state.hasGutter && document.createDocumentFragment();
|
||||||
|
|
||||||
|
for (var i = 0; i < anns.length; ++i) {
|
||||||
|
var ann = anns[i];
|
||||||
|
var severity = ann.severity;
|
||||||
|
if (!severity) severity = "error";
|
||||||
|
maxSeverity = getMaxSeverity(maxSeverity, severity);
|
||||||
|
|
||||||
|
if (options.formatAnnotation) ann = options.formatAnnotation(ann);
|
||||||
|
if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
|
||||||
|
|
||||||
|
if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
|
||||||
|
className: "CodeMirror-lint-mark CodeMirror-lint-mark-" + severity,
|
||||||
|
__annotation: ann
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
// use original annotations[line] to show multiple messages
|
||||||
|
if (state.hasGutter)
|
||||||
|
cm.setGutterMarker(line, GUTTER_ID, makeMarker(cm, tipLabel, maxSeverity, annotations[line].length > 1,
|
||||||
|
state.options.tooltips));
|
||||||
|
|
||||||
|
if (isHighlightErrorLinesEnabled(state))
|
||||||
|
cm.addLineClass(line, "wrap", LINT_LINE_ID + maxSeverity);
|
||||||
|
}
|
||||||
|
if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onChange(cm) {
|
||||||
|
var state = cm.state.lint;
|
||||||
|
if (!state) return;
|
||||||
|
clearTimeout(state.timeout);
|
||||||
|
state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function popupTooltips(cm, annotations, e) {
|
||||||
|
var target = e.target || e.srcElement;
|
||||||
|
var tooltip = document.createDocumentFragment();
|
||||||
|
for (var i = 0; i < annotations.length; i++) {
|
||||||
|
var ann = annotations[i];
|
||||||
|
tooltip.appendChild(annotationTooltip(ann));
|
||||||
|
}
|
||||||
|
showTooltipFor(cm, e, tooltip, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseOver(cm, e) {
|
||||||
|
var target = e.target || e.srcElement;
|
||||||
|
if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
|
||||||
|
var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
|
||||||
|
var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
|
||||||
|
|
||||||
|
var annotations = [];
|
||||||
|
for (var i = 0; i < spans.length; ++i) {
|
||||||
|
var ann = spans[i].__annotation;
|
||||||
|
if (ann) annotations.push(ann);
|
||||||
|
}
|
||||||
|
if (annotations.length) popupTooltips(cm, annotations, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineOption("lint", false, function(cm, val, old) {
|
||||||
|
if (old && old != CodeMirror.Init) {
|
||||||
|
clearMarks(cm);
|
||||||
|
if (cm.state.lint.options.lintOnChange !== false)
|
||||||
|
cm.off("change", onChange);
|
||||||
|
CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
|
||||||
|
clearTimeout(cm.state.lint.timeout);
|
||||||
|
delete cm.state.lint;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
var gutters = cm.getOption("gutters"), hasLintGutter = false;
|
||||||
|
for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
|
||||||
|
var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
|
||||||
|
if (state.options.lintOnChange !== false)
|
||||||
|
cm.on("change", onChange);
|
||||||
|
if (state.options.tooltips != false && state.options.tooltips != "gutter")
|
||||||
|
CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
|
||||||
|
|
||||||
|
startLinting(cm);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.defineExtension("performLint", function() {
|
||||||
|
startLinting(this);
|
||||||
|
});
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,959 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
||||||
|
var indentUnit = config.indentUnit;
|
||||||
|
var statementIndent = parserConfig.statementIndent;
|
||||||
|
var jsonldMode = parserConfig.jsonld;
|
||||||
|
var jsonMode = parserConfig.json || jsonldMode;
|
||||||
|
var trackScope = parserConfig.trackScope !== false
|
||||||
|
var isTS = parserConfig.typescript;
|
||||||
|
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
|
||||||
|
|
||||||
|
// Tokenizer
|
||||||
|
|
||||||
|
var keywords = function(){
|
||||||
|
function kw(type) {return {type: type, style: "keyword"};}
|
||||||
|
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d");
|
||||||
|
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
||||||
|
|
||||||
|
return {
|
||||||
|
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
||||||
|
"return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C,
|
||||||
|
"debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"),
|
||||||
|
"function": kw("function"), "catch": kw("catch"),
|
||||||
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
||||||
|
"in": operator, "typeof": operator, "instanceof": operator,
|
||||||
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
||||||
|
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
|
||||||
|
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
|
||||||
|
"await": C
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
|
||||||
|
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
|
||||||
|
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
|
||||||
|
|
||||||
|
function readRegexp(stream) {
|
||||||
|
var escaped = false, next, inSet = false;
|
||||||
|
while ((next = stream.next()) != null) {
|
||||||
|
if (!escaped) {
|
||||||
|
if (next == "/" && !inSet) return;
|
||||||
|
if (next == "[") inSet = true;
|
||||||
|
else if (inSet && next == "]") inSet = false;
|
||||||
|
}
|
||||||
|
escaped = !escaped && next == "\\";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used as scratch variables to communicate multiple values without
|
||||||
|
// consing up tons of objects.
|
||||||
|
var type, content;
|
||||||
|
function ret(tp, style, cont) {
|
||||||
|
type = tp; content = cont;
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
function tokenBase(stream, state) {
|
||||||
|
var ch = stream.next();
|
||||||
|
if (ch == '"' || ch == "'") {
|
||||||
|
state.tokenize = tokenString(ch);
|
||||||
|
return state.tokenize(stream, state);
|
||||||
|
} else if (ch == "." && stream.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/)) {
|
||||||
|
return ret("number", "number");
|
||||||
|
} else if (ch == "." && stream.match("..")) {
|
||||||
|
return ret("spread", "meta");
|
||||||
|
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||||
|
return ret(ch);
|
||||||
|
} else if (ch == "=" && stream.eat(">")) {
|
||||||
|
return ret("=>", "operator");
|
||||||
|
} else if (ch == "0" && stream.match(/^(?:x[\dA-Fa-f_]+|o[0-7_]+|b[01_]+)n?/)) {
|
||||||
|
return ret("number", "number");
|
||||||
|
} else if (/\d/.test(ch)) {
|
||||||
|
stream.match(/^[\d_]*(?:n|(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?/);
|
||||||
|
return ret("number", "number");
|
||||||
|
} else if (ch == "/") {
|
||||||
|
if (stream.eat("*")) {
|
||||||
|
state.tokenize = tokenComment;
|
||||||
|
return tokenComment(stream, state);
|
||||||
|
} else if (stream.eat("/")) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return ret("comment", "comment");
|
||||||
|
} else if (expressionAllowed(stream, state, 1)) {
|
||||||
|
readRegexp(stream);
|
||||||
|
stream.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/);
|
||||||
|
return ret("regexp", "string-2");
|
||||||
|
} else {
|
||||||
|
stream.eat("=");
|
||||||
|
return ret("operator", "operator", stream.current());
|
||||||
|
}
|
||||||
|
} else if (ch == "`") {
|
||||||
|
state.tokenize = tokenQuasi;
|
||||||
|
return tokenQuasi(stream, state);
|
||||||
|
} else if (ch == "#" && stream.peek() == "!") {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return ret("meta", "meta");
|
||||||
|
} else if (ch == "#" && stream.eatWhile(wordRE)) {
|
||||||
|
return ret("variable", "property")
|
||||||
|
} else if (ch == "<" && stream.match("!--") ||
|
||||||
|
(ch == "-" && stream.match("->") && !/\S/.test(stream.string.slice(0, stream.start)))) {
|
||||||
|
stream.skipToEnd()
|
||||||
|
return ret("comment", "comment")
|
||||||
|
} else if (isOperatorChar.test(ch)) {
|
||||||
|
if (ch != ">" || !state.lexical || state.lexical.type != ">") {
|
||||||
|
if (stream.eat("=")) {
|
||||||
|
if (ch == "!" || ch == "=") stream.eat("=")
|
||||||
|
} else if (/[<>*+\-|&?]/.test(ch)) {
|
||||||
|
stream.eat(ch)
|
||||||
|
if (ch == ">") stream.eat(ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ch == "?" && stream.eat(".")) return ret(".")
|
||||||
|
return ret("operator", "operator", stream.current());
|
||||||
|
} else if (wordRE.test(ch)) {
|
||||||
|
stream.eatWhile(wordRE);
|
||||||
|
var word = stream.current()
|
||||||
|
if (state.lastType != ".") {
|
||||||
|
if (keywords.propertyIsEnumerable(word)) {
|
||||||
|
var kw = keywords[word]
|
||||||
|
return ret(kw.type, kw.style, word)
|
||||||
|
}
|
||||||
|
if (word == "async" && stream.match(/^(\s|\/\*([^*]|\*(?!\/))*?\*\/)*[\[\(\w]/, false))
|
||||||
|
return ret("async", "keyword", word)
|
||||||
|
}
|
||||||
|
return ret("variable", "variable", word)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenString(quote) {
|
||||||
|
return function(stream, state) {
|
||||||
|
var escaped = false, next;
|
||||||
|
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
|
||||||
|
state.tokenize = tokenBase;
|
||||||
|
return ret("jsonld-keyword", "meta");
|
||||||
|
}
|
||||||
|
while ((next = stream.next()) != null) {
|
||||||
|
if (next == quote && !escaped) break;
|
||||||
|
escaped = !escaped && next == "\\";
|
||||||
|
}
|
||||||
|
if (!escaped) state.tokenize = tokenBase;
|
||||||
|
return ret("string", "string");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenComment(stream, state) {
|
||||||
|
var maybeEnd = false, ch;
|
||||||
|
while (ch = stream.next()) {
|
||||||
|
if (ch == "/" && maybeEnd) {
|
||||||
|
state.tokenize = tokenBase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
maybeEnd = (ch == "*");
|
||||||
|
}
|
||||||
|
return ret("comment", "comment");
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenQuasi(stream, state) {
|
||||||
|
var escaped = false, next;
|
||||||
|
while ((next = stream.next()) != null) {
|
||||||
|
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
|
||||||
|
state.tokenize = tokenBase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
escaped = !escaped && next == "\\";
|
||||||
|
}
|
||||||
|
return ret("quasi", "string-2", stream.current());
|
||||||
|
}
|
||||||
|
|
||||||
|
var brackets = "([{}])";
|
||||||
|
// This is a crude lookahead trick to try and notice that we're
|
||||||
|
// parsing the argument patterns for a fat-arrow function before we
|
||||||
|
// actually hit the arrow token. It only works if the arrow is on
|
||||||
|
// the same line as the arguments and there's no strange noise
|
||||||
|
// (comments) in between. Fallback is to only notice when we hit the
|
||||||
|
// arrow, and not declare the arguments as locals for the arrow
|
||||||
|
// body.
|
||||||
|
function findFatArrow(stream, state) {
|
||||||
|
if (state.fatArrowAt) state.fatArrowAt = null;
|
||||||
|
var arrow = stream.string.indexOf("=>", stream.start);
|
||||||
|
if (arrow < 0) return;
|
||||||
|
|
||||||
|
if (isTS) { // Try to skip TypeScript return type declarations after the arguments
|
||||||
|
var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
|
||||||
|
if (m) arrow = m.index
|
||||||
|
}
|
||||||
|
|
||||||
|
var depth = 0, sawSomething = false;
|
||||||
|
for (var pos = arrow - 1; pos >= 0; --pos) {
|
||||||
|
var ch = stream.string.charAt(pos);
|
||||||
|
var bracket = brackets.indexOf(ch);
|
||||||
|
if (bracket >= 0 && bracket < 3) {
|
||||||
|
if (!depth) { ++pos; break; }
|
||||||
|
if (--depth == 0) { if (ch == "(") sawSomething = true; break; }
|
||||||
|
} else if (bracket >= 3 && bracket < 6) {
|
||||||
|
++depth;
|
||||||
|
} else if (wordRE.test(ch)) {
|
||||||
|
sawSomething = true;
|
||||||
|
} else if (/["'\/`]/.test(ch)) {
|
||||||
|
for (;; --pos) {
|
||||||
|
if (pos == 0) return
|
||||||
|
var next = stream.string.charAt(pos - 1)
|
||||||
|
if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break }
|
||||||
|
}
|
||||||
|
} else if (sawSomething && !depth) {
|
||||||
|
++pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sawSomething && !depth) state.fatArrowAt = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parser
|
||||||
|
|
||||||
|
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true,
|
||||||
|
"regexp": true, "this": true, "import": true, "jsonld-keyword": true};
|
||||||
|
|
||||||
|
function JSLexical(indented, column, type, align, prev, info) {
|
||||||
|
this.indented = indented;
|
||||||
|
this.column = column;
|
||||||
|
this.type = type;
|
||||||
|
this.prev = prev;
|
||||||
|
this.info = info;
|
||||||
|
if (align != null) this.align = align;
|
||||||
|
}
|
||||||
|
|
||||||
|
function inScope(state, varname) {
|
||||||
|
if (!trackScope) return false
|
||||||
|
for (var v = state.localVars; v; v = v.next)
|
||||||
|
if (v.name == varname) return true;
|
||||||
|
for (var cx = state.context; cx; cx = cx.prev) {
|
||||||
|
for (var v = cx.vars; v; v = v.next)
|
||||||
|
if (v.name == varname) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJS(state, style, type, content, stream) {
|
||||||
|
var cc = state.cc;
|
||||||
|
// Communicate our context to the combinators.
|
||||||
|
// (Less wasteful than consing up a hundred closures on every call.)
|
||||||
|
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
|
||||||
|
|
||||||
|
if (!state.lexical.hasOwnProperty("align"))
|
||||||
|
state.lexical.align = true;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
||||||
|
if (combinator(type, content)) {
|
||||||
|
while(cc.length && cc[cc.length - 1].lex)
|
||||||
|
cc.pop()();
|
||||||
|
if (cx.marked) return cx.marked;
|
||||||
|
if (type == "variable" && inScope(state, content)) return "variable-2";
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combinator utils
|
||||||
|
|
||||||
|
var cx = {state: null, column: null, marked: null, cc: null};
|
||||||
|
function pass() {
|
||||||
|
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
||||||
|
}
|
||||||
|
function cont() {
|
||||||
|
pass.apply(null, arguments);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function inList(name, list) {
|
||||||
|
for (var v = list; v; v = v.next) if (v.name == name) return true
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function register(varname) {
|
||||||
|
var state = cx.state;
|
||||||
|
cx.marked = "def";
|
||||||
|
if (!trackScope) return
|
||||||
|
if (state.context) {
|
||||||
|
if (state.lexical.info == "var" && state.context && state.context.block) {
|
||||||
|
// FIXME function decls are also not block scoped
|
||||||
|
var newContext = registerVarScoped(varname, state.context)
|
||||||
|
if (newContext != null) {
|
||||||
|
state.context = newContext
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if (!inList(varname, state.localVars)) {
|
||||||
|
state.localVars = new Var(varname, state.localVars)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fall through means this is global
|
||||||
|
if (parserConfig.globalVars && !inList(varname, state.globalVars))
|
||||||
|
state.globalVars = new Var(varname, state.globalVars)
|
||||||
|
}
|
||||||
|
function registerVarScoped(varname, context) {
|
||||||
|
if (!context) {
|
||||||
|
return null
|
||||||
|
} else if (context.block) {
|
||||||
|
var inner = registerVarScoped(varname, context.prev)
|
||||||
|
if (!inner) return null
|
||||||
|
if (inner == context.prev) return context
|
||||||
|
return new Context(inner, context.vars, true)
|
||||||
|
} else if (inList(varname, context.vars)) {
|
||||||
|
return context
|
||||||
|
} else {
|
||||||
|
return new Context(context.prev, new Var(varname, context.vars), false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isModifier(name) {
|
||||||
|
return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combinators
|
||||||
|
|
||||||
|
function Context(prev, vars, block) { this.prev = prev; this.vars = vars; this.block = block }
|
||||||
|
function Var(name, next) { this.name = name; this.next = next }
|
||||||
|
|
||||||
|
var defaultVars = new Var("this", new Var("arguments", null))
|
||||||
|
function pushcontext() {
|
||||||
|
cx.state.context = new Context(cx.state.context, cx.state.localVars, false)
|
||||||
|
cx.state.localVars = defaultVars
|
||||||
|
}
|
||||||
|
function pushblockcontext() {
|
||||||
|
cx.state.context = new Context(cx.state.context, cx.state.localVars, true)
|
||||||
|
cx.state.localVars = null
|
||||||
|
}
|
||||||
|
function popcontext() {
|
||||||
|
cx.state.localVars = cx.state.context.vars
|
||||||
|
cx.state.context = cx.state.context.prev
|
||||||
|
}
|
||||||
|
popcontext.lex = true
|
||||||
|
function pushlex(type, info) {
|
||||||
|
var result = function() {
|
||||||
|
var state = cx.state, indent = state.indented;
|
||||||
|
if (state.lexical.type == "stat") indent = state.lexical.indented;
|
||||||
|
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
|
||||||
|
indent = outer.indented;
|
||||||
|
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
|
||||||
|
};
|
||||||
|
result.lex = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function poplex() {
|
||||||
|
var state = cx.state;
|
||||||
|
if (state.lexical.prev) {
|
||||||
|
if (state.lexical.type == ")")
|
||||||
|
state.indented = state.lexical.indented;
|
||||||
|
state.lexical = state.lexical.prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
poplex.lex = true;
|
||||||
|
|
||||||
|
function expect(wanted) {
|
||||||
|
function exp(type) {
|
||||||
|
if (type == wanted) return cont();
|
||||||
|
else if (wanted == ";" || type == "}" || type == ")" || type == "]") return pass();
|
||||||
|
else return cont(exp);
|
||||||
|
};
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function statement(type, value) {
|
||||||
|
if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex);
|
||||||
|
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
|
||||||
|
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
||||||
|
if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
|
||||||
|
if (type == "debugger") return cont(expect(";"));
|
||||||
|
if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext);
|
||||||
|
if (type == ";") return cont();
|
||||||
|
if (type == "if") {
|
||||||
|
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
||||||
|
cx.state.cc.pop()();
|
||||||
|
return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
|
||||||
|
}
|
||||||
|
if (type == "function") return cont(functiondef);
|
||||||
|
if (type == "for") return cont(pushlex("form"), pushblockcontext, forspec, statement, popcontext, poplex);
|
||||||
|
if (type == "class" || (isTS && value == "interface")) {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(pushlex("form", type == "class" ? type : value), className, poplex)
|
||||||
|
}
|
||||||
|
if (type == "variable") {
|
||||||
|
if (isTS && value == "declare") {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(statement)
|
||||||
|
} else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
if (value == "enum") return cont(enumdef);
|
||||||
|
else if (value == "type") return cont(typename, expect("operator"), typeexpr, expect(";"));
|
||||||
|
else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
|
||||||
|
} else if (isTS && value == "namespace") {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(pushlex("form"), expression, statement, poplex)
|
||||||
|
} else if (isTS && value == "abstract") {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(statement)
|
||||||
|
} else {
|
||||||
|
return cont(pushlex("stat"), maybelabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext,
|
||||||
|
block, poplex, poplex, popcontext);
|
||||||
|
if (type == "case") return cont(expression, expect(":"));
|
||||||
|
if (type == "default") return cont(expect(":"));
|
||||||
|
if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext);
|
||||||
|
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
|
||||||
|
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
|
||||||
|
if (type == "async") return cont(statement)
|
||||||
|
if (value == "@") return cont(expression, statement)
|
||||||
|
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
||||||
|
}
|
||||||
|
function maybeCatchBinding(type) {
|
||||||
|
if (type == "(") return cont(funarg, expect(")"))
|
||||||
|
}
|
||||||
|
function expression(type, value) {
|
||||||
|
return expressionInner(type, value, false);
|
||||||
|
}
|
||||||
|
function expressionNoComma(type, value) {
|
||||||
|
return expressionInner(type, value, true);
|
||||||
|
}
|
||||||
|
function parenExpr(type) {
|
||||||
|
if (type != "(") return pass()
|
||||||
|
return cont(pushlex(")"), maybeexpression, expect(")"), poplex)
|
||||||
|
}
|
||||||
|
function expressionInner(type, value, noComma) {
|
||||||
|
if (cx.state.fatArrowAt == cx.stream.start) {
|
||||||
|
var body = noComma ? arrowBodyNoComma : arrowBody;
|
||||||
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
|
||||||
|
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
||||||
|
}
|
||||||
|
|
||||||
|
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
||||||
|
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
||||||
|
if (type == "function") return cont(functiondef, maybeop);
|
||||||
|
if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); }
|
||||||
|
if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
|
||||||
|
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
|
||||||
|
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
||||||
|
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
||||||
|
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
||||||
|
if (type == "quasi") return pass(quasi, maybeop);
|
||||||
|
if (type == "new") return cont(maybeTarget(noComma));
|
||||||
|
return cont();
|
||||||
|
}
|
||||||
|
function maybeexpression(type) {
|
||||||
|
if (type.match(/[;\}\)\],]/)) return pass();
|
||||||
|
return pass(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybeoperatorComma(type, value) {
|
||||||
|
if (type == ",") return cont(maybeexpression);
|
||||||
|
return maybeoperatorNoComma(type, value, false);
|
||||||
|
}
|
||||||
|
function maybeoperatorNoComma(type, value, noComma) {
|
||||||
|
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
|
||||||
|
var expr = noComma == false ? expression : expressionNoComma;
|
||||||
|
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
||||||
|
if (type == "operator") {
|
||||||
|
if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
|
||||||
|
if (isTS && value == "<" && cx.stream.match(/^([^<>]|<[^<>]*>)*>\s*\(/, false))
|
||||||
|
return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me);
|
||||||
|
if (value == "?") return cont(expression, expect(":"), expr);
|
||||||
|
return cont(expr);
|
||||||
|
}
|
||||||
|
if (type == "quasi") { return pass(quasi, me); }
|
||||||
|
if (type == ";") return;
|
||||||
|
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
||||||
|
if (type == ".") return cont(property, me);
|
||||||
|
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
||||||
|
if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
|
||||||
|
if (type == "regexp") {
|
||||||
|
cx.state.lastType = cx.marked = "operator"
|
||||||
|
cx.stream.backUp(cx.stream.pos - cx.stream.start - 1)
|
||||||
|
return cont(expr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function quasi(type, value) {
|
||||||
|
if (type != "quasi") return pass();
|
||||||
|
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
||||||
|
return cont(maybeexpression, continueQuasi);
|
||||||
|
}
|
||||||
|
function continueQuasi(type) {
|
||||||
|
if (type == "}") {
|
||||||
|
cx.marked = "string-2";
|
||||||
|
cx.state.tokenize = tokenQuasi;
|
||||||
|
return cont(quasi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function arrowBody(type) {
|
||||||
|
findFatArrow(cx.stream, cx.state);
|
||||||
|
return pass(type == "{" ? statement : expression);
|
||||||
|
}
|
||||||
|
function arrowBodyNoComma(type) {
|
||||||
|
findFatArrow(cx.stream, cx.state);
|
||||||
|
return pass(type == "{" ? statement : expressionNoComma);
|
||||||
|
}
|
||||||
|
function maybeTarget(noComma) {
|
||||||
|
return function(type) {
|
||||||
|
if (type == ".") return cont(noComma ? targetNoComma : target);
|
||||||
|
else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
|
||||||
|
else return pass(noComma ? expressionNoComma : expression);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function target(_, value) {
|
||||||
|
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
|
||||||
|
}
|
||||||
|
function targetNoComma(_, value) {
|
||||||
|
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
|
||||||
|
}
|
||||||
|
function maybelabel(type) {
|
||||||
|
if (type == ":") return cont(poplex, statement);
|
||||||
|
return pass(maybeoperatorComma, expect(";"), poplex);
|
||||||
|
}
|
||||||
|
function property(type) {
|
||||||
|
if (type == "variable") {cx.marked = "property"; return cont();}
|
||||||
|
}
|
||||||
|
function objprop(type, value) {
|
||||||
|
if (type == "async") {
|
||||||
|
cx.marked = "property";
|
||||||
|
return cont(objprop);
|
||||||
|
} else if (type == "variable" || cx.style == "keyword") {
|
||||||
|
cx.marked = "property";
|
||||||
|
if (value == "get" || value == "set") return cont(getterSetter);
|
||||||
|
var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params
|
||||||
|
if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false)))
|
||||||
|
cx.state.fatArrowAt = cx.stream.pos + m[0].length
|
||||||
|
return cont(afterprop);
|
||||||
|
} else if (type == "number" || type == "string") {
|
||||||
|
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
||||||
|
return cont(afterprop);
|
||||||
|
} else if (type == "jsonld-keyword") {
|
||||||
|
return cont(afterprop);
|
||||||
|
} else if (isTS && isModifier(value)) {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(objprop)
|
||||||
|
} else if (type == "[") {
|
||||||
|
return cont(expression, maybetype, expect("]"), afterprop);
|
||||||
|
} else if (type == "spread") {
|
||||||
|
return cont(expressionNoComma, afterprop);
|
||||||
|
} else if (value == "*") {
|
||||||
|
cx.marked = "keyword";
|
||||||
|
return cont(objprop);
|
||||||
|
} else if (type == ":") {
|
||||||
|
return pass(afterprop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getterSetter(type) {
|
||||||
|
if (type != "variable") return pass(afterprop);
|
||||||
|
cx.marked = "property";
|
||||||
|
return cont(functiondef);
|
||||||
|
}
|
||||||
|
function afterprop(type) {
|
||||||
|
if (type == ":") return cont(expressionNoComma);
|
||||||
|
if (type == "(") return pass(functiondef);
|
||||||
|
}
|
||||||
|
function commasep(what, end, sep) {
|
||||||
|
function proceed(type, value) {
|
||||||
|
if (sep ? sep.indexOf(type) > -1 : type == ",") {
|
||||||
|
var lex = cx.state.lexical;
|
||||||
|
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
||||||
|
return cont(function(type, value) {
|
||||||
|
if (type == end || value == end) return pass()
|
||||||
|
return pass(what)
|
||||||
|
}, proceed);
|
||||||
|
}
|
||||||
|
if (type == end || value == end) return cont();
|
||||||
|
if (sep && sep.indexOf(";") > -1) return pass(what)
|
||||||
|
return cont(expect(end));
|
||||||
|
}
|
||||||
|
return function(type, value) {
|
||||||
|
if (type == end || value == end) return cont();
|
||||||
|
return pass(what, proceed);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function contCommasep(what, end, info) {
|
||||||
|
for (var i = 3; i < arguments.length; i++)
|
||||||
|
cx.cc.push(arguments[i]);
|
||||||
|
return cont(pushlex(end, info), commasep(what, end), poplex);
|
||||||
|
}
|
||||||
|
function block(type) {
|
||||||
|
if (type == "}") return cont();
|
||||||
|
return pass(statement, block);
|
||||||
|
}
|
||||||
|
function maybetype(type, value) {
|
||||||
|
if (isTS) {
|
||||||
|
if (type == ":") return cont(typeexpr);
|
||||||
|
if (value == "?") return cont(maybetype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function maybetypeOrIn(type, value) {
|
||||||
|
if (isTS && (type == ":" || value == "in")) return cont(typeexpr)
|
||||||
|
}
|
||||||
|
function mayberettype(type) {
|
||||||
|
if (isTS && type == ":") {
|
||||||
|
if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr)
|
||||||
|
else return cont(typeexpr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function isKW(_, value) {
|
||||||
|
if (value == "is") {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function typeexpr(type, value) {
|
||||||
|
if (value == "keyof" || value == "typeof" || value == "infer" || value == "readonly") {
|
||||||
|
cx.marked = "keyword"
|
||||||
|
return cont(value == "typeof" ? expressionNoComma : typeexpr)
|
||||||
|
}
|
||||||
|
if (type == "variable" || value == "void") {
|
||||||
|
cx.marked = "type"
|
||||||
|
return cont(afterType)
|
||||||
|
}
|
||||||
|
if (value == "|" || value == "&") return cont(typeexpr)
|
||||||
|
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
|
||||||
|
if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
|
||||||
|
if (type == "{") return cont(pushlex("}"), typeprops, poplex, afterType)
|
||||||
|
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType, afterType)
|
||||||
|
if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr)
|
||||||
|
if (type == "quasi") { return pass(quasiType, afterType); }
|
||||||
|
}
|
||||||
|
function maybeReturnType(type) {
|
||||||
|
if (type == "=>") return cont(typeexpr)
|
||||||
|
}
|
||||||
|
function typeprops(type) {
|
||||||
|
if (type.match(/[\}\)\]]/)) return cont()
|
||||||
|
if (type == "," || type == ";") return cont(typeprops)
|
||||||
|
return pass(typeprop, typeprops)
|
||||||
|
}
|
||||||
|
function typeprop(type, value) {
|
||||||
|
if (type == "variable" || cx.style == "keyword") {
|
||||||
|
cx.marked = "property"
|
||||||
|
return cont(typeprop)
|
||||||
|
} else if (value == "?" || type == "number" || type == "string") {
|
||||||
|
return cont(typeprop)
|
||||||
|
} else if (type == ":") {
|
||||||
|
return cont(typeexpr)
|
||||||
|
} else if (type == "[") {
|
||||||
|
return cont(expect("variable"), maybetypeOrIn, expect("]"), typeprop)
|
||||||
|
} else if (type == "(") {
|
||||||
|
return pass(functiondecl, typeprop)
|
||||||
|
} else if (!type.match(/[;\}\)\],]/)) {
|
||||||
|
return cont()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function quasiType(type, value) {
|
||||||
|
if (type != "quasi") return pass();
|
||||||
|
if (value.slice(value.length - 2) != "${") return cont(quasiType);
|
||||||
|
return cont(typeexpr, continueQuasiType);
|
||||||
|
}
|
||||||
|
function continueQuasiType(type) {
|
||||||
|
if (type == "}") {
|
||||||
|
cx.marked = "string-2";
|
||||||
|
cx.state.tokenize = tokenQuasi;
|
||||||
|
return cont(quasiType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function typearg(type, value) {
|
||||||
|
if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg)
|
||||||
|
if (type == ":") return cont(typeexpr)
|
||||||
|
if (type == "spread") return cont(typearg)
|
||||||
|
return pass(typeexpr)
|
||||||
|
}
|
||||||
|
function afterType(type, value) {
|
||||||
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
||||||
|
if (value == "|" || type == "." || value == "&") return cont(typeexpr)
|
||||||
|
if (type == "[") return cont(typeexpr, expect("]"), afterType)
|
||||||
|
if (value == "extends" || value == "implements") { cx.marked = "keyword"; return cont(typeexpr) }
|
||||||
|
if (value == "?") return cont(typeexpr, expect(":"), typeexpr)
|
||||||
|
}
|
||||||
|
function maybeTypeArgs(_, value) {
|
||||||
|
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
|
||||||
|
}
|
||||||
|
function typeparam() {
|
||||||
|
return pass(typeexpr, maybeTypeDefault)
|
||||||
|
}
|
||||||
|
function maybeTypeDefault(_, value) {
|
||||||
|
if (value == "=") return cont(typeexpr)
|
||||||
|
}
|
||||||
|
function vardef(_, value) {
|
||||||
|
if (value == "enum") {cx.marked = "keyword"; return cont(enumdef)}
|
||||||
|
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
||||||
|
}
|
||||||
|
function pattern(type, value) {
|
||||||
|
if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(pattern) }
|
||||||
|
if (type == "variable") { register(value); return cont(); }
|
||||||
|
if (type == "spread") return cont(pattern);
|
||||||
|
if (type == "[") return contCommasep(eltpattern, "]");
|
||||||
|
if (type == "{") return contCommasep(proppattern, "}");
|
||||||
|
}
|
||||||
|
function proppattern(type, value) {
|
||||||
|
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
|
||||||
|
register(value);
|
||||||
|
return cont(maybeAssign);
|
||||||
|
}
|
||||||
|
if (type == "variable") cx.marked = "property";
|
||||||
|
if (type == "spread") return cont(pattern);
|
||||||
|
if (type == "}") return pass();
|
||||||
|
if (type == "[") return cont(expression, expect(']'), expect(':'), proppattern);
|
||||||
|
return cont(expect(":"), pattern, maybeAssign);
|
||||||
|
}
|
||||||
|
function eltpattern() {
|
||||||
|
return pass(pattern, maybeAssign)
|
||||||
|
}
|
||||||
|
function maybeAssign(_type, value) {
|
||||||
|
if (value == "=") return cont(expressionNoComma);
|
||||||
|
}
|
||||||
|
function vardefCont(type) {
|
||||||
|
if (type == ",") return cont(vardef);
|
||||||
|
}
|
||||||
|
function maybeelse(type, value) {
|
||||||
|
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
||||||
|
}
|
||||||
|
function forspec(type, value) {
|
||||||
|
if (value == "await") return cont(forspec);
|
||||||
|
if (type == "(") return cont(pushlex(")"), forspec1, poplex);
|
||||||
|
}
|
||||||
|
function forspec1(type) {
|
||||||
|
if (type == "var") return cont(vardef, forspec2);
|
||||||
|
if (type == "variable") return cont(forspec2);
|
||||||
|
return pass(forspec2)
|
||||||
|
}
|
||||||
|
function forspec2(type, value) {
|
||||||
|
if (type == ")") return cont()
|
||||||
|
if (type == ";") return cont(forspec2)
|
||||||
|
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression, forspec2) }
|
||||||
|
return pass(expression, forspec2)
|
||||||
|
}
|
||||||
|
function functiondef(type, value) {
|
||||||
|
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
||||||
|
if (type == "variable") {register(value); return cont(functiondef);}
|
||||||
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext);
|
||||||
|
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef)
|
||||||
|
}
|
||||||
|
function functiondecl(type, value) {
|
||||||
|
if (value == "*") {cx.marked = "keyword"; return cont(functiondecl);}
|
||||||
|
if (type == "variable") {register(value); return cont(functiondecl);}
|
||||||
|
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, popcontext);
|
||||||
|
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondecl)
|
||||||
|
}
|
||||||
|
function typename(type, value) {
|
||||||
|
if (type == "keyword" || type == "variable") {
|
||||||
|
cx.marked = "type"
|
||||||
|
return cont(typename)
|
||||||
|
} else if (value == "<") {
|
||||||
|
return cont(pushlex(">"), commasep(typeparam, ">"), poplex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function funarg(type, value) {
|
||||||
|
if (value == "@") cont(expression, funarg)
|
||||||
|
if (type == "spread") return cont(funarg);
|
||||||
|
if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); }
|
||||||
|
if (isTS && type == "this") return cont(maybetype, maybeAssign)
|
||||||
|
return pass(pattern, maybetype, maybeAssign);
|
||||||
|
}
|
||||||
|
function classExpression(type, value) {
|
||||||
|
// Class expressions may have an optional name.
|
||||||
|
if (type == "variable") return className(type, value);
|
||||||
|
return classNameAfter(type, value);
|
||||||
|
}
|
||||||
|
function className(type, value) {
|
||||||
|
if (type == "variable") {register(value); return cont(classNameAfter);}
|
||||||
|
}
|
||||||
|
function classNameAfter(type, value) {
|
||||||
|
if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter)
|
||||||
|
if (value == "extends" || value == "implements" || (isTS && type == ",")) {
|
||||||
|
if (value == "implements") cx.marked = "keyword";
|
||||||
|
return cont(isTS ? typeexpr : expression, classNameAfter);
|
||||||
|
}
|
||||||
|
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
||||||
|
}
|
||||||
|
function classBody(type, value) {
|
||||||
|
if (type == "async" ||
|
||||||
|
(type == "variable" &&
|
||||||
|
(value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) &&
|
||||||
|
cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
|
||||||
|
cx.marked = "keyword";
|
||||||
|
return cont(classBody);
|
||||||
|
}
|
||||||
|
if (type == "variable" || cx.style == "keyword") {
|
||||||
|
cx.marked = "property";
|
||||||
|
return cont(classfield, classBody);
|
||||||
|
}
|
||||||
|
if (type == "number" || type == "string") return cont(classfield, classBody);
|
||||||
|
if (type == "[")
|
||||||
|
return cont(expression, maybetype, expect("]"), classfield, classBody)
|
||||||
|
if (value == "*") {
|
||||||
|
cx.marked = "keyword";
|
||||||
|
return cont(classBody);
|
||||||
|
}
|
||||||
|
if (isTS && type == "(") return pass(functiondecl, classBody)
|
||||||
|
if (type == ";" || type == ",") return cont(classBody);
|
||||||
|
if (type == "}") return cont();
|
||||||
|
if (value == "@") return cont(expression, classBody)
|
||||||
|
}
|
||||||
|
function classfield(type, value) {
|
||||||
|
if (value == "!") return cont(classfield)
|
||||||
|
if (value == "?") return cont(classfield)
|
||||||
|
if (type == ":") return cont(typeexpr, maybeAssign)
|
||||||
|
if (value == "=") return cont(expressionNoComma)
|
||||||
|
var context = cx.state.lexical.prev, isInterface = context && context.info == "interface"
|
||||||
|
return pass(isInterface ? functiondecl : functiondef)
|
||||||
|
}
|
||||||
|
function afterExport(type, value) {
|
||||||
|
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
||||||
|
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
||||||
|
if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
|
||||||
|
return pass(statement);
|
||||||
|
}
|
||||||
|
function exportField(type, value) {
|
||||||
|
if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
|
||||||
|
if (type == "variable") return pass(expressionNoComma, exportField);
|
||||||
|
}
|
||||||
|
function afterImport(type) {
|
||||||
|
if (type == "string") return cont();
|
||||||
|
if (type == "(") return pass(expression);
|
||||||
|
if (type == ".") return pass(maybeoperatorComma);
|
||||||
|
return pass(importSpec, maybeMoreImports, maybeFrom);
|
||||||
|
}
|
||||||
|
function importSpec(type, value) {
|
||||||
|
if (type == "{") return contCommasep(importSpec, "}");
|
||||||
|
if (type == "variable") register(value);
|
||||||
|
if (value == "*") cx.marked = "keyword";
|
||||||
|
return cont(maybeAs);
|
||||||
|
}
|
||||||
|
function maybeMoreImports(type) {
|
||||||
|
if (type == ",") return cont(importSpec, maybeMoreImports)
|
||||||
|
}
|
||||||
|
function maybeAs(_type, value) {
|
||||||
|
if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
|
||||||
|
}
|
||||||
|
function maybeFrom(_type, value) {
|
||||||
|
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
|
||||||
|
}
|
||||||
|
function arrayLiteral(type) {
|
||||||
|
if (type == "]") return cont();
|
||||||
|
return pass(commasep(expressionNoComma, "]"));
|
||||||
|
}
|
||||||
|
function enumdef() {
|
||||||
|
return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex)
|
||||||
|
}
|
||||||
|
function enummember() {
|
||||||
|
return pass(pattern, maybeAssign);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isContinuedStatement(state, textAfter) {
|
||||||
|
return state.lastType == "operator" || state.lastType == "," ||
|
||||||
|
isOperatorChar.test(textAfter.charAt(0)) ||
|
||||||
|
/[,.]/.test(textAfter.charAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
function expressionAllowed(stream, state, backUp) {
|
||||||
|
return state.tokenize == tokenBase &&
|
||||||
|
/^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
|
||||||
|
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface
|
||||||
|
|
||||||
|
return {
|
||||||
|
startState: function(basecolumn) {
|
||||||
|
var state = {
|
||||||
|
tokenize: tokenBase,
|
||||||
|
lastType: "sof",
|
||||||
|
cc: [],
|
||||||
|
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
||||||
|
localVars: parserConfig.localVars,
|
||||||
|
context: parserConfig.localVars && new Context(null, null, false),
|
||||||
|
indented: basecolumn || 0
|
||||||
|
};
|
||||||
|
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
||||||
|
state.globalVars = parserConfig.globalVars;
|
||||||
|
return state;
|
||||||
|
},
|
||||||
|
|
||||||
|
token: function(stream, state) {
|
||||||
|
if (stream.sol()) {
|
||||||
|
if (!state.lexical.hasOwnProperty("align"))
|
||||||
|
state.lexical.align = false;
|
||||||
|
state.indented = stream.indentation();
|
||||||
|
findFatArrow(stream, state);
|
||||||
|
}
|
||||||
|
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
|
||||||
|
var style = state.tokenize(stream, state);
|
||||||
|
if (type == "comment") return style;
|
||||||
|
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
|
||||||
|
return parseJS(state, style, type, content, stream);
|
||||||
|
},
|
||||||
|
|
||||||
|
indent: function(state, textAfter) {
|
||||||
|
if (state.tokenize == tokenComment || state.tokenize == tokenQuasi) return CodeMirror.Pass;
|
||||||
|
if (state.tokenize != tokenBase) return 0;
|
||||||
|
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top
|
||||||
|
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
||||||
|
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
||||||
|
var c = state.cc[i];
|
||||||
|
if (c == poplex) lexical = lexical.prev;
|
||||||
|
else if (c != maybeelse && c != popcontext) break;
|
||||||
|
}
|
||||||
|
while ((lexical.type == "stat" || lexical.type == "form") &&
|
||||||
|
(firstChar == "}" || ((top = state.cc[state.cc.length - 1]) &&
|
||||||
|
(top == maybeoperatorComma || top == maybeoperatorNoComma) &&
|
||||||
|
!/^[,\.=+\-*:?[\(]/.test(textAfter))))
|
||||||
|
lexical = lexical.prev;
|
||||||
|
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
|
||||||
|
lexical = lexical.prev;
|
||||||
|
var type = lexical.type, closing = firstChar == type;
|
||||||
|
|
||||||
|
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info.length + 1 : 0);
|
||||||
|
else if (type == "form" && firstChar == "{") return lexical.indented;
|
||||||
|
else if (type == "form") return lexical.indented + indentUnit;
|
||||||
|
else if (type == "stat")
|
||||||
|
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
|
||||||
|
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
|
||||||
|
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
||||||
|
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
||||||
|
else return lexical.indented + (closing ? 0 : indentUnit);
|
||||||
|
},
|
||||||
|
|
||||||
|
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
||||||
|
blockCommentStart: jsonMode ? null : "/*",
|
||||||
|
blockCommentEnd: jsonMode ? null : "*/",
|
||||||
|
blockCommentContinue: jsonMode ? null : " * ",
|
||||||
|
lineComment: jsonMode ? null : "//",
|
||||||
|
fold: "brace",
|
||||||
|
closeBrackets: "()[]{}''\"\"``",
|
||||||
|
|
||||||
|
helperType: jsonMode ? "json" : "javascript",
|
||||||
|
jsonldMode: jsonldMode,
|
||||||
|
jsonMode: jsonMode,
|
||||||
|
|
||||||
|
expressionAllowed: expressionAllowed,
|
||||||
|
|
||||||
|
skipExpression: function(state) {
|
||||||
|
parseJS(state, "atom", "atom", "true", new CodeMirror.StringStream("", 2, null))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/javascript", "javascript");
|
||||||
|
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
||||||
|
CodeMirror.defineMIME("application/javascript", "javascript");
|
||||||
|
CodeMirror.defineMIME("application/x-javascript", "javascript");
|
||||||
|
CodeMirror.defineMIME("application/ecmascript", "javascript");
|
||||||
|
CodeMirror.defineMIME("application/json", { name: "javascript", json: true });
|
||||||
|
CodeMirror.defineMIME("application/x-json", { name: "javascript", json: true });
|
||||||
|
CodeMirror.defineMIME("application/manifest+json", { name: "javascript", json: true })
|
||||||
|
CodeMirror.defineMIME("application/ld+json", { name: "javascript", jsonld: true });
|
||||||
|
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
|
||||||
|
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1,886 @@
|
||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../meta"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror", "../xml/xml", "../meta"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
||||||
|
|
||||||
|
var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
|
||||||
|
var htmlModeMissing = htmlMode.name == "null"
|
||||||
|
|
||||||
|
function getMode(name) {
|
||||||
|
if (CodeMirror.findModeByName) {
|
||||||
|
var found = CodeMirror.findModeByName(name);
|
||||||
|
if (found) name = found.mime || found.mimes[0];
|
||||||
|
}
|
||||||
|
var mode = CodeMirror.getMode(cmCfg, name);
|
||||||
|
return mode.name == "null" ? null : mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should characters that affect highlighting be highlighted separate?
|
||||||
|
// Does not include characters that will be output (such as `1.` and `-` for lists)
|
||||||
|
if (modeCfg.highlightFormatting === undefined)
|
||||||
|
modeCfg.highlightFormatting = false;
|
||||||
|
|
||||||
|
// Maximum number of nested blockquotes. Set to 0 for infinite nesting.
|
||||||
|
// Excess `>` will emit `error` token.
|
||||||
|
if (modeCfg.maxBlockquoteDepth === undefined)
|
||||||
|
modeCfg.maxBlockquoteDepth = 0;
|
||||||
|
|
||||||
|
// Turn on task lists? ("- [ ] " and "- [x] ")
|
||||||
|
if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
|
||||||
|
|
||||||
|
// Turn on strikethrough syntax
|
||||||
|
if (modeCfg.strikethrough === undefined)
|
||||||
|
modeCfg.strikethrough = false;
|
||||||
|
|
||||||
|
if (modeCfg.emoji === undefined)
|
||||||
|
modeCfg.emoji = false;
|
||||||
|
|
||||||
|
if (modeCfg.fencedCodeBlockHighlighting === undefined)
|
||||||
|
modeCfg.fencedCodeBlockHighlighting = true;
|
||||||
|
|
||||||
|
if (modeCfg.fencedCodeBlockDefaultMode === undefined)
|
||||||
|
modeCfg.fencedCodeBlockDefaultMode = 'text/plain';
|
||||||
|
|
||||||
|
if (modeCfg.xml === undefined)
|
||||||
|
modeCfg.xml = true;
|
||||||
|
|
||||||
|
// Allow token types to be overridden by user-provided token types.
|
||||||
|
if (modeCfg.tokenTypeOverrides === undefined)
|
||||||
|
modeCfg.tokenTypeOverrides = {};
|
||||||
|
|
||||||
|
var tokenTypes = {
|
||||||
|
header: "header",
|
||||||
|
code: "comment",
|
||||||
|
quote: "quote",
|
||||||
|
list1: "variable-2",
|
||||||
|
list2: "variable-3",
|
||||||
|
list3: "keyword",
|
||||||
|
hr: "hr",
|
||||||
|
image: "image",
|
||||||
|
imageAltText: "image-alt-text",
|
||||||
|
imageMarker: "image-marker",
|
||||||
|
formatting: "formatting",
|
||||||
|
linkInline: "link",
|
||||||
|
linkEmail: "link",
|
||||||
|
linkText: "link",
|
||||||
|
linkHref: "string",
|
||||||
|
em: "em",
|
||||||
|
strong: "strong",
|
||||||
|
strikethrough: "strikethrough",
|
||||||
|
emoji: "builtin"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var tokenType in tokenTypes) {
|
||||||
|
if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
|
||||||
|
tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
|
||||||
|
, listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
|
||||||
|
, taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE
|
||||||
|
, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
|
||||||
|
, setextHeaderRE = /^ {0,3}(?:\={1,}|-{2,})\s*$/
|
||||||
|
, textRE = /^[^#!\[\]*_\\<>` "'(~:]+/
|
||||||
|
, fencedCodeRE = /^(~~~+|```+)[ \t]*([\w\/+#-]*)[^\n`]*$/
|
||||||
|
, linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition
|
||||||
|
, punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/
|
||||||
|
, expandedTab = " " // CommonMark specifies tab as 4 spaces
|
||||||
|
|
||||||
|
function switchInline(stream, state, f) {
|
||||||
|
state.f = state.inline = f;
|
||||||
|
return f(stream, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchBlock(stream, state, f) {
|
||||||
|
state.f = state.block = f;
|
||||||
|
return f(stream, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lineIsEmpty(line) {
|
||||||
|
return !line || !/\S/.test(line.string)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blocks
|
||||||
|
|
||||||
|
function blankLine(state) {
|
||||||
|
// Reset linkTitle state
|
||||||
|
state.linkTitle = false;
|
||||||
|
state.linkHref = false;
|
||||||
|
state.linkText = false;
|
||||||
|
// Reset EM state
|
||||||
|
state.em = false;
|
||||||
|
// Reset STRONG state
|
||||||
|
state.strong = false;
|
||||||
|
// Reset strikethrough state
|
||||||
|
state.strikethrough = false;
|
||||||
|
// Reset state.quote
|
||||||
|
state.quote = 0;
|
||||||
|
// Reset state.indentedCode
|
||||||
|
state.indentedCode = false;
|
||||||
|
if (state.f == htmlBlock) {
|
||||||
|
var exit = htmlModeMissing
|
||||||
|
if (!exit) {
|
||||||
|
var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
|
||||||
|
exit = inner.mode.name == "xml" && inner.state.tagStart === null &&
|
||||||
|
(!inner.state.context && inner.state.tokenize.isInText)
|
||||||
|
}
|
||||||
|
if (exit) {
|
||||||
|
state.f = inlineNormal;
|
||||||
|
state.block = blockNormal;
|
||||||
|
state.htmlState = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Reset state.trailingSpace
|
||||||
|
state.trailingSpace = 0;
|
||||||
|
state.trailingSpaceNewLine = false;
|
||||||
|
// Mark this line as blank
|
||||||
|
state.prevLine = state.thisLine
|
||||||
|
state.thisLine = {stream: null}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function blockNormal(stream, state) {
|
||||||
|
var firstTokenOnLine = stream.column() === state.indentation;
|
||||||
|
var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);
|
||||||
|
var prevLineIsIndentedCode = state.indentedCode;
|
||||||
|
var prevLineIsHr = state.prevLine.hr;
|
||||||
|
var prevLineIsList = state.list !== false;
|
||||||
|
var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;
|
||||||
|
|
||||||
|
state.indentedCode = false;
|
||||||
|
|
||||||
|
var lineIndentation = state.indentation;
|
||||||
|
// compute once per line (on first token)
|
||||||
|
if (state.indentationDiff === null) {
|
||||||
|
state.indentationDiff = state.indentation;
|
||||||
|
if (prevLineIsList) {
|
||||||
|
state.list = null;
|
||||||
|
// While this list item's marker's indentation is less than the deepest
|
||||||
|
// list item's content's indentation,pop the deepest list item
|
||||||
|
// indentation off the stack, and update block indentation state
|
||||||
|
while (lineIndentation < state.listStack[state.listStack.length - 1]) {
|
||||||
|
state.listStack.pop();
|
||||||
|
if (state.listStack.length) {
|
||||||
|
state.indentation = state.listStack[state.listStack.length - 1];
|
||||||
|
// less than the first list's indent -> the line is no longer a list
|
||||||
|
} else {
|
||||||
|
state.list = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state.list !== false) {
|
||||||
|
state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// not comprehensive (currently only for setext detection purposes)
|
||||||
|
var allowsInlineContinuation = (
|
||||||
|
!prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&
|
||||||
|
(!prevLineIsList || !prevLineIsIndentedCode) &&
|
||||||
|
!state.prevLine.fencedCodeEnd
|
||||||
|
);
|
||||||
|
|
||||||
|
var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&
|
||||||
|
state.indentation <= maxNonCodeIndentation && stream.match(hrRE);
|
||||||
|
|
||||||
|
var match = null;
|
||||||
|
if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||
|
||||||
|
state.prevLine.header || prevLineLineIsEmpty)) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
state.indentedCode = true;
|
||||||
|
return tokenTypes.code;
|
||||||
|
} else if (stream.eatSpace()) {
|
||||||
|
return null;
|
||||||
|
} else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
|
||||||
|
state.quote = 0;
|
||||||
|
state.header = match[1].length;
|
||||||
|
state.thisLine.header = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
||||||
|
state.f = state.inline;
|
||||||
|
return getType(state);
|
||||||
|
} else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {
|
||||||
|
state.quote = firstTokenOnLine ? 1 : state.quote + 1;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "quote";
|
||||||
|
stream.eatSpace();
|
||||||
|
return getType(state);
|
||||||
|
} else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {
|
||||||
|
var listType = match[1] ? "ol" : "ul";
|
||||||
|
|
||||||
|
state.indentation = lineIndentation + stream.current().length;
|
||||||
|
state.list = true;
|
||||||
|
state.quote = 0;
|
||||||
|
|
||||||
|
// Add this list item's content's indentation to the stack
|
||||||
|
state.listStack.push(state.indentation);
|
||||||
|
// Reset inline styles which shouldn't propagate across list items
|
||||||
|
state.em = false;
|
||||||
|
state.strong = false;
|
||||||
|
state.code = false;
|
||||||
|
state.strikethrough = false;
|
||||||
|
|
||||||
|
if (modeCfg.taskLists && stream.match(taskListRE, false)) {
|
||||||
|
state.taskList = true;
|
||||||
|
}
|
||||||
|
state.f = state.inline;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
|
||||||
|
return getType(state);
|
||||||
|
} else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {
|
||||||
|
state.quote = 0;
|
||||||
|
state.fencedEndRE = new RegExp(match[1] + "+ *$");
|
||||||
|
// try switching mode
|
||||||
|
state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2] || modeCfg.fencedCodeBlockDefaultMode );
|
||||||
|
if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
|
||||||
|
state.f = state.block = local;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
||||||
|
state.code = -1
|
||||||
|
return getType(state);
|
||||||
|
// SETEXT has lowest block-scope precedence after HR, so check it after
|
||||||
|
// the others (code, blockquote, list...)
|
||||||
|
} else if (
|
||||||
|
// if setext set, indicates line after ---/===
|
||||||
|
state.setext || (
|
||||||
|
// line before ---/===
|
||||||
|
(!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&
|
||||||
|
!state.code && !isHr && !linkDefRE.test(stream.string) &&
|
||||||
|
(match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if ( !state.setext ) {
|
||||||
|
state.header = match[0].charAt(0) == '=' ? 1 : 2;
|
||||||
|
state.setext = state.header;
|
||||||
|
} else {
|
||||||
|
state.header = state.setext;
|
||||||
|
// has no effect on type so we can reset it now
|
||||||
|
state.setext = 0;
|
||||||
|
stream.skipToEnd();
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
||||||
|
}
|
||||||
|
state.thisLine.header = true;
|
||||||
|
state.f = state.inline;
|
||||||
|
return getType(state);
|
||||||
|
} else if (isHr) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
state.hr = true;
|
||||||
|
state.thisLine.hr = true;
|
||||||
|
return tokenTypes.hr;
|
||||||
|
} else if (stream.peek() === '[') {
|
||||||
|
return switchInline(stream, state, footnoteLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
return switchInline(stream, state, state.inline);
|
||||||
|
}
|
||||||
|
|
||||||
|
function htmlBlock(stream, state) {
|
||||||
|
var style = htmlMode.token(stream, state.htmlState);
|
||||||
|
if (!htmlModeMissing) {
|
||||||
|
var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
|
||||||
|
if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
|
||||||
|
(!inner.state.context && inner.state.tokenize.isInText)) ||
|
||||||
|
(state.md_inside && stream.current().indexOf(">") > -1)) {
|
||||||
|
state.f = inlineNormal;
|
||||||
|
state.block = blockNormal;
|
||||||
|
state.htmlState = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
function local(stream, state) {
|
||||||
|
var currListInd = state.listStack[state.listStack.length - 1] || 0;
|
||||||
|
var hasExitedList = state.indentation < currListInd;
|
||||||
|
var maxFencedEndInd = currListInd + 3;
|
||||||
|
if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
||||||
|
var returnType;
|
||||||
|
if (!hasExitedList) returnType = getType(state)
|
||||||
|
state.localMode = state.localState = null;
|
||||||
|
state.block = blockNormal;
|
||||||
|
state.f = inlineNormal;
|
||||||
|
state.fencedEndRE = null;
|
||||||
|
state.code = 0
|
||||||
|
state.thisLine.fencedCodeEnd = true;
|
||||||
|
if (hasExitedList) return switchBlock(stream, state, state.block);
|
||||||
|
return returnType;
|
||||||
|
} else if (state.localMode) {
|
||||||
|
return state.localMode.token(stream, state.localState);
|
||||||
|
} else {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return tokenTypes.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inline
|
||||||
|
function getType(state) {
|
||||||
|
var styles = [];
|
||||||
|
|
||||||
|
if (state.formatting) {
|
||||||
|
styles.push(tokenTypes.formatting);
|
||||||
|
|
||||||
|
if (typeof state.formatting === "string") state.formatting = [state.formatting];
|
||||||
|
|
||||||
|
for (var i = 0; i < state.formatting.length; i++) {
|
||||||
|
styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
|
||||||
|
|
||||||
|
if (state.formatting[i] === "header") {
|
||||||
|
styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add `formatting-quote` and `formatting-quote-#` for blockquotes
|
||||||
|
// Add `error` instead if the maximum blockquote nesting depth is passed
|
||||||
|
if (state.formatting[i] === "quote") {
|
||||||
|
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
|
||||||
|
styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
|
||||||
|
} else {
|
||||||
|
styles.push("error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.taskOpen) {
|
||||||
|
styles.push("meta");
|
||||||
|
return styles.length ? styles.join(' ') : null;
|
||||||
|
}
|
||||||
|
if (state.taskClosed) {
|
||||||
|
styles.push("property");
|
||||||
|
return styles.length ? styles.join(' ') : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.linkHref) {
|
||||||
|
styles.push(tokenTypes.linkHref, "url");
|
||||||
|
} else { // Only apply inline styles to non-url text
|
||||||
|
if (state.strong) { styles.push(tokenTypes.strong); }
|
||||||
|
if (state.em) { styles.push(tokenTypes.em); }
|
||||||
|
if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
|
||||||
|
if (state.emoji) { styles.push(tokenTypes.emoji); }
|
||||||
|
if (state.linkText) { styles.push(tokenTypes.linkText); }
|
||||||
|
if (state.code) { styles.push(tokenTypes.code); }
|
||||||
|
if (state.image) { styles.push(tokenTypes.image); }
|
||||||
|
if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
|
||||||
|
if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
|
||||||
|
|
||||||
|
if (state.quote) {
|
||||||
|
styles.push(tokenTypes.quote);
|
||||||
|
|
||||||
|
// Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
|
||||||
|
if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
|
||||||
|
styles.push(tokenTypes.quote + "-" + state.quote);
|
||||||
|
} else {
|
||||||
|
styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.list !== false) {
|
||||||
|
var listMod = (state.listStack.length - 1) % 3;
|
||||||
|
if (!listMod) {
|
||||||
|
styles.push(tokenTypes.list1);
|
||||||
|
} else if (listMod === 1) {
|
||||||
|
styles.push(tokenTypes.list2);
|
||||||
|
} else {
|
||||||
|
styles.push(tokenTypes.list3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.trailingSpaceNewLine) {
|
||||||
|
styles.push("trailing-space-new-line");
|
||||||
|
} else if (state.trailingSpace) {
|
||||||
|
styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles.length ? styles.join(' ') : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleText(stream, state) {
|
||||||
|
if (stream.match(textRE, true)) {
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function inlineNormal(stream, state) {
|
||||||
|
var style = state.text(stream, state);
|
||||||
|
if (typeof style !== 'undefined')
|
||||||
|
return style;
|
||||||
|
|
||||||
|
if (state.list) { // List marker (*, +, -, 1., etc)
|
||||||
|
state.list = null;
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.taskList) {
|
||||||
|
var taskOpen = stream.match(taskListRE, true)[1] === " ";
|
||||||
|
if (taskOpen) state.taskOpen = true;
|
||||||
|
else state.taskClosed = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "task";
|
||||||
|
state.taskList = false;
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
state.taskOpen = false;
|
||||||
|
state.taskClosed = false;
|
||||||
|
|
||||||
|
if (state.header && stream.match(/^#+$/, true)) {
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ch = stream.next();
|
||||||
|
|
||||||
|
// Matches link titles present on next line
|
||||||
|
if (state.linkTitle) {
|
||||||
|
state.linkTitle = false;
|
||||||
|
var matchCh = ch;
|
||||||
|
if (ch === '(') {
|
||||||
|
matchCh = ')';
|
||||||
|
}
|
||||||
|
matchCh = (matchCh+'').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");
|
||||||
|
var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
|
||||||
|
if (stream.match(new RegExp(regex), true)) {
|
||||||
|
return tokenTypes.linkHref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this block is changed, it may need to be updated in GFM mode
|
||||||
|
if (ch === '`') {
|
||||||
|
var previousFormatting = state.formatting;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "code";
|
||||||
|
stream.eatWhile('`');
|
||||||
|
var count = stream.current().length
|
||||||
|
if (state.code == 0 && (!state.quote || count == 1)) {
|
||||||
|
state.code = count
|
||||||
|
return getType(state)
|
||||||
|
} else if (count == state.code) { // Must be exact
|
||||||
|
var t = getType(state)
|
||||||
|
state.code = 0
|
||||||
|
return t
|
||||||
|
} else {
|
||||||
|
state.formatting = previousFormatting
|
||||||
|
return getType(state)
|
||||||
|
}
|
||||||
|
} else if (state.code) {
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '\\') {
|
||||||
|
stream.next();
|
||||||
|
if (modeCfg.highlightFormatting) {
|
||||||
|
var type = getType(state);
|
||||||
|
var formattingEscape = tokenTypes.formatting + "-escape";
|
||||||
|
return type ? type + " " + formattingEscape : formattingEscape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
|
||||||
|
state.imageMarker = true;
|
||||||
|
state.image = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {
|
||||||
|
state.imageMarker = false;
|
||||||
|
state.imageAltText = true
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === ']' && state.imageAltText) {
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
||||||
|
var type = getType(state);
|
||||||
|
state.imageAltText = false;
|
||||||
|
state.image = false;
|
||||||
|
state.inline = state.f = linkHref;
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '[' && !state.image) {
|
||||||
|
if (state.linkText && stream.match(/^.*?\]/)) return getType(state)
|
||||||
|
state.linkText = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === ']' && state.linkText) {
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
var type = getType(state);
|
||||||
|
state.linkText = false;
|
||||||
|
state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
|
||||||
|
state.f = state.inline = linkInline;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
var type = getType(state);
|
||||||
|
if (type){
|
||||||
|
type += " ";
|
||||||
|
} else {
|
||||||
|
type = "";
|
||||||
|
}
|
||||||
|
return type + tokenTypes.linkInline;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
|
||||||
|
state.f = state.inline = linkInline;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
var type = getType(state);
|
||||||
|
if (type){
|
||||||
|
type += " ";
|
||||||
|
} else {
|
||||||
|
type = "";
|
||||||
|
}
|
||||||
|
return type + tokenTypes.linkEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
|
||||||
|
var end = stream.string.indexOf(">", stream.pos);
|
||||||
|
if (end != -1) {
|
||||||
|
var atts = stream.string.substring(stream.start, end);
|
||||||
|
if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
|
||||||
|
}
|
||||||
|
stream.backUp(1);
|
||||||
|
state.htmlState = CodeMirror.startState(htmlMode);
|
||||||
|
return switchBlock(stream, state, htmlBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {
|
||||||
|
state.md_inside = false;
|
||||||
|
return "tag";
|
||||||
|
} else if (ch === "*" || ch === "_") {
|
||||||
|
var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)
|
||||||
|
while (len < 3 && stream.eat(ch)) len++
|
||||||
|
var after = stream.peek() || " "
|
||||||
|
// See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
|
||||||
|
var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))
|
||||||
|
var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))
|
||||||
|
var setEm = null, setStrong = null
|
||||||
|
if (len % 2) { // Em
|
||||||
|
if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
|
||||||
|
setEm = true
|
||||||
|
else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
|
||||||
|
setEm = false
|
||||||
|
}
|
||||||
|
if (len > 1) { // Strong
|
||||||
|
if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
|
||||||
|
setStrong = true
|
||||||
|
else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
|
||||||
|
setStrong = false
|
||||||
|
}
|
||||||
|
if (setStrong != null || setEm != null) {
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"
|
||||||
|
if (setEm === true) state.em = ch
|
||||||
|
if (setStrong === true) state.strong = ch
|
||||||
|
var t = getType(state)
|
||||||
|
if (setEm === false) state.em = false
|
||||||
|
if (setStrong === false) state.strong = false
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
} else if (ch === ' ') {
|
||||||
|
if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
|
||||||
|
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
|
||||||
|
return getType(state);
|
||||||
|
} else { // Not surrounded by spaces, back up pointer
|
||||||
|
stream.backUp(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modeCfg.strikethrough) {
|
||||||
|
if (ch === '~' && stream.eatWhile(ch)) {
|
||||||
|
if (state.strikethrough) {// Remove strikethrough
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
|
||||||
|
var t = getType(state);
|
||||||
|
state.strikethrough = false;
|
||||||
|
return t;
|
||||||
|
} else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
|
||||||
|
state.strikethrough = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
} else if (ch === ' ') {
|
||||||
|
if (stream.match('~~', true)) { // Probably surrounded by space
|
||||||
|
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
|
||||||
|
return getType(state);
|
||||||
|
} else { // Not surrounded by spaces, back up pointer
|
||||||
|
stream.backUp(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {
|
||||||
|
state.emoji = true;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "emoji";
|
||||||
|
var retType = getType(state);
|
||||||
|
state.emoji = false;
|
||||||
|
return retType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch === ' ') {
|
||||||
|
if (stream.match(/^ +$/, false)) {
|
||||||
|
state.trailingSpace++;
|
||||||
|
} else if (state.trailingSpace) {
|
||||||
|
state.trailingSpaceNewLine = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkInline(stream, state) {
|
||||||
|
var ch = stream.next();
|
||||||
|
|
||||||
|
if (ch === ">") {
|
||||||
|
state.f = state.inline = inlineNormal;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
var type = getType(state);
|
||||||
|
if (type){
|
||||||
|
type += " ";
|
||||||
|
} else {
|
||||||
|
type = "";
|
||||||
|
}
|
||||||
|
return type + tokenTypes.linkInline;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.match(/^[^>]+/, true);
|
||||||
|
|
||||||
|
return tokenTypes.linkInline;
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkHref(stream, state) {
|
||||||
|
// Check if space, and return NULL if so (to avoid marking the space)
|
||||||
|
if(stream.eatSpace()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var ch = stream.next();
|
||||||
|
if (ch === '(' || ch === '[') {
|
||||||
|
state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link-string";
|
||||||
|
state.linkHref = true;
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
|
||||||
|
var linkRE = {
|
||||||
|
")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
|
||||||
|
"]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLinkHrefInside(endChar) {
|
||||||
|
return function(stream, state) {
|
||||||
|
var ch = stream.next();
|
||||||
|
|
||||||
|
if (ch === endChar) {
|
||||||
|
state.f = state.inline = inlineNormal;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link-string";
|
||||||
|
var returnState = getType(state);
|
||||||
|
state.linkHref = false;
|
||||||
|
return returnState;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.match(linkRE[endChar])
|
||||||
|
state.linkHref = true;
|
||||||
|
return getType(state);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function footnoteLink(stream, state) {
|
||||||
|
if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
|
||||||
|
state.f = footnoteLinkInside;
|
||||||
|
stream.next(); // Consume [
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
state.linkText = true;
|
||||||
|
return getType(state);
|
||||||
|
}
|
||||||
|
return switchInline(stream, state, inlineNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
function footnoteLinkInside(stream, state) {
|
||||||
|
if (stream.match(']:', true)) {
|
||||||
|
state.f = state.inline = footnoteUrl;
|
||||||
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
||||||
|
var returnType = getType(state);
|
||||||
|
state.linkText = false;
|
||||||
|
return returnType;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.match(/^([^\]\\]|\\.)+/, true);
|
||||||
|
|
||||||
|
return tokenTypes.linkText;
|
||||||
|
}
|
||||||
|
|
||||||
|
function footnoteUrl(stream, state) {
|
||||||
|
// Check if space, and return NULL if so (to avoid marking the space)
|
||||||
|
if(stream.eatSpace()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Match URL
|
||||||
|
stream.match(/^[^\s]+/, true);
|
||||||
|
// Check for link title
|
||||||
|
if (stream.peek() === undefined) { // End of line, set flag to check next line
|
||||||
|
state.linkTitle = true;
|
||||||
|
} else { // More content on line, check if link title
|
||||||
|
stream.match(/^(?:\s+(?:"(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+'|\((?:[^)\\]|\\.)+\)))?/, true);
|
||||||
|
}
|
||||||
|
state.f = state.inline = inlineNormal;
|
||||||
|
return tokenTypes.linkHref + " url";
|
||||||
|
}
|
||||||
|
|
||||||
|
var mode = {
|
||||||
|
startState: function() {
|
||||||
|
return {
|
||||||
|
f: blockNormal,
|
||||||
|
|
||||||
|
prevLine: {stream: null},
|
||||||
|
thisLine: {stream: null},
|
||||||
|
|
||||||
|
block: blockNormal,
|
||||||
|
htmlState: null,
|
||||||
|
indentation: 0,
|
||||||
|
|
||||||
|
inline: inlineNormal,
|
||||||
|
text: handleText,
|
||||||
|
|
||||||
|
formatting: false,
|
||||||
|
linkText: false,
|
||||||
|
linkHref: false,
|
||||||
|
linkTitle: false,
|
||||||
|
code: 0,
|
||||||
|
em: false,
|
||||||
|
strong: false,
|
||||||
|
header: 0,
|
||||||
|
setext: 0,
|
||||||
|
hr: false,
|
||||||
|
taskList: false,
|
||||||
|
list: false,
|
||||||
|
listStack: [],
|
||||||
|
quote: 0,
|
||||||
|
trailingSpace: 0,
|
||||||
|
trailingSpaceNewLine: false,
|
||||||
|
strikethrough: false,
|
||||||
|
emoji: false,
|
||||||
|
fencedEndRE: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
copyState: function(s) {
|
||||||
|
return {
|
||||||
|
f: s.f,
|
||||||
|
|
||||||
|
prevLine: s.prevLine,
|
||||||
|
thisLine: s.thisLine,
|
||||||
|
|
||||||
|
block: s.block,
|
||||||
|
htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
|
||||||
|
indentation: s.indentation,
|
||||||
|
|
||||||
|
localMode: s.localMode,
|
||||||
|
localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
|
||||||
|
|
||||||
|
inline: s.inline,
|
||||||
|
text: s.text,
|
||||||
|
formatting: false,
|
||||||
|
linkText: s.linkText,
|
||||||
|
linkTitle: s.linkTitle,
|
||||||
|
linkHref: s.linkHref,
|
||||||
|
code: s.code,
|
||||||
|
em: s.em,
|
||||||
|
strong: s.strong,
|
||||||
|
strikethrough: s.strikethrough,
|
||||||
|
emoji: s.emoji,
|
||||||
|
header: s.header,
|
||||||
|
setext: s.setext,
|
||||||
|
hr: s.hr,
|
||||||
|
taskList: s.taskList,
|
||||||
|
list: s.list,
|
||||||
|
listStack: s.listStack.slice(0),
|
||||||
|
quote: s.quote,
|
||||||
|
indentedCode: s.indentedCode,
|
||||||
|
trailingSpace: s.trailingSpace,
|
||||||
|
trailingSpaceNewLine: s.trailingSpaceNewLine,
|
||||||
|
md_inside: s.md_inside,
|
||||||
|
fencedEndRE: s.fencedEndRE
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
token: function(stream, state) {
|
||||||
|
|
||||||
|
// Reset state.formatting
|
||||||
|
state.formatting = false;
|
||||||
|
|
||||||
|
if (stream != state.thisLine.stream) {
|
||||||
|
state.header = 0;
|
||||||
|
state.hr = false;
|
||||||
|
|
||||||
|
if (stream.match(/^\s*$/, true)) {
|
||||||
|
blankLine(state);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.prevLine = state.thisLine
|
||||||
|
state.thisLine = {stream: stream}
|
||||||
|
|
||||||
|
// Reset state.taskList
|
||||||
|
state.taskList = false;
|
||||||
|
|
||||||
|
// Reset state.trailingSpace
|
||||||
|
state.trailingSpace = 0;
|
||||||
|
state.trailingSpaceNewLine = false;
|
||||||
|
|
||||||
|
if (!state.localState) {
|
||||||
|
state.f = state.block;
|
||||||
|
if (state.f != htmlBlock) {
|
||||||
|
var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;
|
||||||
|
state.indentation = indentation;
|
||||||
|
state.indentationDiff = null;
|
||||||
|
if (indentation > 0) return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state.f(stream, state);
|
||||||
|
},
|
||||||
|
|
||||||
|
innerMode: function(state) {
|
||||||
|
if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};
|
||||||
|
if (state.localState) return {state: state.localState, mode: state.localMode};
|
||||||
|
return {state: state, mode: mode};
|
||||||
|
},
|
||||||
|
|
||||||
|
indent: function(state, textAfter, line) {
|
||||||
|
if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)
|
||||||
|
if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)
|
||||||
|
return CodeMirror.Pass
|
||||||
|
},
|
||||||
|
|
||||||
|
blankLine: blankLine,
|
||||||
|
|
||||||
|
getType: getType,
|
||||||
|
|
||||||
|
blockCommentStart: "<!--",
|
||||||
|
blockCommentEnd: "-->",
|
||||||
|
closeBrackets: "()[]{}''\"\"``",
|
||||||
|
fold: "markdown"
|
||||||
|
};
|
||||||
|
return mode;
|
||||||
|
}, "xml");
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/markdown", "markdown");
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/x-markdown", "markdown");
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue