mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-18 20:16:34 +02:00
Desktop: Fixes #3903: Header links with special characters were no longer working
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user