@markdoc/markdoc 0.5.2 → 0.5.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACzC,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAmeF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAI5E"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACzC,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA2eF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAI5E"}
@@ -0,0 +1,13 @@
1
+ import { Config, CustomAttributeTypeInterface, ValidationError } from '../types';
2
+ /**
3
+ * Conditional attribute type for Markdoc {% if /%} and {% else /%} tags.
4
+ *
5
+ * Acceptable values are:
6
+ * - `boolean` (true or false)
7
+ * - `null` or `undefined` (in case of using variable that's not defined)
8
+ * - `object`
9
+ */
10
+ export declare class ConditionalAttributeType implements CustomAttributeTypeInterface {
11
+ validate(value: any, _config: Config, key: string): ValidationError[];
12
+ }
13
+ //# sourceMappingURL=conditional.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/schema-types/conditional.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,4BAA4B,EAC5B,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB;;;;;;;GAOG;AACH,qBAAa,wBAAyB,YAAW,4BAA4B;IAC3E,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,EAAE;CAkBtE"}
@@ -1 +1 @@
1
- {"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/tags/conditional.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,MAAM,EAEP,MAAM,UAAU,CAAC;AAIlB,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,WAEhC;AAmBD,eAAO,MAAM,KAAK,EAAE,MAmBnB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAKrB,CAAC"}
1
+ {"version":3,"file":"conditional.d.ts","sourceRoot":"","sources":["../../../src/tags/conditional.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,MAAM,EAEP,MAAM,UAAU,CAAC;AAKlB,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,WAEhC;AAmBD,eAAO,MAAM,KAAK,EAAE,MAmBnB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MAKrB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.5.2",
4
+ "version": "0.5.4",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -145,21 +145,28 @@ regular_word_with_underscores
145
145
 
146
146
  \\> Blockquote
147
147
 
148
+ Text > not a blockquote
149
+
148
150
  \\# Heading
149
151
 
150
152
  \\### Heading
151
153
 
154
+ #Not a heading
155
+
152
156
  **/docs/\\***
153
157
 
154
158
  ~~**a \\_sentence\\_ with \\_underscores**~~
155
159
 
156
160
  - Item with [brackets]
157
161
 
162
+ -not a list item
163
+
158
164
  \`\`\`
159
165
  \\*\\_[\\[]
160
166
  \`\`\`
161
167
 
162
168
  {% table %}
169
+ - <https://autolink.com>
163
170
  - **[Link](https://example.com?q=()**
164
171
  - **[Link](https://example.com?q=\\()**
165
172
  - **[Link](https://example.com?q=\\(\\))**
package/src/formatter.ts CHANGED
@@ -190,8 +190,16 @@ function* formatNode(n: Node, o: Options = {}) {
190
190
  break;
191
191
  }
192
192
  case 'link': {
193
+ const children = [...formatChildren(n, no)].join('');
194
+
195
+ // https://spec.commonmark.org/0.31.2/#autolinks
196
+ if (children === n.attributes.href && !n.attributes.title) {
197
+ yield `<${n.attributes.href}>`;
198
+ break;
199
+ }
200
+
193
201
  yield '[';
194
- yield* formatChildren(n, no);
202
+ yield children;
195
203
  yield ']';
196
204
  yield '(';
197
205
  yield* typeof n.attributes.href === 'string'
@@ -216,7 +224,7 @@ function* formatNode(n: Node, o: Options = {}) {
216
224
  yield* escapeMarkdownCharacters(content, /[*_~]/g);
217
225
  } else {
218
226
  // Escape > blockquote, * list item, and heading
219
- yield* escapeMarkdownCharacters(content, /^[*>#]/);
227
+ yield* escapeMarkdownCharacters(content, /^\*|#+\s|^>/);
220
228
  }
221
229
  }
222
230
 
@@ -0,0 +1,34 @@
1
+ import {
2
+ Config,
3
+ CustomAttributeTypeInterface,
4
+ ValidationError,
5
+ } from '../types';
6
+
7
+ /**
8
+ * Conditional attribute type for Markdoc {% if /%} and {% else /%} tags.
9
+ *
10
+ * Acceptable values are:
11
+ * - `boolean` (true or false)
12
+ * - `null` or `undefined` (in case of using variable that's not defined)
13
+ * - `object`
14
+ */
15
+ export class ConditionalAttributeType implements CustomAttributeTypeInterface {
16
+ validate(value: any, _config: Config, key: string): ValidationError[] {
17
+ if (
18
+ typeof value === 'boolean' ||
19
+ value === null ||
20
+ value === undefined ||
21
+ typeof value === 'object'
22
+ ) {
23
+ return [];
24
+ }
25
+
26
+ return [
27
+ {
28
+ id: 'attribute-type-invalid',
29
+ level: 'error',
30
+ message: `Attribute '${key}' must be type 'boolean | object' (null or undefined are also allowed)`,
31
+ },
32
+ ];
33
+ }
34
+ }
@@ -8,6 +8,7 @@ import {
8
8
  Schema,
9
9
  Value,
10
10
  } from '../types';
11
+ import { ConditionalAttributeType } from '../schema-types/conditional';
11
12
 
12
13
  type Condition = { condition: Value; children: Node[] };
13
14
 
@@ -34,7 +35,7 @@ function renderConditions(node: Node) {
34
35
 
35
36
  export const tagIf: Schema = {
36
37
  attributes: {
37
- primary: { type: Object, render: false },
38
+ primary: { type: ConditionalAttributeType, render: false },
38
39
  },
39
40
 
40
41
  transform(node, config) {
@@ -56,6 +57,6 @@ export const tagIf: Schema = {
56
57
  export const tagElse: Schema = {
57
58
  selfClosing: true,
58
59
  attributes: {
59
- primary: { type: Object, render: false },
60
+ primary: { type: ConditionalAttributeType, render: false },
60
61
  },
61
62
  };