Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title anchor bug #107

Closed
Ibadichan opened this issue Sep 14, 2023 · 5 comments
Closed

Title anchor bug #107

Ibadichan opened this issue Sep 14, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Ibadichan
Copy link

Describe the issue

config({
  markdownItConfig(mdit) {
    mdit.use(ancher, {
      permalink: ancher.permalink.headerLink(),
    });
  },
});

this configuration removes id from title ->
expected result:

<h2 id="title"><a class="header-anchor" href="#title">Title</a></h2>

current:

<h2><a class="header-anchor" href="#title">Title</a></h2>

Procedure version

markdown-it-anchor=8.6.7, md-editor-rt=4.6.1

Reproduction link

No response

@imzbf
Copy link
Owner

imzbf commented Sep 14, 2023

Failed to get the title. There is a quick solution

const mdHeadingId = (t: string, l: number, index: number) => `heading-${index}`;

<MdEditor mdHeadingId={mdHeadingId} />

@Ibadichan
Copy link
Author

My config:

import React from 'react';
import { MdPreview, config } from 'md-editor-rt';
import ancher from 'markdown-it-anchor';
import slugify from 'slugify';
import 'md-editor-rt/lib/preview.css';

const mdHeadingId = (text) => slugify(text, {
  lower: true,
  strict: true,
  replacement: '-',
});

config({
  markdownItConfig(mdit) {
    mdit.use(ancher, {
      slugify: mdHeadingId, // to slugify cyrillic symbols
      permalink: ancher.permalink.headerLink(),
    });
  },
});

function App() {
  return <MdPreview modelValue={"## foo bar"} mdHeadingId={mdHeadingId} />
}

Output:

<h2 id="" tabindex="-1" data-line="0"><a class="header-anchor" href="#foo-bar">foo bar</a></h2>

@imzbf
Copy link
Owner

imzbf commented Sep 14, 2023

Not like this, the reason is with configuration ancher.permalink.headerLink, cannot get right text, first parameter of mdHeadingId.

I'll fix it in 4.6.2, but now this is a quick solution

@imzbf imzbf self-assigned this Sep 14, 2023
@imzbf imzbf added the bug Something isn't working label Sep 14, 2023
imzbf added a commit that referenced this issue Sep 14, 2023
@imzbf
Copy link
Owner

imzbf commented Sep 14, 2023

or try install beta

yarn add md-editor-rt@beta

@imzbf
Copy link
Owner

imzbf commented Sep 17, 2023

The latest version has been released

@imzbf imzbf closed this as completed Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants