@jinntec/fore 1.0.0-4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -38
- package/dist/fore-dev.js +43 -0
- package/dist/fore-dev.js.map +1 -0
- package/dist/fore.js +37 -0
- package/dist/fore.js.map +1 -0
- package/index.js +4 -0
- package/package.json +42 -42
- package/resources/fore.css +186 -0
- package/resources/toastify.css +87 -0
- package/resources/{fore-styles.css → vars.css} +0 -292
- package/src/DependencyNotifyingDomFacade.js +10 -16
- package/src/ForeElementMixin.js +26 -19
- package/src/actions/abstract-action.js +30 -9
- package/src/actions/fx-action.js +6 -4
- package/src/actions/fx-append.js +8 -17
- package/src/actions/fx-confirm.js +5 -3
- package/src/actions/fx-delete.js +6 -3
- package/src/actions/fx-dispatch.js +9 -8
- package/src/actions/fx-hide.js +10 -6
- package/src/actions/fx-insert.js +49 -39
- package/src/actions/fx-message.js +3 -1
- package/src/actions/fx-refresh.js +15 -1
- package/src/actions/fx-replace.js +73 -0
- package/src/actions/fx-return.js +42 -0
- package/src/actions/fx-send.js +3 -1
- package/src/actions/fx-setfocus.js +37 -0
- package/src/actions/fx-setvalue.js +58 -51
- package/src/actions/fx-show.js +12 -4
- package/src/actions/fx-toggle.js +15 -10
- package/src/actions/fx-update.js +3 -1
- package/src/dep_graph.js +4 -2
- package/src/drawdown.js +67 -82
- package/src/fore.js +158 -12
- package/src/functions/fx-function.js +17 -3
- package/src/fx-bind.js +42 -202
- package/src/fx-fore.js +599 -567
- package/src/fx-header.js +3 -1
- package/src/fx-instance.js +9 -1
- package/src/fx-model.js +59 -23
- package/src/fx-submission.js +106 -48
- package/src/fx-var.js +7 -4
- package/src/getInScopeContext.js +37 -11
- package/src/modelitem.js +4 -4
- package/src/relevance.js +64 -0
- package/src/ui/abstract-control.js +64 -37
- package/src/ui/fx-alert.js +7 -1
- package/src/ui/fx-case.js +4 -3
- package/src/ui/fx-container.js +7 -1
- package/src/ui/fx-control.js +309 -34
- package/src/ui/fx-dialog.js +54 -40
- package/src/ui/fx-group.js +3 -1
- package/src/ui/fx-hint.js +4 -1
- package/src/ui/fx-inspector.js +120 -17
- package/src/ui/fx-items.js +8 -8
- package/src/ui/fx-output.js +16 -5
- package/src/ui/fx-repeat.js +33 -41
- package/src/ui/fx-repeatitem.js +10 -4
- package/src/ui/fx-switch.js +5 -3
- package/src/ui/fx-trigger.js +3 -1
- package/src/xpath-evaluation.js +621 -576
- package/src/xpath-util.js +15 -8
- package/dist/fore-all.js +0 -140
- package/dist/fore-debug.js +0 -140
- package/src/.DS_Store +0 -0
- package/src/actions/.DS_Store +0 -0
- package/src/ui/.DS_Store +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// import { FxAction } from './fx-action.js';
|
|
2
|
+
import '../fx-model.js';
|
|
3
|
+
import { AbstractAction } from './abstract-action.js';
|
|
4
|
+
import { evaluateXPathToFirstNode } from '../xpath-evaluation.js';
|
|
5
|
+
import getInScopeContext from "../getInScopeContext";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `fx-replace` - replaces the node referred to with 'ref' with node referred to with 'with' attribute.
|
|
9
|
+
*
|
|
10
|
+
* @customElement
|
|
11
|
+
*/
|
|
12
|
+
export default class FxReplace extends AbstractAction {
|
|
13
|
+
static get properties() {
|
|
14
|
+
return {
|
|
15
|
+
...super.properties,
|
|
16
|
+
with: {
|
|
17
|
+
type: String,
|
|
18
|
+
},
|
|
19
|
+
replaceNode: Object,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.with = '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
if (super.connectedCallback) {
|
|
30
|
+
super.connectedCallback();
|
|
31
|
+
}
|
|
32
|
+
this.with = this.getAttribute('with');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
perform() {
|
|
36
|
+
super.perform();
|
|
37
|
+
console.log('replace action');
|
|
38
|
+
// console.log('replace action variables', this.inScopeVariables);
|
|
39
|
+
// if (!this.nodeset) {
|
|
40
|
+
// return;
|
|
41
|
+
// }
|
|
42
|
+
const target = evaluateXPathToFirstNode(this.with, this.nodeset, this);
|
|
43
|
+
if (!target) return;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
this.replace(this.nodeset, target);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
replace(toReplace, replaceWith) {
|
|
50
|
+
if (!toReplace || !replaceWith) return; // bail out silently
|
|
51
|
+
if (!toReplace.nodeName || !replaceWith.nodeName) {
|
|
52
|
+
console.warn('fx-replace: one argument is not a node');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (toReplace.nodeType === Node.ATTRIBUTE_NODE) {
|
|
57
|
+
const { ownerElement } = toReplace;
|
|
58
|
+
ownerElement.setAttribute(replaceWith.nodeName, replaceWith.textContent);
|
|
59
|
+
ownerElement.removeAttribute(toReplace.nodeName);
|
|
60
|
+
console.log('owner', ownerElement);
|
|
61
|
+
} else if (toReplace.nodeType === Node.ELEMENT_NODE) {
|
|
62
|
+
const cloned = replaceWith.cloneNode(true);
|
|
63
|
+
toReplace.replaceWith(cloned);
|
|
64
|
+
}
|
|
65
|
+
// const modelitem = this.getModelItem();
|
|
66
|
+
// this.getModel().changed.push(modelitem);
|
|
67
|
+
this.needsUpdate = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!customElements.get('fx-replace')) {
|
|
72
|
+
window.customElements.define('fx-replace', FxReplace);
|
|
73
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AbstractAction } from './abstract-action.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `fx-return`
|
|
5
|
+
* returns data from a nested Fore to it's host Fore.
|
|
6
|
+
*
|
|
7
|
+
* behaves like a `<fx-submission @replace='instance' with `targetref` and respects relevance processing.
|
|
8
|
+
*
|
|
9
|
+
* `targetref` will be the `ref` of the host control.
|
|
10
|
+
*
|
|
11
|
+
* todo: deos not relevant selection yet
|
|
12
|
+
*
|
|
13
|
+
* @customElement
|
|
14
|
+
*/
|
|
15
|
+
export class FxReturn extends AbstractAction {
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
if (super.connectedCallback) {
|
|
18
|
+
super.connectedCallback();
|
|
19
|
+
}
|
|
20
|
+
// const nonrelevant = this.hasAttribute('nonrelevant') ? this.getAttribute('nonrelevant') : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
perform() {
|
|
24
|
+
super.perform();
|
|
25
|
+
console.log('performing return with nodes', this.nodeset);
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
### note that this event does not use Fore.dispatch as the event uses 'composed:true' to let the event travel
|
|
29
|
+
up through the shadowRoot and being catched in outer form.
|
|
30
|
+
*/
|
|
31
|
+
const event = new CustomEvent('return', {
|
|
32
|
+
composed: true,
|
|
33
|
+
bubbles: true,
|
|
34
|
+
detail: { nodeset: this.nodeset },
|
|
35
|
+
});
|
|
36
|
+
this.getOwnerForm().dispatchEvent(event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!customElements.get('fx-return')) {
|
|
41
|
+
window.customElements.define('fx-return', FxReturn);
|
|
42
|
+
}
|
package/src/actions/fx-send.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {AbstractAction} from "./abstract-action";
|
|
2
|
+
import {resolveId} from "../xpath-evaluation";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `fx-setfocus`
|
|
6
|
+
* Set the focus to a target control.
|
|
7
|
+
*
|
|
8
|
+
* @customElement
|
|
9
|
+
*/
|
|
10
|
+
export class FxSetfocus extends AbstractAction {
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
super.connectedCallback();
|
|
13
|
+
this.control = this.hasAttribute('control') ? this.getAttribute('control') : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
perform() {
|
|
17
|
+
console.log('setting focus', this.control);
|
|
18
|
+
// super.perform();
|
|
19
|
+
|
|
20
|
+
// const targetElement = resolveId(this.control, this);
|
|
21
|
+
const selector = '#'+this.control;
|
|
22
|
+
let targetElement = document.querySelector(selector);
|
|
23
|
+
const repeatitem = targetElement.closest('fx-repeatitem, .fx-repeatitem');
|
|
24
|
+
if(repeatitem){
|
|
25
|
+
// targetElement is repeated
|
|
26
|
+
// get the active repeatitem (only for fx-repeat for now - todo: support repeat attributes
|
|
27
|
+
const repeat = repeatitem.parentNode;
|
|
28
|
+
targetElement = repeat.querySelector('[repeat-index] ' + selector);
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
targetElement.getWidget().focus();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!customElements.get('fx-setfocus')) {
|
|
36
|
+
window.customElements.define('fx-setfocus', FxSetfocus);
|
|
37
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// import { FxAction } from './fx-action.js';
|
|
2
2
|
import '../fx-model.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {AbstractAction} from './abstract-action.js';
|
|
4
|
+
import {evaluateXPath} from '../xpath-evaluation.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* `fx-setvalue`
|
|
@@ -9,64 +9,71 @@ import { evaluateXPath } from '../xpath-evaluation.js';
|
|
|
9
9
|
* @customElement
|
|
10
10
|
*/
|
|
11
11
|
export default class FxSetvalue extends AbstractAction {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this.ref = '';
|
|
27
|
-
this.valueAttr = '';
|
|
28
|
-
}
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
...super.properties,
|
|
15
|
+
ref: {
|
|
16
|
+
type: String,
|
|
17
|
+
},
|
|
18
|
+
valueAttr: {
|
|
19
|
+
type: String,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.ref = '';
|
|
27
|
+
this.valueAttr = '';
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
if (super.connectedCallback) {
|
|
32
|
+
super.connectedCallback();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.hasAttribute('ref')) {
|
|
36
|
+
this.ref = this.getAttribute('ref');
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error('fx-setvalue must specify a "ref" attribute');
|
|
39
|
+
}
|
|
40
|
+
this.valueAttr = this.getAttribute('value');
|
|
39
41
|
}
|
|
40
|
-
this.valueAttr = this.getAttribute('value');
|
|
41
|
-
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
perform() {
|
|
44
|
+
super.perform();
|
|
45
|
+
let {value} = this;
|
|
46
|
+
if (this.valueAttr !== null) {
|
|
47
|
+
[value] = evaluateXPath(this.valueAttr, this.nodeset, this, this.detail);
|
|
48
|
+
} else if (this.textContent !== '') {
|
|
49
|
+
value = this.textContent;
|
|
50
|
+
} else {
|
|
51
|
+
value = '';
|
|
52
|
+
}
|
|
53
|
+
console.log('value', value);
|
|
54
|
+
if (value.nodeType === Node.ATTRIBUTE_NODE) {
|
|
55
|
+
console.log('value', value.nodeValue);
|
|
56
|
+
value = value.nodeValue;
|
|
57
|
+
}
|
|
58
|
+
const mi = this.getModelItem();
|
|
59
|
+
this.setValue(mi, value);
|
|
52
60
|
}
|
|
53
|
-
const mi = this.getModelItem();
|
|
54
|
-
this.setValue(mi, value);
|
|
55
|
-
}
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
setValue(modelItem, newVal) {
|
|
63
|
+
console.log('setvalue[1] ', modelItem, newVal);
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
const item = modelItem;
|
|
66
|
+
if (!item) return;
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
if (item.value !== newVal) {
|
|
69
|
+
item.value = newVal;
|
|
70
|
+
this.getModel().changed.push(modelItem);
|
|
71
|
+
this.needsUpdate = true;
|
|
72
|
+
console.log('setvalue[2] ', item, newVal);
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
|
-
}
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
if (!customElements.get('fx-setvalue')) {
|
|
78
|
+
window.customElements.define('fx-setvalue', FxSetvalue);
|
|
79
|
+
}
|
package/src/actions/fx-show.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Fore } from '../fore.js';
|
|
1
2
|
import { FxAction } from './fx-action.js';
|
|
3
|
+
import { resolveId } from '../xpath-evaluation.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* `fx-confirm`
|
|
@@ -10,14 +12,20 @@ import { FxAction } from './fx-action.js';
|
|
|
10
12
|
export class FxShow extends FxAction {
|
|
11
13
|
connectedCallback() {
|
|
12
14
|
this.dialog = this.getAttribute('dialog');
|
|
13
|
-
if(!this.dialog){
|
|
14
|
-
|
|
15
|
+
if (!this.dialog) {
|
|
16
|
+
Fore.dispatch(this, 'error', { message: 'dialog does not exist' });
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
perform() {
|
|
19
|
-
|
|
21
|
+
const targetDlg = resolveId(this.dialog,this);
|
|
22
|
+
if(!targetDlg){
|
|
23
|
+
console.error('target dialog with given id does not exist',this.dialog);
|
|
24
|
+
}
|
|
25
|
+
targetDlg.open();
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
if (!customElements.get('fx-show')) {
|
|
30
|
+
window.customElements.define('fx-show', FxShow);
|
|
31
|
+
}
|
package/src/actions/fx-toggle.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractAction } from './abstract-action.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* `fx-toggle`
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
|
-
class FxToggle extends
|
|
7
|
+
class FxToggle extends AbstractAction {
|
|
8
|
+
/*
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.attachShadow({ mode: 'open' });
|
|
12
|
+
}
|
|
13
|
+
*/
|
|
8
14
|
connectedCallback() {
|
|
15
|
+
super.connectedCallback();
|
|
9
16
|
if (this.hasAttribute('case')) {
|
|
10
17
|
this.case = this.getAttribute('case');
|
|
11
18
|
}
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
super.disconnectedCallback();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
execute() {
|
|
21
|
+
perform() {
|
|
22
|
+
super.perform();
|
|
21
23
|
console.log('### fx-toggle.execute ');
|
|
22
24
|
if (this.case) {
|
|
23
25
|
const ownerForm = this.getOwnerForm();
|
|
@@ -25,7 +27,10 @@ class FxToggle extends FxAction {
|
|
|
25
27
|
const fxSwitch = caseElement.parentNode;
|
|
26
28
|
fxSwitch.toggle(caseElement);
|
|
27
29
|
}
|
|
30
|
+
// this.needsUpdate = true;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
if (!customElements.get('fx-toggle')) {
|
|
35
|
+
window.customElements.define('fx-toggle', FxToggle);
|
|
36
|
+
}
|
package/src/actions/fx-update.js
CHANGED
package/src/dep_graph.js
CHANGED
|
@@ -80,7 +80,7 @@ function createDFS(edges, leavesOnly, result, circular) {
|
|
|
80
80
|
currentPath.push(node);
|
|
81
81
|
window.dispatchEvent(
|
|
82
82
|
new CustomEvent('compute-exception', {
|
|
83
|
-
composed:
|
|
83
|
+
composed: false,
|
|
84
84
|
bubbles: true,
|
|
85
85
|
detail: {
|
|
86
86
|
path: currentPath,
|
|
@@ -91,7 +91,9 @@ function createDFS(edges, leavesOnly, result, circular) {
|
|
|
91
91
|
// return;
|
|
92
92
|
// console.log('‘circular path: ' + currentPath);
|
|
93
93
|
// throw new DepGraphCycleError(currentPath);
|
|
94
|
-
|
|
94
|
+
|
|
95
|
+
// Stop all processing. This form is broken and we should not break the browser
|
|
96
|
+
throw new Error(`Cyclic at ${currentPath}`);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
inCurrentPath[node] = true;
|
package/src/drawdown.js
CHANGED
|
@@ -4,72 +4,67 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
function markdown(src) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const rx_lt = /</g;
|
|
8
|
+
const rx_gt = />/g;
|
|
9
|
+
const rx_space = /\t|\r|\uf8ff/g;
|
|
10
|
+
const rx_escape = /\\([\\\|`*_{}\[\]()#+\-~])/g;
|
|
11
|
+
const rx_hr = /^([*\-=_] *){3,}$/gm;
|
|
12
|
+
const rx_blockquote = /\n *> *([^]*?)(?=(\n|$){2})/g;
|
|
13
|
+
const rx_list = /\n( *)(?:[*\-+]|((\d+)|([a-z])|[A-Z])[.)]) +([^]*?)(?=(\n|$){2})/g;
|
|
14
|
+
const rx_listjoin = /<\/(ol|ul)>\n\n<\1>/g;
|
|
15
|
+
const rx_highlight = /(^|[^A-Za-z\d\\])(([*_])|(~)|(\^)|(--)|(\+\+)|`)(\2?)([^<]*?)\2\8(?!\2)(?=\W|_|$)/g;
|
|
16
|
+
const rx_code = /\n((```|~~~).*\n?([^]*?)\n?\2|(( {4}.*?\n)+))/g;
|
|
17
|
+
const rx_link = /((!?)\[(.*?)\]\((.*?)( ".*")?\)|\\([\\`*_{}\[\]()#+\-.!~]))/g;
|
|
18
|
+
const rx_table = /\n(( *\|.*?\| *\n)+)/g;
|
|
19
|
+
const rx_thead = /^.*\n( *\|( *\:?-+\:?-+\:? *\|)* *\n|)/;
|
|
20
|
+
const rx_row = /.*\n/g;
|
|
21
|
+
const rx_cell = /\||(.*?[^\\])\|/g;
|
|
22
|
+
const rx_heading = /(?=^|>|\n)([>\s]*?)(#{1,6}) (.*?)( #*)? *(?=\n|$)/g;
|
|
23
|
+
const rx_para = /(?=^|>|\n)\s*\n+([^<]+?)\n+\s*(?=\n|<|$)/g;
|
|
24
|
+
const rx_stash = /-\d+\uf8ff/g;
|
|
25
25
|
|
|
26
26
|
function replace(rex, fn) {
|
|
27
27
|
src = src.replace(rex, fn);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function element(tag, content) {
|
|
31
|
-
return
|
|
31
|
+
return `<${tag}>${content}</${tag}>`;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function blockquote(src) {
|
|
35
|
-
return src.replace(rx_blockquote,
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return src.replace(rx_blockquote, (all, content) =>
|
|
36
|
+
element('blockquote', blockquote(highlight(content.replace(/^ *> */gm, '')))),
|
|
37
|
+
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function list(src) {
|
|
41
|
-
return src.replace(rx_list,
|
|
42
|
-
|
|
41
|
+
return src.replace(rx_list, (all, ind, ol, num, low, content) => {
|
|
42
|
+
const entry = element(
|
|
43
43
|
'li',
|
|
44
44
|
highlight(
|
|
45
45
|
content
|
|
46
|
-
.split(RegExp(
|
|
46
|
+
.split(RegExp(`\n ?${ind}(?:(?:\\d+|[a-zA-Z])[.)]|[*\\-+]) +`, 'g'))
|
|
47
47
|
.map(list)
|
|
48
48
|
.join('</li><li>'),
|
|
49
49
|
),
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(low ? 'low' : 'upp') +
|
|
62
|
-
'er-alpha">') +
|
|
63
|
-
entry +
|
|
64
|
-
'</ol>'
|
|
65
|
-
: element('ul', entry))
|
|
66
|
-
);
|
|
52
|
+
return `\n${
|
|
53
|
+
ol
|
|
54
|
+
? `<ol start="${
|
|
55
|
+
num
|
|
56
|
+
? `${ol}">`
|
|
57
|
+
: `${parseInt(ol, 36) - 9}" style="list-style-type:${low ? 'low' : 'upp'}er-alpha">`
|
|
58
|
+
}${entry}</ol>`
|
|
59
|
+
: element('ul', entry)
|
|
60
|
+
}`;
|
|
67
61
|
});
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
function highlight(src) {
|
|
71
|
-
return src.replace(
|
|
72
|
-
|
|
65
|
+
return src.replace(
|
|
66
|
+
rx_highlight,
|
|
67
|
+
(all, _, p1, emp, sub, sup, small, big, p2, content) =>
|
|
73
68
|
_ +
|
|
74
69
|
element(
|
|
75
70
|
emp
|
|
@@ -88,19 +83,18 @@ function markdown(src) {
|
|
|
88
83
|
? 'big'
|
|
89
84
|
: 'code',
|
|
90
85
|
highlight(content),
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
});
|
|
86
|
+
),
|
|
87
|
+
);
|
|
94
88
|
}
|
|
95
89
|
|
|
96
90
|
function unesc(str) {
|
|
97
91
|
return str.replace(rx_escape, '$1');
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const stash = [];
|
|
95
|
+
let si = 0;
|
|
102
96
|
|
|
103
|
-
src =
|
|
97
|
+
src = `\n${src}\n`;
|
|
104
98
|
|
|
105
99
|
replace(rx_lt, '<');
|
|
106
100
|
replace(rx_gt, '>');
|
|
@@ -117,56 +111,47 @@ function markdown(src) {
|
|
|
117
111
|
replace(rx_listjoin, '');
|
|
118
112
|
|
|
119
113
|
// code
|
|
120
|
-
replace(rx_code,
|
|
121
|
-
stash[--si] = element('pre', element('code', p3 || p4.replace(/^
|
|
122
|
-
return si
|
|
114
|
+
replace(rx_code, (all, p1, p2, p3, p4) => {
|
|
115
|
+
stash[--si] = element('pre', element('code', p3 || p4.replace(/^ {4}/gm, '')));
|
|
116
|
+
return `${si}\uf8ff`;
|
|
123
117
|
});
|
|
124
118
|
|
|
125
119
|
// link or image
|
|
126
|
-
replace(rx_link,
|
|
120
|
+
replace(rx_link, (all, p1, p2, p3, p4, p5, p6) => {
|
|
127
121
|
stash[--si] = p4
|
|
128
122
|
? p2
|
|
129
|
-
?
|
|
130
|
-
:
|
|
123
|
+
? `<img src="${p4}" alt="${p3}"/>`
|
|
124
|
+
: `<a href="${p4}">${unesc(highlight(p3))}</a>`
|
|
131
125
|
: p6;
|
|
132
|
-
return si
|
|
126
|
+
return `${si}\uf8ff`;
|
|
133
127
|
});
|
|
134
128
|
|
|
135
129
|
// table
|
|
136
|
-
replace(rx_table,
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
'
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
'
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}),
|
|
152
|
-
)
|
|
153
|
-
);
|
|
130
|
+
replace(rx_table, (all, table) => {
|
|
131
|
+
const sep = table.match(rx_thead)[1];
|
|
132
|
+
return `\n${element(
|
|
133
|
+
'table',
|
|
134
|
+
table.replace(rx_row, (row, ri) =>
|
|
135
|
+
row == sep
|
|
136
|
+
? ''
|
|
137
|
+
: element(
|
|
138
|
+
'tr',
|
|
139
|
+
row.replace(rx_cell, (all, cell, ci) =>
|
|
140
|
+
ci ? element(sep && !ri ? 'th' : 'td', unesc(highlight(cell || ''))) : '',
|
|
141
|
+
),
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
)}`;
|
|
154
145
|
});
|
|
155
146
|
|
|
156
147
|
// heading
|
|
157
|
-
replace(rx_heading,
|
|
158
|
-
return _ + element('h' + p1.length, unesc(highlight(p2)));
|
|
159
|
-
});
|
|
148
|
+
replace(rx_heading, (all, _, p1, p2) => _ + element(`h${p1.length}`, unesc(highlight(p2))));
|
|
160
149
|
|
|
161
150
|
// paragraph
|
|
162
|
-
replace(rx_para,
|
|
163
|
-
return element('p', unesc(highlight(content)));
|
|
164
|
-
});
|
|
151
|
+
replace(rx_para, (all, content) => element('p', unesc(highlight(content))));
|
|
165
152
|
|
|
166
153
|
// stash
|
|
167
|
-
replace(rx_stash,
|
|
168
|
-
return stash[parseInt(all)];
|
|
169
|
-
});
|
|
154
|
+
replace(rx_stash, all => stash[parseInt(all)]);
|
|
170
155
|
|
|
171
156
|
return src.trim();
|
|
172
157
|
}
|