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

Closed
@Joaxin

Description

@Joaxin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions