From c0602be7e1e8159e846e1eacfdc23e65f90eb3d2 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:31:17 +0200 Subject: [PATCH 1/6] Refactor the slugifier to work like the one used by GitHub This commit fixes #107 --- src/System/Documents/Slugifier.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/System/Documents/Slugifier.ts b/src/System/Documents/Slugifier.ts index 678c47ca..796f098d 100644 --- a/src/System/Documents/Slugifier.ts +++ b/src/System/Documents/Slugifier.ts @@ -1,5 +1,3 @@ -import { slugify } from "transliteration"; - /** * Provides the functionality to generate slugs. */ @@ -45,7 +43,7 @@ export class Slugifier { let baseName = this.Slugify(text); - let counter = 1; + let counter = 0; let slug = baseName; while (this.Slugs.includes(slug)) @@ -76,12 +74,6 @@ export class Slugifier */ protected Slugify(text: string): string { - return slugify( - text, - { - lowercase: true, - separator: "-", - ignore: [] - }); + return text.replace(/[^\p{L}\p{M}\p{Nd}\p{Nl}\p{Pc}\- ]/gu, "").toLowerCase().replace(/ /g, "-"); } } From c240216f9747c7039f40db1b3d9ad1a12c9f6898 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:31:30 +0200 Subject: [PATCH 2/6] Refactor the tests accordingly --- .../common/System/Documents/Slugifier.test.ts | 35 +++++++++++++++++-- .../System/Tasks/ConversionRunner.test.ts | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/tests/common/System/Documents/Slugifier.test.ts b/src/tests/common/System/Documents/Slugifier.test.ts index b268c32b..04b2895b 100644 --- a/src/tests/common/System/Documents/Slugifier.test.ts +++ b/src/tests/common/System/Documents/Slugifier.test.ts @@ -29,7 +29,7 @@ export function SlugifierTests(): void slugifier = new Slugifier(); }); - suite( + suite.only( nameof((slugifier) => slugifier.CreateSlug), () => { @@ -50,9 +50,40 @@ export function SlugifierTests(): void for (let i = 0; i < max; i++) { - strictEqual(slugifier.CreateSlug(slug), kebabCase(`${slug}${i + 2}`)); + strictEqual(slugifier.CreateSlug(slug), kebabCase(`${slug}${i + 1}`)); } }); + + test( + "Checking whether multiple spaces in a row are not removed…", + () => + { + let count = random.integer(1, 10); + + strictEqual( + slugifier.CreateSlug(`hello${" ".repeat(count)}world`), + `hello${"-".repeat(count)}world`); + }); + + test( + "Checking whether punctations are removed…", + () => + { + strictEqual( + slugifier.CreateSlug( + "hello " + + "[]!'#$%&()*+,./:;<=>?@\\^{|}~`。,、;:?!…—·¨‘’“”~‖∶"'`|〃〔〕〈〉《》「」『』.〖〗【】()[]{}" + + "world"), + "hello-world"); + }); + + test( + "Checking whether unicode-characters aren't stripped away…", + () => + { + strictEqual(slugifier.CreateSlug("你好, world!'"), "你好-world"); + strictEqual(slugifier.CreateSlug("Krøv"), "krøv"); + }); }); suite( diff --git a/src/tests/common/System/Tasks/ConversionRunner.test.ts b/src/tests/common/System/Tasks/ConversionRunner.test.ts index 2cede513..36b2a465 100644 --- a/src/tests/common/System/Tasks/ConversionRunner.test.ts +++ b/src/tests/common/System/Tasks/ConversionRunner.test.ts @@ -889,7 +889,7 @@ export function ConversionRunnerTests(context: ITestContext): void { let result = load(parser.render(content)); strictEqual(result(`#${kebabCase(headerText)}`).length, 1); - strictEqual(result(`#${kebabCase(`${headerText}2`)}`).length, 1); + strictEqual(result(`#${kebabCase(`${headerText}1`)}`).length, 1); } }); From e441ab214514b90b73ef1ecb6670afcbb5d4b0a8 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:32:25 +0200 Subject: [PATCH 3/6] Refactor test-timeouts --- src/test/CommonHooks.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/CommonHooks.ts b/src/test/CommonHooks.ts index f803b0ec..080258c1 100644 --- a/src/test/CommonHooks.ts +++ b/src/test/CommonHooks.ts @@ -26,8 +26,9 @@ export function CommonHooks(): ITestContext }); teardown( - async () => + async function() { + this.timeout(5 * 1000); Resources.Culture = originalCulture; await interceptor.Context.CloseEditors(); }); From 3dba5c197904641b3b4b1c978cc1704adaa0f1a6 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:36:23 +0200 Subject: [PATCH 4/6] Add changelog-entries --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e5df447..76ae017b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## MarkdownConverter [Unreleased] +### Updated + - The internal slugifier to make anchors look like the ones produced by GitHub + Once more, thanks to [@Postur](https://github.com/Postur) for pointing this out! [Show differences](https://github.com/manuth/MarkdownConverter/compare/v5.0.0...dev) From 584ec38b3cdcf3e478d7d06cc27ecce91921ad2a Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:37:00 +0200 Subject: [PATCH 5/6] Update the changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ae017b..95565a4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## MarkdownConverter [Unreleased] + +[Show differences](https://github.com/manuth/MarkdownConverter/compare/v5.0.1...dev) + +## MarkdownConverter v5.0.1 ### Updated - The internal slugifier to make anchors look like the ones produced by GitHub Once more, thanks to [@Postur](https://github.com/Postur) for pointing this out! -[Show differences](https://github.com/manuth/MarkdownConverter/compare/v5.0.0...dev) +[Show differences](https://github.com/manuth/MarkdownConverter/compare/v5.0.0...v5.0.1) ## MarkdownConverter v5.0.0 ### Breaking From d48bb8b4ce868bf5db89ac1c4ba9ea51a9fa48b3 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 5 Oct 2021 11:37:28 +0200 Subject: [PATCH 6/6] Bump the version number --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c0aa5103..e8752069 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "markdown-converter", - "version": "5.0.0", + "version": "5.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "markdown-converter", - "version": "5.0.0", + "version": "5.0.1", "license": "MIT", "dependencies": { "@manuth/package-json-editor": "^2.2.3", diff --git a/package.json b/package.json index 1f0d6c28..4d520e49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-converter", - "version": "5.0.0", + "version": "5.0.1", "private": true, "description": "A markdown-converter for vscode", "author": "Manuel Thalmann (https://nuth.ch)",