hexojs / hexojs/hexo

Rendering issue with Tag Plugin

Open
#5,309 1 comment 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
41.8k
Forks
41
PR merge metrics
No merged PRs in 30d

Description

## Check List

- [x] I have already read [Docs page](https://hexo.io/docs/) & [Troubleshooting page](https://hexo.io/docs/troubleshooting)
- [x] I have already searched existing issues and they are not help to me
- [x] I examined error or warning messages and it's difficult to solve
- [x] Using [the latest](https://github.com/hexojs/hexo/releases) version of Hexo (run `hexo version` to check)
- [x] Node.js is higher than [minimum required version](https://hexo.io/docs/#Minimum-required-Node-js-version)

## Expected behavior

Fyi, I'm using .

with

```markdown
{% label @v1 %} v2

{% label @v3 %} v4
```

I would expect two paragraphs generated.

```html

v1 v2


v3 v4


```

## Actual behavior

No paragraphs generated.

```html
v1 v2

v3 v4
```

## How to reproduce?

is ready for your convenience.

## Is the problem still there under "Safe mode"?

No HTML generated.

## Environment & Settings

**Node.js & npm version(`node -v && npm -v`)**

```
v18.18.0
9.8.1
```

**Your site `_config.yml`** (Optional)

The only configuration I changed is `theme: next`, and no configuration for the theme itself.

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

```
hexo-site@0.0.0 C:\Users\14517\Desktop\test-blog\blog
├── hexo-generator-archive@2.0.0 -> .\node_modules\.pnpm\hexo-generator-archive@2.0.0\node_modules\hexo-generator-archive
├── hexo-generator-category@2.0.0 -> .\node_modules\.pnpm\hexo-generator-category@2.0.0\node_modules\hexo-generator-category
├── hexo-generator-index@3.0.0 -> .\node_modules\.pnpm\hexo-generator-index@3.0.0\node_modules\hexo-generator-index
├── hexo-generator-tag@2.0.0 -> .\node_modules\.pnpm\hexo-generator-tag@2.0.0\node_modules\hexo-generator-tag
├── hexo-renderer-ejs@2.0.0 -> .\node_modules\.pnpm\hexo-renderer-ejs@2.0.0\node_modules\hexo-renderer-ejs
├── hexo-renderer-marked@6.1.1 -> .\node_modules\.pnpm\hexo-renderer-marked@6.1.1\node_modules\hexo-renderer-marked
├── hexo-renderer-stylus@3.0.0 -> .\node_modules\.pnpm\hexo-renderer-stylus@3.0.0\node_modules\hexo-renderer-stylus
├── hexo-server@3.0.0 -> .\node_modules\.pnpm\hexo-server@3.0.0\node_modules\hexo-server
├── hexo-theme-landscape@1.0.0 -> .\node_modules\.pnpm\hexo-theme-landscape@1.0.0\node_modules\hexo-theme-landscape
├── hexo-theme-next@8.18.2 -> .\node_modules\.pnpm\hexo-theme-next@8.18.2\node_modules\hexo-theme-next
└── hexo@6.3.0 -> .\node_modules\.pnpm\hexo@6.3.0\node_modules\hexo
```

**Your package.json `package.json`**

```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": "6.3.0"
},
"dependencies": {
"hexo": "^6.3.0",
"hexo-generator-archive": "^2.0.0",
"hexo-generator-category": "^2.0.0",
"hexo-generator-index": "^3.0.0",
"hexo-generator-tag": "^2.0.0",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-marked": "^6.0.0",
"hexo-renderer-stylus": "^3.0.0",
"hexo-server": "^3.0.0",
"hexo-theme-landscape": "^1.0.0",
"hexo-theme-next": "^8.18.2"
}
}
```

## Others

I tried to dig out the root cause and fix it. It seems to be related to the way how Hexo implements Tag Plugins. I change

https://github.com/hexojs/hexo/blob/ad056527cee2c55fa961cc84a56f44ea55404c63/lib/hexo/post.js#L16-L17

to

```javascript
const rSwigPlaceHolder = /swig(?:<|<)!--\uFFFC(\d+)--(?:>|>)/g;
const rCodeBlockPlaceHolder = /code(?:<|<)!--\uFFFC(\d+)--(?:>|>)/g;
```

, and

https://github.com/hexojs/hexo/blob/ad056527cee2c55fa961cc84a56f44ea55404c63/lib/hexo/post.js#L37-L39

to

```javascript
static escapeContent(cache, flag, str) {
return `${flag}`;
}
```

. It solves the problem above, while it breaks unit tests. Which is another part I do not quite understand. For example, should not the following test

https://github.com/hexojs/hexo/blob/ad056527cee2c55fa961cc84a56f44ea55404c63/test/scripts/hexo/post.js#L1249-L1276

expect

```html

{{ 1 + 1 }} 3 {{ 2 + 2 }}
Text

Raw1

AnotherText

Raw2


```

? With a single `\n` between texts, how can `Another Text` be wrapped in a paragraph?

Finally, one another question, why Hexo is using an outdated `markedjs` with some copied code snippets and uncleared (to me) customization?

- An issue raised in `Next` (in Chinese), [使用 label 标签外挂在开头时,会导致无法换行 #707](https://github.com/next-theme/hexo-theme-next/issues/707)

Thanks for your work!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.