repl-sdk 1.3.0 → 1.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repl-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -12,6 +12,11 @@
12
12
  "default": "./src/compilers/markdown/parse.js"
13
13
  }
14
14
  },
15
+ "repository": {
16
+ "type": "https",
17
+ "url": "https://github.com/NullVoxPopuli/limber.git",
18
+ "directory": "packages/repl-sdk"
19
+ },
15
20
  "ember-addon": {
16
21
  "version": 2,
17
22
  "type": "addon"
@@ -91,8 +96,8 @@
91
96
  "unist-util-visit": "^5.0.0",
92
97
  "vfile": "^6.0.3",
93
98
  "codemirror-lang-glimdown": "^2.0.3",
94
- "codemirror-lang-glimmer": "^2.0.3",
95
- "codemirror-lang-glimmer-js": "^2.0.3"
99
+ "codemirror-lang-glimmer-js": "^2.0.3",
100
+ "codemirror-lang-glimmer": "^2.0.3"
96
101
  },
97
102
  "volta": {
98
103
  "extends": "../../package.json"
@@ -44,8 +44,8 @@ export function buildCompiler(options) {
44
44
  // @ts-ignore - unified processor types are complex and change as plugins are added
45
45
  compiler = compiler.use(() => (tree) => {
46
46
  visit(tree, 'html', function (node) {
47
- // Check if this html node is a PascalCase component
48
- if (typeof node.value === 'string' && node.value.match(/^<[A-Z][a-zA-Z0-9]/)) {
47
+ // Check if this html node is a PascalCase component (opening or closing tag)
48
+ if (typeof node.value === 'string' && node.value.match(/^<\/?[A-Z][a-zA-Z0-9]/)) {
49
49
  // Add a marker to the node's data that remarkRehype will preserve
50
50
  // remark-rehype with allowDangerousHtml will turn this into a text node,
51
51
  // and the data should be preserved
@@ -63,7 +63,7 @@ export function buildCompiler(options) {
63
63
  if (
64
64
  child.type === 'html' &&
65
65
  typeof child.value === 'string' &&
66
- child.value.match(/^<[A-Z][a-zA-Z0-9]/)
66
+ child.value.match(/^<\/?[A-Z][a-zA-Z0-9]/)
67
67
  ) {
68
68
  if (!child.data) child.data = {};
69
69
  child.data.isPascalCaseComponent = true;
@@ -154,7 +154,7 @@ export function buildCompiler(options) {
154
154
  // Pattern: <PascalCaseName followed by whitespace, > or @
155
155
  if (
156
156
  (nodeObj.type === 'text' || nodeObj.type === 'raw' || nodeObj.type === 'html') &&
157
- nodeObj.value.match(/<[A-Z][a-zA-Z0-9]*(\s|>|@)/)
157
+ nodeObj.value.match(/<\/?[A-Z][a-zA-Z0-9]*(\s|>|@)/)
158
158
  ) {
159
159
  nodeObj.type = 'glimmer_raw';
160
160
 
@@ -14,13 +14,15 @@
14
14
 
15
15
  import { buildCompiler } from './build-compiler.js';
16
16
 
17
+ export { buildCompiler } from './build-compiler.js';
18
+
17
19
  /**
18
20
  * @param {string} input
19
21
  * @param {import('./types').InternalOptions} options
20
22
  * @returns {Promise<ParseResult>}
21
23
  */
22
24
  export async function parseMarkdown(input, options) {
23
- const markdownCompiler = buildCompiler(options);
25
+ const markdownCompiler = options?.compiler ?? buildCompiler(options);
24
26
  const processed = await markdownCompiler.process(input);
25
27
  const liveCode = /** @type {CodeBlock[]} */ (processed.data.liveCode || []);
26
28
  // @ts-ignore - processed is typed as unknown due to unified processor complexity
@@ -104,6 +104,33 @@ describe('default features', () => {
104
104
  `);
105
105
  });
106
106
 
107
+ it('allows components to wrap markdown content', async () => {
108
+ const result = await parseMarkdown(
109
+ [
110
+ `# Title`,
111
+ '',
112
+ 'Text',
113
+ '',
114
+ '<Callout>',
115
+ '',
116
+ 'Info [text](https://url.url)',
117
+ '',
118
+ '</Callout>',
119
+ '',
120
+ ].join('\n'),
121
+ { ...defaults }
122
+ );
123
+
124
+ expect(result.codeBlocks).toMatchInlineSnapshot(`[]`);
125
+ expect(result.text).toMatchInlineSnapshot(`
126
+ "<h1 id="title">Title</h1>
127
+ <p>Text</p>
128
+ <Callout>
129
+ <p>Info <a href="https://url.url">text</a></p>
130
+ </Callout>"
131
+ `);
132
+ });
133
+
107
134
  describe('does not', () => {
108
135
  it(`mistakenly transform text in codefences (previewed text is transformed though)`, async () => {
109
136
  const result = await parseMarkdown(
@@ -16,6 +16,7 @@ export interface PublicOptions {
16
16
  };
17
17
  remarkPlugins?: unknown[];
18
18
  rehypePlugins?: unknown[];
19
+ compiler?: { process: (text: string) => Promise<{ data: { liveCode: Array<string> } }> };
19
20
  }
20
21
 
21
22
  export type InternalOptions = PublicOptions & LiveCodeExtractionOptions;