Skip to content

Commit efb544f

Browse files
Martin Beganmarcjulian
Martin Began
authored andcommitted
fix(dbml): fix md parser
1 parent 297e4b7 commit efb544f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

__tests__/project.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Project', () => {
2121
const project = generateProject(projectOptions);
2222

2323
const expected =
24-
'Project Test Project {\n' +
24+
'Project "Test Project" {\n' +
2525
" database_type: 'PostgreSQL'\n" +
2626
" Note: 'Test project description'\n" +
2727
'}';
@@ -36,7 +36,7 @@ describe('Project', () => {
3636
const project = generateProject(projectOptions);
3737

3838
const expected =
39-
'Project Test Project {\n' +
39+
'Project "Test Project" {\n' +
4040
" database_type: 'PostgreSQL'\n" +
4141
" Note: '''\n" +
4242
' # Test Project Database\n' +

src/generator/project.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export function generateProject({
1717
isMd = false,
1818
}: ProjectOptions): string[] {
1919
const projectNote = isMd
20-
? `'''\n` + ` ${note.replace('\n', '\n ')} '''`
20+
? `'''\n` +
21+
` ${note
22+
.replace(/\n/g, '\n ')
23+
.replace(/(\n\s+\n)/g, '\n\n')
24+
.replace(/\s+$/g, '')}\n '''`
2125
: `'${note}'`;
2226
const project = [
2327
`Project ${name} {\n` +
@@ -46,8 +50,8 @@ export async function getProjectOptions({
4650
}
4751

4852
return {
49-
name: projectName,
50-
databaseType: projectDatabaseType,
53+
name: projectName && `"${projectName}"`,
54+
databaseType: projectDatabaseType || '',
5155
note: projectNoteMd || projectNote || '', // noteMd takes precedence
5256
isMd: projectNoteMd !== '',
5357
};

0 commit comments

Comments
 (0)