Desktop: Fixes #3903: Header links with special characters were no longer working

This commit is contained in:
Laurent Cozic
2020-10-16 22:55:48 +01:00
parent 3179117c62
commit 958e5a80b7
12 changed files with 137 additions and 38 deletions
+3 -3
View File
@@ -125,17 +125,17 @@ joplin.plugins.register({
});
```
Later you will also need a way to generate the slug for each header. A slug is an identifier which is used to link to a particular header. Essentially a header text like "My Header" is converted to "my-header". And if there's already a slug with that name, a number is appended to it. Without going into too much details, you will need the "slug" package to generate this for you, so install it using `npm i -s slug` from the root of your plugin directory.
Later you will also need a way to generate the slug for each header. A slug is an identifier which is used to link to a particular header. Essentially a header text like "My Header" is converted to "my-header". And if there's already a slug with that name, a number is appended to it. Without going into too much details, you will need the "slug" package to generate this for you, so install it using `npm i -s uslug` from the root of your plugin directory.
Then this is the function you will need for Joplin, so copy it somewhere in your file:
```typescript
const nodeSlug = require('slug');
const uslug = require('uslug');
let slugs = {};
function headerSlug(headerText) {
const s = nodeSlug(headerText);
const s = uslug(headerText);
let num = slugs[s] ? slugs[s] : 1;
const output = [s];
if (num > 1) output.push(num);