Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/md-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ class MarkdownCLI {
sanitizeText(text) {
return text
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(
/[^a-z0-9\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af\s-]/g,
''
)
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kayvan/markdown-tree-parser",
"version": "1.5.1",
"version": "1.6.0",
"description": "A powerful JavaScript library and CLI tool for parsing and manipulating markdown files as tree structures using the remark/unified ecosystem",
"type": "module",
"main": "index.js",
Expand Down
17 changes: 17 additions & 0 deletions test/test-cjk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Document Title

## 章节一

This is the first section.

## 章二

This is the second section.

### セクション 2.1

This is a subsection.

## Another Section

This is another section.
36 changes: 36 additions & 0 deletions test/test-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,42 @@ This document has links too:
);
});

await test('CLI explode command with CJK characters', async () => {
const cjkTestFile = path.resolve(__dirname, 'test-cjk.md');
const outputDir = path.join(testDir, 'cjk-exploded');
const result = await runCLI(['explode', cjkTestFile, outputDir]);

assert(
result.code === 0,
`Command should succeed, got exit code ${result.code}\nstderr: ${result.stderr}`
);

const files = await fs.readdir(outputDir);
assert(files.includes('index.md'), 'Should create index.md');
assert(files.includes('章节一.md'), 'Should create file with Chinese slug');
assert(files.includes('章二.md'), 'Should create file with Chinese slug');
assert(
files.includes('another-section.md'),
'Should create file with English slug'
);

// Check the index file for correct links
const indexPath = path.join(outputDir, 'index.md');
const indexContent = await fs.readFile(indexPath, 'utf-8');
assert(
indexContent.includes('[章节一](./章节一.md)'),
'Should link to Chinese filename'
);
assert(
indexContent.includes('[章二](./章二.md)'),
'Should link to Chinese filename'
);
assert(
indexContent.includes('[セクション 2.1](./章二.md#セクション-21)'),
'Should link to Japanese subsection'
);
});

await cleanupTests();

// Summary
Expand Down