Skip to content

I am writing a plugin that support image caption, but when it serves with docsify, only even order image works correctly #1613

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

Closed
1 task done
Joaxin opened this issue Jul 21, 2021 · 1 comment

Comments

@Joaxin
Copy link

Joaxin commented Jul 21, 2021

Bug Report

Steps to reproduce

The key code is here

                hook.beforeEach(function (content) {
                    let mark_imgReg = /!\[(?<alt>[^\]]*)\]\((?<filename>.*?)(?=\"|\))(?<title>\".*\")?\)/g;
                    let mark_img = content.match(mark_imgReg);
                    if (mark_img) {
                        mark_img.forEach(function (item, idx) {
                            console.log(item, idx)
                            let match = mark_imgReg.exec(item);
                            console.log(match)
                            if (match) {
                                if (match.groups.alt) {
                                    content = content.replace(item, `<figure>
<img src="${match.groups.filename}" width="100%" alt="${match.groups.alt}" title = "${match.groups.title}">
    <figcaption>${match.groups.alt}</figcaption>
</figure>`)
                                } else {
                                    content = content.replace(item, `<figure>
<img src="${match.groups.filename}" width="100%" alt="${match.groups.alt}" title = "${match.groups.title}">
</figure>`)
                                }
                            }
                        })
                    }
                })

What is current behaviour

See screenshots, only even order image works correctly

What is the expected behaviour

All images work correctly

Other relevant information

  • Bug does still occur when all/other plugins are disabled?

  • Your OS: Windows_NT 10.0.19041 win32 x64

  • Node.js version: 16.1.0

  • npm/yarn version: 7.11.2

  • Browser version: Version 91.0.4472.114 (Official Build) (64-bit)

  • Docsify version: 4.12.1

  • Docsify plugins: None, I create a project without any plugins the problem still happens.

@Joaxin Joaxin changed the title Writing image caption plugins, but only even image works I am writing a plugin that support image caption, but when it serves with docsify, only even order image works correctly Jul 21, 2021
@Koooooo-7
Copy link
Member

Hi.
IMO, It is not our side problem.
When you change to rematch a new string by exec(), you need reset the lastIndex manually.

                            console.log(item, idx)
                            let match = mark_imgReg.exec(item);
                            console.log(match)
                            mark_imgReg.lastIndex = 0

FYI. Finding successive matches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants