hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.64k stars 4.87k forks source link

How to contain a single quote or a double quote in images' title and alt? #4715

Closed alohaia closed 2 years ago

alohaia commented 3 years ago

Check List

Please check followings before submitting a new issue.

Question

I simply included a single quote in an image's title and alt. It isn't rendered as expected. Actually, the image didn't even appear on the result.

{% asset_img "Gower's_sign.png" "Gower's sign'Gower's sign" %}

Environment & Settings

Node.js & npm version

# node -v
v16.3.0
# npm -v
7.16.0

Hexo and Plugin version(npm ls --depth 0)

hexo-site@0.0.0 /home/aloha/blog
├── hexo-deployer-git@3.0.0
├── hexo-generator-archive@1.0.0
├── hexo-generator-category@1.0.0
├── hexo-generator-feed@3.0.0
├── hexo-generator-index@2.0.0
├── hexo-generator-searchdb@1.3.3
├── hexo-generator-sitemap@2.1.0
├── hexo-generator-tag@1.0.0
├── hexo-next-fireworks@1.0.2 (git+ssh://git@github.com/next-theme/hexo-next-fireworks.git#cccfe84bccccc91f4dae24b7ceb4050ee324fb59)
├── hexo-related-popular-posts@5.0.1
├── hexo-renderer-ejs@1.0.0
├── hexo-renderer-markdown-it-plus@1.0.4 (git+ssh://git@github.com/CHENXCHEN/hexo-renderer-markdown-it-plus.git#f2dd1b25738992efc391ba9da398a9c6a7efb105)
├── hexo-renderer-stylus@2.0.1
├── hexo-server@2.0.0
├── hexo@5.4.0
└── markdown-it-task-checkbox@1.0.6

Your package.json package.json

{
    "name": "hexo-site",
    "version": "0.0.0",
    "private": true,
    "scripts": {
        "build": "hexo generate",
        "clean": "hexo clean",
        "deploy": "hexo deploy",
        "server": "hexo server"
    },
    "hexo": {
        "version": "5.4.0"
    },
    "dependencies": {
        "hexo": "^5.0.0",
        "hexo-deployer-git": "^3.0.0",
        "hexo-generator-archive": "^1.0.0",
        "hexo-generator-category": "^1.0.0",
        "hexo-generator-feed": "^3.0.0",
        "hexo-generator-index": "^2.0.0",
        "hexo-generator-searchdb": "^1.3.3",
        "hexo-generator-sitemap": "^2.1.0",
        "hexo-generator-tag": "^1.0.0",
        "hexo-next-fireworks": "github:next-theme/hexo-next-fireworks",
        "hexo-related-popular-posts": "^5.0.1",
        "hexo-renderer-ejs": "^1.0.0",
        "hexo-renderer-markdown-it-plus": "github:CHENXCHEN/hexo-renderer-markdown-it-plus",
        "hexo-renderer-stylus": "^2.0.0",
        "hexo-server": "^2.0.0",
        "markdown-it-task-checkbox": "^1.0.6"
    }
}

Others

I edited node_modules/hexo/lib/plugins/tag/img.js so I can use \\sq and \\dq instead.

          title = typeof match[1] == 'string'
                    ? match[1].replace(/\\sq/g, "'").replace(/\\dq/g, '"')
                    : '';
          alt = typeof match[2] == 'string'
                    ? match[2].replace(/\\sq/g, "'").replace(/\\dq/g, '"')
                    : '';
{% asset_img "Gower's sign.png" "Gowers\\sqs sign'Gowers\\sqs sign'" %}
stevenjoezhang commented 2 years ago

Fixed in https://github.com/hexojs/hexo/pull/5112 Thanks for your feedback!