@kamilio/wire 0.1.22 → 0.1.23
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 +7 -2
- package/dist/adapters/root.d.ts +5 -0
- package/dist/adapters/root.d.ts.map +1 -1
- package/dist/adapters/root.js +40 -4
- package/dist/adapters/root.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/executable.d.ts.map +1 -1
- package/dist/executable.js +2 -1
- package/dist/executable.js.map +1 -1
- package/node_modules/@xmldom/xmldom/CHANGELOG.md +1132 -0
- package/node_modules/@xmldom/xmldom/LICENSE +8 -0
- package/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
- package/node_modules/@xmldom/xmldom/index.d.ts +1843 -0
- package/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +3 -0
- package/node_modules/@xmldom/xmldom/lib/conventions.js +429 -0
- package/node_modules/@xmldom/xmldom/lib/dom-parser.js +591 -0
- package/node_modules/@xmldom/xmldom/lib/dom.js +3759 -0
- package/node_modules/@xmldom/xmldom/lib/entities.js +2171 -0
- package/node_modules/@xmldom/xmldom/lib/errors.js +205 -0
- package/node_modules/@xmldom/xmldom/lib/grammar.js +559 -0
- package/node_modules/@xmldom/xmldom/lib/index.js +41 -0
- package/node_modules/@xmldom/xmldom/lib/sax.js +983 -0
- package/node_modules/@xmldom/xmldom/package.json +77 -0
- package/node_modules/@xmldom/xmldom/readme.md +366 -0
- package/node_modules/marked/LICENSE.md +44 -0
- package/node_modules/marked/README.md +107 -0
- package/node_modules/marked/bin/main.js +284 -0
- package/node_modules/marked/bin/marked.js +16 -0
- package/node_modules/marked/lib/marked.d.ts +759 -0
- package/node_modules/marked/lib/marked.esm.js +72 -0
- package/node_modules/marked/lib/marked.esm.js.map +7 -0
- package/node_modules/marked/lib/marked.umd.js +74 -0
- package/node_modules/marked/lib/marked.umd.js.map +7 -0
- package/node_modules/marked/man/marked.1 +113 -0
- package/node_modules/marked/man/marked.1.md +93 -0
- package/node_modules/marked/package.json +103 -0
- package/node_modules/provider-asana/dist/asana-markdown.d.ts +5 -0
- package/node_modules/provider-asana/dist/asana-markdown.d.ts.map +1 -0
- package/node_modules/provider-asana/dist/asana-markdown.js +127 -0
- package/node_modules/provider-asana/dist/asana-markdown.js.map +1 -0
- package/node_modules/provider-asana/dist/asana-task.d.ts +9 -4
- package/node_modules/provider-asana/dist/asana-task.d.ts.map +1 -1
- package/node_modules/provider-asana/dist/asana-task.js +92 -12
- package/node_modules/provider-asana/dist/asana-task.js.map +1 -1
- package/node_modules/provider-asana/dist/index.d.ts +1 -1
- package/node_modules/provider-asana/dist/index.d.ts.map +1 -1
- package/node_modules/provider-asana/dist/index.js +1 -1
- package/node_modules/provider-asana/dist/index.js.map +1 -1
- package/node_modules/provider-asana/package.json +2 -0
- package/node_modules/provider-asana/src/asana-markdown.ts +113 -0
- package/node_modules/provider-asana/src/asana-task.ts +80 -12
- package/node_modules/provider-asana/src/index.ts +1 -1
- package/package.json +12 -6
- package/src/adapters/root.ts +42 -4
- package/src/cli.ts +1 -1
- package/src/executable.ts +2 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
.TH "MARKED" "1" "April 2026" "17.0.5"
|
|
2
|
+
.SH "NAME"
|
|
3
|
+
\fBmarked\fR \- a javascript markdown parser
|
|
4
|
+
.SH SYNOPSIS
|
|
5
|
+
.P
|
|
6
|
+
\fBmarked\fP [\fB\-o\fP <output file>] [\fB\-i\fP <input file>] [\fB\-s\fP <markdown string>] [\fB\-c\fP <config file>] [\fB\-\-help\fP] [\fB\-\-version\fP] [\fB\-\-tokens\fP] [\fB\-\-no\-clobber\fP] [\fB\-\-pedantic\fP] [\fB\-\-gfm\fP] [\fB\-\-breaks\fP] [\fB\-\-no\-etc\.\.\.\fP] [\fB\-\-silent\fP] [filename]
|
|
7
|
+
.SH DESCRIPTION
|
|
8
|
+
.P
|
|
9
|
+
marked is a full\-featured javascript markdown parser, built for speed\.
|
|
10
|
+
.br
|
|
11
|
+
It also includes multiple GFM features\.
|
|
12
|
+
.SH EXAMPLES
|
|
13
|
+
.RS 2
|
|
14
|
+
.nf
|
|
15
|
+
cat in\.md | marked > out\.html
|
|
16
|
+
.fi
|
|
17
|
+
.RE
|
|
18
|
+
.RS 2
|
|
19
|
+
.nf
|
|
20
|
+
echo "hello *world*" | marked
|
|
21
|
+
.fi
|
|
22
|
+
.RE
|
|
23
|
+
.RS 2
|
|
24
|
+
.nf
|
|
25
|
+
marked \-o out\.html \-i in\.md \-\-gfm
|
|
26
|
+
.fi
|
|
27
|
+
.RE
|
|
28
|
+
.RS 2
|
|
29
|
+
.nf
|
|
30
|
+
marked \-\-output="hello world\.html" \-i in\.md \-\-no\-breaks
|
|
31
|
+
.fi
|
|
32
|
+
.RE
|
|
33
|
+
.SH OPTIONS
|
|
34
|
+
|
|
35
|
+
.RS 1
|
|
36
|
+
.IP \(bu 2
|
|
37
|
+
\-o, \-\-output [output file]
|
|
38
|
+
.br
|
|
39
|
+
Specify file output\. If none is specified, write to stdout\.
|
|
40
|
+
.IP \(bu 2
|
|
41
|
+
\-i, \-\-input [input file]
|
|
42
|
+
.br
|
|
43
|
+
Specify file input, otherwise use last argument as input file\.
|
|
44
|
+
.br
|
|
45
|
+
If no input file is specified, read from stdin\.
|
|
46
|
+
.IP \(bu 2
|
|
47
|
+
\-s, \-\-string [markdown string]
|
|
48
|
+
.br
|
|
49
|
+
Specify string input instead of a file\.
|
|
50
|
+
.IP \(bu 2
|
|
51
|
+
\-c, \-\-config [config file]
|
|
52
|
+
.br
|
|
53
|
+
Specify config file to use instead of the default \fB~/\.marked\.json\fP or \fB~/\.marked\.js\fP or \fB~/\.marked/index\.js\fP\|\.
|
|
54
|
+
.IP \(bu 2
|
|
55
|
+
\-t, \-\-tokens
|
|
56
|
+
.br
|
|
57
|
+
Output a token list instead of html\.
|
|
58
|
+
.IP \(bu 2
|
|
59
|
+
\-n, \-\-no\-clobber
|
|
60
|
+
.br
|
|
61
|
+
Do not overwrite \fBoutput\fP if it exists\.
|
|
62
|
+
.IP \(bu 2
|
|
63
|
+
\-\-pedantic
|
|
64
|
+
.br
|
|
65
|
+
Conform to obscure parts of markdown\.pl as much as possible\.
|
|
66
|
+
.br
|
|
67
|
+
Don't fix original markdown bugs\.
|
|
68
|
+
.IP \(bu 2
|
|
69
|
+
\-\-gfm
|
|
70
|
+
.br
|
|
71
|
+
Enable github flavored markdown\.
|
|
72
|
+
.IP \(bu 2
|
|
73
|
+
\-\-breaks
|
|
74
|
+
.br
|
|
75
|
+
Enable GFM line breaks\. Only works with the gfm option\.
|
|
76
|
+
.IP \(bu 2
|
|
77
|
+
\-\-no\-breaks, \-no\-etc\.\.\.
|
|
78
|
+
.br
|
|
79
|
+
The inverse of any of the marked options above\.
|
|
80
|
+
.IP \(bu 2
|
|
81
|
+
\-\-silent
|
|
82
|
+
.br
|
|
83
|
+
Silence error output\.
|
|
84
|
+
.IP \(bu 2
|
|
85
|
+
\-h, \-\-help
|
|
86
|
+
.br
|
|
87
|
+
Display help information\.
|
|
88
|
+
|
|
89
|
+
.RE
|
|
90
|
+
.SH CONFIGURATION
|
|
91
|
+
.P
|
|
92
|
+
For configuring and running programmatically\.
|
|
93
|
+
.P
|
|
94
|
+
Example
|
|
95
|
+
.RS 2
|
|
96
|
+
.nf
|
|
97
|
+
import { Marked } from 'marked';
|
|
98
|
+
const marked = new Marked({ gfm: true });
|
|
99
|
+
marked\.parse('*foo*');
|
|
100
|
+
.fi
|
|
101
|
+
.RE
|
|
102
|
+
.SH BUGS
|
|
103
|
+
.P
|
|
104
|
+
Please report any bugs to https://github.com/markedjs/marked
|
|
105
|
+
.SH LICENSE
|
|
106
|
+
.P
|
|
107
|
+
Copyright (c) 2018+, MarkedJS\. (MIT License)
|
|
108
|
+
.br
|
|
109
|
+
Copyright (c) 2011\-2018, Christopher Jeffrey\. (MIT License)
|
|
110
|
+
.SH SEE ALSO
|
|
111
|
+
.P
|
|
112
|
+
markdown(1), nodejs(1)
|
|
113
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# marked(1) -- a javascript markdown parser
|
|
2
|
+
|
|
3
|
+
## SYNOPSIS
|
|
4
|
+
|
|
5
|
+
`marked` [`-o` <output file>] [`-i` <input file>] [`-s` <markdown string>] [`-c` <config file>] [`--help`] [`--version`] [`--tokens`] [`--no-clobber`] [`--pedantic`] [`--gfm`] [`--breaks`] [`--no-etc...`] [`--silent`] [filename]
|
|
6
|
+
|
|
7
|
+
## DESCRIPTION
|
|
8
|
+
|
|
9
|
+
marked is a full-featured javascript markdown parser, built for speed.
|
|
10
|
+
It also includes multiple GFM features.
|
|
11
|
+
|
|
12
|
+
## EXAMPLES
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
cat in.md | marked > out.html
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
echo "hello *world*" | marked
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
marked -o out.html -i in.md --gfm
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
marked --output="hello world.html" -i in.md --no-breaks
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## OPTIONS
|
|
31
|
+
|
|
32
|
+
* -o, --output [output file]
|
|
33
|
+
Specify file output. If none is specified, write to stdout.
|
|
34
|
+
|
|
35
|
+
* -i, --input [input file]
|
|
36
|
+
Specify file input, otherwise use last argument as input file.
|
|
37
|
+
If no input file is specified, read from stdin.
|
|
38
|
+
|
|
39
|
+
* -s, --string [markdown string]
|
|
40
|
+
Specify string input instead of a file.
|
|
41
|
+
|
|
42
|
+
* -c, --config [config file]
|
|
43
|
+
Specify config file to use instead of the default `~/.marked.json` or `~/.marked.js` or `~/.marked/index.js`.
|
|
44
|
+
|
|
45
|
+
* -t, --tokens
|
|
46
|
+
Output a token list instead of html.
|
|
47
|
+
|
|
48
|
+
* -n, --no-clobber
|
|
49
|
+
Do not overwrite `output` if it exists.
|
|
50
|
+
|
|
51
|
+
* --pedantic
|
|
52
|
+
Conform to obscure parts of markdown.pl as much as possible.
|
|
53
|
+
Don't fix original markdown bugs.
|
|
54
|
+
|
|
55
|
+
* --gfm
|
|
56
|
+
Enable github flavored markdown.
|
|
57
|
+
|
|
58
|
+
* --breaks
|
|
59
|
+
Enable GFM line breaks. Only works with the gfm option.
|
|
60
|
+
|
|
61
|
+
* --no-breaks, -no-etc...
|
|
62
|
+
The inverse of any of the marked options above.
|
|
63
|
+
|
|
64
|
+
* --silent
|
|
65
|
+
Silence error output.
|
|
66
|
+
|
|
67
|
+
* -h, --help
|
|
68
|
+
Display help information.
|
|
69
|
+
|
|
70
|
+
## CONFIGURATION
|
|
71
|
+
|
|
72
|
+
For configuring and running programmatically.
|
|
73
|
+
|
|
74
|
+
Example
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
import { Marked } from 'marked';
|
|
78
|
+
const marked = new Marked({ gfm: true });
|
|
79
|
+
marked.parse('*foo*');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## BUGS
|
|
83
|
+
|
|
84
|
+
Please report any bugs to <https://github.com/markedjs/marked>.
|
|
85
|
+
|
|
86
|
+
## LICENSE
|
|
87
|
+
|
|
88
|
+
Copyright (c) 2018+, MarkedJS. (MIT License)
|
|
89
|
+
Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
|
|
90
|
+
|
|
91
|
+
## SEE ALSO
|
|
92
|
+
|
|
93
|
+
markdown(1), nodejs(1)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "marked",
|
|
3
|
+
"description": "A markdown parser built for speed",
|
|
4
|
+
"author": "Christopher Jeffrey",
|
|
5
|
+
"version": "17.0.6",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./lib/marked.esm.js",
|
|
8
|
+
"module": "./lib/marked.esm.js",
|
|
9
|
+
"browser": "./lib/marked.umd.js",
|
|
10
|
+
"types": "./lib/marked.d.ts",
|
|
11
|
+
"bin": {
|
|
12
|
+
"marked": "bin/marked.js"
|
|
13
|
+
},
|
|
14
|
+
"man": "./man/marked.1",
|
|
15
|
+
"files": [
|
|
16
|
+
"bin/",
|
|
17
|
+
"lib/",
|
|
18
|
+
"man/"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./lib/marked.d.ts",
|
|
23
|
+
"default": "./lib/marked.esm.js"
|
|
24
|
+
},
|
|
25
|
+
"./bin/marked": "./bin/marked.js",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"provenance": true
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git://github.com/markedjs/marked.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://marked.js.org",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "http://github.com/markedjs/marked/issues"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"markdown",
|
|
42
|
+
"markup",
|
|
43
|
+
"html"
|
|
44
|
+
],
|
|
45
|
+
"tags": [
|
|
46
|
+
"markdown",
|
|
47
|
+
"markup",
|
|
48
|
+
"html"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
52
|
+
"@markedjs/eslint-config": "^1.0.14",
|
|
53
|
+
"@markedjs/testutils": "17.0.1-2",
|
|
54
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
55
|
+
"@semantic-release/git": "^10.0.1",
|
|
56
|
+
"@semantic-release/github": "^12.0.6",
|
|
57
|
+
"@semantic-release/npm": "^13.1.5",
|
|
58
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
59
|
+
"cheerio": "1.2.0",
|
|
60
|
+
"commonmark": "0.31.2",
|
|
61
|
+
"cross-env": "^10.1.0",
|
|
62
|
+
"dts-bundle-generator": "^9.5.1",
|
|
63
|
+
"esbuild": "^0.27.4",
|
|
64
|
+
"esbuild-plugin-umd-wrapper": "^3.0.0",
|
|
65
|
+
"eslint": "^10.1.0",
|
|
66
|
+
"highlight.js": "^11.11.1",
|
|
67
|
+
"markdown-it": "14.1.1",
|
|
68
|
+
"marked-highlight": "^2.2.3",
|
|
69
|
+
"marked-man": "^2.1.0",
|
|
70
|
+
"recheck": "^4.5.0",
|
|
71
|
+
"rimraf": "^6.1.3",
|
|
72
|
+
"semantic-release": "^25.0.3",
|
|
73
|
+
"titleize": "^4.0.0",
|
|
74
|
+
"tslib": "^2.8.1",
|
|
75
|
+
"typescript": "5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"bench": "npm run build && node test/bench.js",
|
|
79
|
+
"build": "npm run build:esbuild && npm run build:types && npm run build:man",
|
|
80
|
+
"build:docs": "npm run build && node docs/build.js",
|
|
81
|
+
"build:esbuild": "node esbuild.config.js",
|
|
82
|
+
"build:man": "marked-man man/marked.1.md > man/marked.1",
|
|
83
|
+
"build:reset": "rimraf ./lib ./public",
|
|
84
|
+
"build:types": "tsc && dts-bundle-generator --export-referenced-types --project tsconfig.json -o lib/marked.d.ts src/marked.ts",
|
|
85
|
+
"lint": "eslint --fix",
|
|
86
|
+
"rules": "node test/rules.js",
|
|
87
|
+
"test": "npm run build:reset && npm run build:docs && npm run test:specs && npm run test:unit && npm run test:umd && npm run test:cjs && npm run test:types && npm run test:lint",
|
|
88
|
+
"test:cjs": "node test/cjs-test.cjs",
|
|
89
|
+
"test:lint": "eslint",
|
|
90
|
+
"test:only": "npm run build && npm run test:specs:only && npm run test:unit:only",
|
|
91
|
+
"test:redos": "node test/recheck.ts > vuln.js",
|
|
92
|
+
"test:specs:only": "node --test --test-only --test-reporter=spec test/run-spec-tests.js",
|
|
93
|
+
"test:specs": "node --test --test-reporter=spec test/run-spec-tests.js",
|
|
94
|
+
"test:types": "tsc --project tsconfig-type-test.json && attw -P --entrypoints . --profile esm-only",
|
|
95
|
+
"test:umd": "node test/umd-test.js",
|
|
96
|
+
"test:unit:only": "node --test --test-only --test-reporter=spec test/unit/*.test.js",
|
|
97
|
+
"test:unit": "node --test --test-reporter=spec test/unit/*.test.js",
|
|
98
|
+
"test:update": "node test/update-specs.js"
|
|
99
|
+
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">= 20"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asana-markdown.d.ts","sourceRoot":"","sources":["../src/asana-markdown.ts"],"names":[],"mappings":"AAOA,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3C,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA6CtE;AAMD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoDlD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
2
|
+
import { marked } from "marked";
|
|
3
|
+
function xml(text) {
|
|
4
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5
|
+
}
|
|
6
|
+
export function asanaRichText(markdown, target) {
|
|
7
|
+
const render = (tokens) => tokens.map(token).join("");
|
|
8
|
+
const blocks = (tokens) => tokens.filter((t) => t.type !== "space" && t.type !== "def").map(token).join("\n\n");
|
|
9
|
+
function token(t) {
|
|
10
|
+
switch (t.type) {
|
|
11
|
+
case "paragraph": return render(t.tokens);
|
|
12
|
+
case "text": return t.tokens ? render(t.tokens) : xml(t.text);
|
|
13
|
+
case "escape": return xml(t.text);
|
|
14
|
+
case "html": return /^<\/?u>$/.test(t.text) ? t.text : xml(t.text);
|
|
15
|
+
case "br": return "\n";
|
|
16
|
+
case "strong":
|
|
17
|
+
case "em": return `<${t.type}>${render(t.tokens)}</${t.type}>`;
|
|
18
|
+
case "del": return `<s>${render(t.tokens)}</s>`;
|
|
19
|
+
case "codespan": return `<code>${xml(t.text)}</code>`;
|
|
20
|
+
case "code": return `<pre${t.lang ? ` data-language="${xml(t.lang)}"` : ""}>${xml(t.text)}</pre>`;
|
|
21
|
+
case "blockquote": return `<blockquote>${blocks(t.tokens)}</blockquote>`;
|
|
22
|
+
case "heading": {
|
|
23
|
+
const tag = target === "task" && t.depth <= 2 ? `h${t.depth}` : "strong";
|
|
24
|
+
return `<${tag}>${render(t.tokens)}</${tag}>`;
|
|
25
|
+
}
|
|
26
|
+
case "hr": return target === "task" ? "<hr/>" : "———";
|
|
27
|
+
case "list": {
|
|
28
|
+
const tag = t.ordered ? "ol" : "ul";
|
|
29
|
+
return `<${tag}>${t.items.map((item) => `<li>${render(item.tokens)}</li>`).join("")}</${tag}>`;
|
|
30
|
+
}
|
|
31
|
+
case "checkbox": return t.checked ? "☑ " : "☐ ";
|
|
32
|
+
case "space": return "\n\n";
|
|
33
|
+
case "link":
|
|
34
|
+
case "image": {
|
|
35
|
+
const gid = /^asana:(\d+)$/.exec(t.title ?? "")?.[1] ?? /^asana:\/\/(\d+)$/.exec(t.href)?.[1];
|
|
36
|
+
if (t.type === "image" && gid && target === "task")
|
|
37
|
+
return `<img data-asana-gid="${gid}"/>`;
|
|
38
|
+
if (gid)
|
|
39
|
+
return `<a data-asana-gid="${gid}"></a>`;
|
|
40
|
+
if (!/^(?:https?:\/\/|mailto:)/i.test(t.href))
|
|
41
|
+
throw new Error("Asana links need an absolute HTTP, HTTPS, or mailto URL.");
|
|
42
|
+
return `<a href="${xml(t.href)}">${t.type === "image" ? xml(t.text || t.href) : render(t.tokens)}</a>`;
|
|
43
|
+
}
|
|
44
|
+
case "table": {
|
|
45
|
+
if (target !== "task")
|
|
46
|
+
throw new Error("Asana supports Markdown tables in task descriptions only.");
|
|
47
|
+
return "<table>" + [t.header, ...t.rows].map((row) => "<tr>" + row.map((cell) => `<td>${render(cell.tokens)}</td>`).join("") + "</tr>").join("") + "</table>";
|
|
48
|
+
}
|
|
49
|
+
default: return xml(t.raw);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const html = `<body>${blocks(marked.lexer(markdown))}</body>`;
|
|
53
|
+
if (/[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(html))
|
|
54
|
+
throw new Error("Asana rich text cannot contain XML control characters.");
|
|
55
|
+
// Raw underline tags are allowed in Markdown, so validate their nesting.
|
|
56
|
+
if (/<\/?u>/.test(html))
|
|
57
|
+
new DOMParser({ onError: () => { throw new Error("Unbalanced underline tags in Markdown."); } }).parseFromString(html, "application/xml");
|
|
58
|
+
return html;
|
|
59
|
+
}
|
|
60
|
+
function literal(value) {
|
|
61
|
+
return value.replace(/([\\`*_\[\]~<>])/g, "\\$1").replace(/^(\s*)(#{1,6}|[-+=>])(?=\s)/gm, "$1\\$2").replace(/^(\s*\d+)([.)])(?=\s)/gm, "$1\\$2");
|
|
62
|
+
}
|
|
63
|
+
export function asanaMarkdown(html) {
|
|
64
|
+
const root = new DOMParser().parseFromString(html, "application/xml").documentElement;
|
|
65
|
+
// Asana may supply its own newlines around block elements. Keep whichever
|
|
66
|
+
// boundary is wider rather than adding both to the Markdown.
|
|
67
|
+
const children = (node) => Array.from(node.childNodes ?? []).map(render).reduce((before, after) => {
|
|
68
|
+
const overlap = Math.min(before.match(/\n*$/)[0].length, after.match(/^\n*/)[0].length);
|
|
69
|
+
return before + after.slice(overlap);
|
|
70
|
+
}, "");
|
|
71
|
+
function render(node) {
|
|
72
|
+
if (node.nodeType === 3 || node.nodeType === 4)
|
|
73
|
+
return literal(node.nodeValue ?? "");
|
|
74
|
+
if (node.nodeType !== 1)
|
|
75
|
+
return "";
|
|
76
|
+
const el = node;
|
|
77
|
+
const content = () => children(el);
|
|
78
|
+
switch (el.tagName) {
|
|
79
|
+
case "strong":
|
|
80
|
+
case "b": return `**${content()}**`;
|
|
81
|
+
case "em":
|
|
82
|
+
case "i": return `*${content()}*`;
|
|
83
|
+
case "s": return `~~${content()}~~`;
|
|
84
|
+
case "u": return `<u>${content()}</u>`;
|
|
85
|
+
case "br": return "\n";
|
|
86
|
+
case "a":
|
|
87
|
+
case "img": {
|
|
88
|
+
const gid = el.getAttribute("data-asana-gid");
|
|
89
|
+
const href = el.getAttribute("href") || (gid ? `asana://${gid}` : el.getAttribute("src"));
|
|
90
|
+
if (!href)
|
|
91
|
+
return content();
|
|
92
|
+
return `${el.tagName === "img" ? "!" : ""}[${content() || gid || "link"}](${href.replace(/[()\s<>]/g, c => "%" + c.charCodeAt(0).toString(16))}${gid && el.hasAttribute("href") ? ` "asana:${gid}"` : ""})`;
|
|
93
|
+
}
|
|
94
|
+
case "code":
|
|
95
|
+
case "pre": {
|
|
96
|
+
const text = el.textContent ?? "";
|
|
97
|
+
const fence = "`".repeat(Math.max(el.tagName === "pre" ? 3 : 1, ...Array.from(text.matchAll(/`+/g), m => m[0].length + 1)));
|
|
98
|
+
if (el.tagName === "pre")
|
|
99
|
+
return `\n\n${fence}${el.getAttribute("data-language") ?? ""}\n${text}\n${fence}\n\n`;
|
|
100
|
+
const pad = /^`|`$/.test(text) || /^ .* $/.test(text) && /\S/.test(text) ? " " : "";
|
|
101
|
+
return `${fence}${pad}${text}${pad}${fence}`;
|
|
102
|
+
}
|
|
103
|
+
case "h1":
|
|
104
|
+
case "h2": return `\n\n${el.tagName === "h1" ? "#" : "##"} ${content()}\n\n`;
|
|
105
|
+
case "hr": return "\n\n---\n\n";
|
|
106
|
+
case "blockquote": return "\n\n" + content().trim().split("\n").map(line => "> " + line).join("\n") + "\n\n";
|
|
107
|
+
case "ul":
|
|
108
|
+
case "ol": {
|
|
109
|
+
const rows = Array.from(el.childNodes).filter(item => item.nodeName === "li").map((li, i) => {
|
|
110
|
+
const prefix = el.tagName === "ol" ? `${i + 1}. ` : "- ";
|
|
111
|
+
return prefix + children(li).trim().replace(/\n/g, "\n" + " ".repeat(prefix.length));
|
|
112
|
+
});
|
|
113
|
+
return "\n" + rows.join("\n") + "\n";
|
|
114
|
+
}
|
|
115
|
+
case "table": {
|
|
116
|
+
const rows = Array.from(el.getElementsByTagName("tr")).map(row => Array.from(row.getElementsByTagName("td")).map(cell => children(cell).replace(/\|/g, "\\|").replace(/\n/g, " ")));
|
|
117
|
+
if (!rows.length)
|
|
118
|
+
return "";
|
|
119
|
+
rows.splice(1, 0, rows[0].map(() => "---"));
|
|
120
|
+
return "\n\n" + rows.map(row => "| " + row.join(" | ") + " |").join("\n") + "\n\n";
|
|
121
|
+
}
|
|
122
|
+
default: return content();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return children(root).trim();
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=asana-markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asana-markdown.js","sourceRoot":"","sources":["../src/asana-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA2B,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,MAAM,EAA2B,MAAM,QAAQ,CAAC;AAEzD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACzG,CAAC;AAID,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,MAAc;IAC5D,MAAM,MAAM,GAAG,CAAC,MAAe,EAAU,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,CAAC,MAAe,EAAU,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAA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,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACvC,CAAC;YACD,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBACpL,IAAI,CAAC,IAAI,CAAC,MAAM;oBAAE,OAAO,EAAE,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7C,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;YACrF,CAAC;YACD,OAAO,CAAC,CAAC,OAAO,OAAO,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsonValue } from "wire-core";
|
|
1
|
+
import type { JsonObject, JsonValue } from "wire-core";
|
|
2
2
|
import type { RuntimeCapabilities } from "wire-core";
|
|
3
3
|
export declare const asanaTaskService: Readonly<{
|
|
4
4
|
name: string;
|
|
@@ -37,10 +37,15 @@ export declare function showAsanaTask(runtime: RuntimeCapabilities, identifier:
|
|
|
37
37
|
markdown: `${string}
|
|
38
38
|
`;
|
|
39
39
|
data: {
|
|
40
|
-
task:
|
|
40
|
+
task: {
|
|
41
|
+
body_markdown: string;
|
|
42
|
+
};
|
|
43
|
+
stories: Readonly<{
|
|
41
44
|
[key: string]: JsonValue;
|
|
42
|
-
}
|
|
43
|
-
stories: readonly JsonValue[];
|
|
45
|
+
}>[];
|
|
44
46
|
};
|
|
45
47
|
}>>;
|
|
48
|
+
export declare function editAsanaTask(runtime: RuntimeCapabilities, task: string, fields: JsonObject): Promise<JsonObject>;
|
|
49
|
+
export declare function addAsanaComment(runtime: RuntimeCapabilities, task: string, body: string): Promise<JsonObject>;
|
|
50
|
+
export declare function editAsanaComment(runtime: RuntimeCapabilities, comment: string, body: string): Promise<JsonObject>;
|
|
46
51
|
//# sourceMappingURL=asana-task.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asana-task.d.ts","sourceRoot":"","sources":["../src/asana-task.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asana-task.d.ts","sourceRoot":"","sources":["../src/asana-task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAkErD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAO3B,CAAC;AAEH,wBAAsB,aAAa,CAAC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM;WAwCpC,MAAM;;;;;;;;;;;IACrD;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CA6BvH;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAInH;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAIvH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { asanaMarkdown, asanaRichText } from "./asana-markdown.js";
|
|
2
|
+
import { asanaHttp, request } from "./asana-http.js";
|
|
2
3
|
import { defineService } from "wire-core";
|
|
3
4
|
function object(value) {
|
|
4
5
|
return value;
|
|
@@ -34,14 +35,14 @@ async function asana(runtime, path, parameters) {
|
|
|
34
35
|
}
|
|
35
36
|
async function fetchTask(runtime, identifier) {
|
|
36
37
|
return object((await asana(runtime, `/tasks/${identifier}`, {
|
|
37
|
-
opt_fields: "gid,name,notes,completed,completed_at,created_at,modified_at,due_on,due_at,permalink_url,assignee,assignee.name,assignee.email,memberships.project.gid,memberships.project.name,memberships.section.name,projects.name,tags.name",
|
|
38
|
+
opt_fields: "gid,name,notes,html_notes,completed,completed_at,created_at,modified_at,due_on,due_at,permalink_url,assignee,assignee.name,assignee.email,memberships.project.gid,memberships.project.name,memberships.section.name,projects.name,tags.name,start_on,start_at,resource_subtype,approval_status,custom_type.name,custom_type_status_option.name,custom_fields.name,custom_fields.resource_subtype,custom_fields.display_value,custom_fields.is_value_read_only,custom_fields.enabled,custom_fields.enum_options.name,custom_fields.enum_options.enabled,custom_fields.text_value,custom_fields.html_text_value,custom_fields.number_value,custom_fields.enum_value.name,custom_fields.multi_enum_values.name,custom_fields.date_value,custom_fields.people_value.name,custom_fields.reference_value.name",
|
|
38
39
|
}))["data"]);
|
|
39
40
|
}
|
|
40
41
|
async function fetchStories(runtime, identifier) {
|
|
41
42
|
const stories = [];
|
|
42
43
|
let offset;
|
|
43
44
|
do {
|
|
44
|
-
const parameters = { limit: "100", opt_fields: "gid,type,text,created_at,created_by.name,created_by.email,resource_subtype" };
|
|
45
|
+
const parameters = { limit: "100", opt_fields: "gid,type,text,html_text,is_editable,comment_gid,anchor_gid,created_at,created_by.name,created_by.email,resource_subtype" };
|
|
45
46
|
if (offset !== undefined)
|
|
46
47
|
parameters["offset"] = offset;
|
|
47
48
|
const page = await asana(runtime, `/tasks/${identifier}/stories`, parameters);
|
|
@@ -85,16 +86,95 @@ export async function showAsanaTask(runtime, identifier) {
|
|
|
85
86
|
const assignee = task["assignee"];
|
|
86
87
|
const lines = [`# ${task["name"]}`, "", `- Source: ${task["permalink_url"]}`, `- Completed: ${task["completed"] ? "True" : "False"}`];
|
|
87
88
|
if (assignee !== null)
|
|
88
|
-
lines.push(`- Assignee: ${assignee["name"]}`);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
lines.push(`- Assignee: ${assignee["name"]}${assignee["email"] ? ` <${assignee["email"]}>` : ""}`);
|
|
90
|
+
for (const [label, value] of [
|
|
91
|
+
["Starts", task["start_at"] ?? task["start_on"]], ["Due", task["due_at"] ?? task["due_on"]],
|
|
92
|
+
["Approval", task["resource_subtype"] === "approval" ? task["approval_status"] : null],
|
|
93
|
+
["Task type", task["custom_type"]?.["name"]],
|
|
94
|
+
["Status", task["custom_type_status_option"]?.["name"]],
|
|
95
|
+
])
|
|
96
|
+
if (value)
|
|
97
|
+
lines.push(`- ${label}: ${value}`);
|
|
98
|
+
const bodyMarkdown = task["html_notes"] ? asanaMarkdown(task["html_notes"]) : task["notes"];
|
|
99
|
+
lines.push("", bodyMarkdown);
|
|
100
|
+
const fields = task["custom_fields"];
|
|
101
|
+
if (fields?.length) {
|
|
102
|
+
lines.push("", "## Custom fields", "");
|
|
103
|
+
for (const field of fields) {
|
|
104
|
+
const readOnly = field["is_value_read_only"] || field["enabled"] === false;
|
|
105
|
+
lines.push(`- ${field["name"]} (${field["gid"]}, ${field["resource_subtype"]}${readOnly ? ", read-only" : ""}): ${field["html_text_value"] ? asanaMarkdown(field["html_text_value"]) : field["display_value"] ?? "—"}`);
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
|
-
|
|
108
|
+
const comments = [];
|
|
109
|
+
const activity = [];
|
|
110
|
+
const storyData = stories.map((value) => {
|
|
111
|
+
const story = object(value);
|
|
112
|
+
const isComment = story["type"] === "comment" || story["resource_subtype"] === "comment_added";
|
|
113
|
+
const author = story["created_by"]?.["name"] ?? "System";
|
|
114
|
+
const id = isComment ? ` [${story["gid"]}${story["is_editable"] ? ", editable" : ""}]` : "";
|
|
115
|
+
if (isComment) {
|
|
116
|
+
const body = story["html_text"] ? asanaMarkdown(story["html_text"]) : story["text"] ?? "";
|
|
117
|
+
comments.push(`**${author}** · ${story["created_at"]}${id}\n\n${body}`);
|
|
118
|
+
return { ...story, body_markdown: body };
|
|
119
|
+
}
|
|
120
|
+
activity.push(`- ${story["created_at"]} — ${author}: ${story["text"] ?? ""}`);
|
|
121
|
+
return story;
|
|
122
|
+
});
|
|
123
|
+
if (comments.length)
|
|
124
|
+
lines.push("", "## Comments", "", comments.join("\n\n"));
|
|
125
|
+
if (activity.length)
|
|
126
|
+
lines.push("", "## Activity", "", ...activity);
|
|
127
|
+
return Object.freeze({ title: task["name"], markdown: `${lines.join("\n").trimEnd()}\n`, data: { task: { ...task, body_markdown: bodyMarkdown }, stories: storyData } });
|
|
128
|
+
}
|
|
129
|
+
export async function editAsanaTask(runtime, task, fields) {
|
|
130
|
+
if (!/^\d+$/.test(task))
|
|
131
|
+
throw new Error("Expected a numeric Asana task ID.");
|
|
132
|
+
if (!Object.keys(fields).length)
|
|
133
|
+
throw new Error("No task fields to update.");
|
|
134
|
+
const data = { ...fields };
|
|
135
|
+
if ("html_notes" in data || "html_custom_fields" in data)
|
|
136
|
+
throw new Error("Use Markdown in notes or custom_fields instead of HTML.");
|
|
137
|
+
if ("notes" in data) {
|
|
138
|
+
if (typeof data["notes"] !== "string")
|
|
139
|
+
throw new Error("Task notes must be Markdown text.");
|
|
140
|
+
data["html_notes"] = asanaRichText(data["notes"], "task");
|
|
141
|
+
delete data["notes"];
|
|
142
|
+
}
|
|
143
|
+
const custom = data["custom_fields"];
|
|
144
|
+
if (custom && typeof custom === "object" && !Array.isArray(custom) && Object.values(custom).some(v => typeof v === "string")) {
|
|
145
|
+
const schema = object((await asana(runtime, `/tasks/${task}`, { opt_fields: "custom_fields.resource_subtype" }))["data"]);
|
|
146
|
+
const values = { ...custom };
|
|
147
|
+
const rich = {};
|
|
148
|
+
for (const field of schema["custom_fields"]) {
|
|
149
|
+
const key = field["gid"];
|
|
150
|
+
const value = values[key];
|
|
151
|
+
if (field["resource_subtype"] !== "text" || typeof value !== "string")
|
|
152
|
+
continue;
|
|
153
|
+
rich[key] = asanaRichText(value, "field");
|
|
154
|
+
delete values[key];
|
|
155
|
+
}
|
|
156
|
+
if (Object.keys(rich).length) {
|
|
157
|
+
data["html_custom_fields"] = rich;
|
|
158
|
+
if (Object.keys(values).length)
|
|
159
|
+
data["custom_fields"] = values;
|
|
160
|
+
else
|
|
161
|
+
delete data["custom_fields"];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return object((await request(runtime, "PUT", `/tasks/${task}`, { opt_fields: "name,permalink_url" }, data))["data"]);
|
|
165
|
+
}
|
|
166
|
+
export async function addAsanaComment(runtime, task, body) {
|
|
167
|
+
if (!/^\d+$/.test(task))
|
|
168
|
+
throw new Error("Expected a numeric Asana task ID.");
|
|
169
|
+
if (!body.trim())
|
|
170
|
+
throw new Error("Comment body cannot be empty.");
|
|
171
|
+
return object((await request(runtime, "POST", `/tasks/${task}/stories`, { opt_fields: "text" }, { html_text: asanaRichText(body, "comment") }))["data"]);
|
|
172
|
+
}
|
|
173
|
+
export async function editAsanaComment(runtime, comment, body) {
|
|
174
|
+
if (!/^\d+$/.test(comment))
|
|
175
|
+
throw new Error("Expected a numeric Asana comment ID.");
|
|
176
|
+
if (!body.trim())
|
|
177
|
+
throw new Error("Comment body cannot be empty.");
|
|
178
|
+
return object((await request(runtime, "PUT", `/stories/${comment}`, { opt_fields: "text" }, { html_text: asanaRichText(body, "comment") }))["data"]);
|
|
99
179
|
}
|
|
100
180
|
//# sourceMappingURL=asana-task.js.map
|