hexojs / hexo

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

代码片段中 HTML 片段会被渲染成 HTML,升级7.3.0后无法构建。HTML fragments in code snippets are rendered as HTML and cannot be built after upgrading 7.3.0. #5521

Closed note4 closed 2 months ago

note4 commented 2 months ago

Check List

Expected behavior

代码片段只直接按输入的代码展示源代码,而不进行渲染成HTML。 The code snippet only displays the source code directly as entered, without rendering it to HTML.

Actual behavior

代码片段被解析成了HTML。 The code snippet is parsed into HTML.

image

问题示范:https://yijile.com/log/572/

Model question: https://yijile.com/log/572/

How to reproduce?

在文章中使用输入以下代码片段: Use enter the following code snippet in the article:


---
layout: touch
title: Url 列表
permalink: /collect1/
---

<h1 class="mt-4">Publications</h1>

{% assign publications = site.url | sort: "year" | reverse %}
{% for pub in publications %}
<div class="pubitem">
  <div class="pubtitle"><a href="{{ pub.url }}">{{ pub.title }}</a></div>
  <div class="pubauthors">{{ pub.authors }}</div>
  <div class="pubinfo">{{ pub.publication }}, {{ pub.year}}</div>
  <a href="{{pub.url}}"><i class="fas fa-link"></i> Project Page</a>
  <hr>
</div>
{% endfor %}

Is the problem still there under Safe mode?

Still exist

Your Node.js & npm version

Node.js v20.10.0

npm -v
10.5.0

Your Hexo and Plugin version

├── hexo-algolia@1.3.2
├── hexo-browsersync@0.3.0
├── hexo-deployer-git@4.0.0
├── hexo-filter-nofollow@2.0.2
├── hexo-generator-alias@1.0.0
├── hexo-generator-archive@2.0.0
├── hexo-generator-category@2.0.0
├── hexo-generator-feed@3.0.0
├── hexo-generator-index@3.0.0
├── hexo-generator-json-content@4.2.3
├── hexo-generator-search@2.4.3
├── hexo-generator-sitemap@3.0.1
├── hexo-generator-tag@2.0.0
├── hexo-html-minifier@1.0.0
├── hexo-renderer-ejs@2.0.0
├── hexo-renderer-jade@0.3.0
├── hexo-renderer-less@4.0.0
├── hexo-renderer-marked@6.3.0
├── hexo-renderer-stylus@3.0.1
├── hexo-server@3.0.0
├── hexo-sitemap-generator@1.0.2
├── hexo-submit-urls-to-search-engine@2.1.0
└── hexo@6.3.0

Your package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "6.3.0"
  },
  "dependencies": {
    "hexo": "^6.3.0",
    "hexo-algolia": "^1.3.2",
    "hexo-browsersync": "^0.3.0",
    "hexo-deployer-git": "^4.0.0",
    "hexo-filter-nofollow": "^2.0.2",
    "hexo-generator-alias": "^1.0.0",
    "hexo-generator-archive": "^2.0.0",
    "hexo-generator-category": "^2.0.0",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-index": "^3.0.0",
    "hexo-generator-json-content": "^4.2.3",
    "hexo-generator-search": "^2.4.3",
    "hexo-generator-sitemap": "^3.0.1",
    "hexo-generator-tag": "^2.0.0",
    "hexo-html-minifier": "^1.0.0",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-jade": "^0.3.0",
    "hexo-renderer-less": "^4.0.0",
    "hexo-renderer-marked": "^6.2.0",
    "hexo-renderer-stylus": "^3.0.1",
    "hexo-server": "^3.0.0",
    "hexo-sitemap-generator": "^1.0.2",
    "hexo-submit-urls-to-search-engine": "^2.1.0"
  },
  "scripts": {
    "dev": "hexo server -p $PORT",
    "build": "hexo generate"
  }
}

Your site's _config.yml (Optional)


language: zh
timezone: Asia/Hong_Kong

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://yijile.com
root: /
permalink: 'log/:title/'
permalink_defaults: null

# 比如,一个页面的永久链接是 http://example.com/foo/bar/index.html
pretty_urls:
  trailing_index: false
# 此时页面的永久链接会变为 http://example.com/foo/bar/

# Directory
source_dir: source
public_dir: public
tag_dir: tag
archive_dir: archives/
category_dir: /
code_dir: downloads/code
i18n_dir: ':lang'
skip_render:
  - 'robots.txt'
  - 'test.html'

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
# external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: false
  line_number: true
  auto_detect: true
  tab_replace: true

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: '-date'

# Category & Tag
default_category: note   
category_map:
    笔记: note

tag_map:
    博客: blog

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: anhei-landscape #yijile15 #icarus #landscape #material-flow

# Deployment
## Docs: https://hexo.io/docs/deployment.html
#deploy:
#- type: git
#  repo: git@git.dev.tencent.com:andynode/note.teai.org.git
#  branch: master

html_minifier:  
  collapseBooleanAttributes: true
  collapseWhitespace: true
  # Ignore '<!-- more -->' https://hexo.io/docs/tag-plugins#Post-Excerpt
  # ignoreCustomComments: [ !!js/regexp /^\s*more/]
  removeComments: true
  removeEmptyAttributes: true
  removeScriptTypeAttributes: true
  removeStyleLinkTypeAttributes: true
  minifyJS: true
  minifyCSS: true
  exclude: 
  - '107b5c7a20b238e0f10740279a350b88.html'

# clean_css:
#   exclude: 
#     - 'test.min.css'

alias: # README https://github.com/hexojs/hexo-generator-alias ## page: redirect 跳出,alias 跳入且支持多个
  /index.php/log/336.html: /log/336/

nofollow:
  enable: true
  field: site
  exclude:
    - 'yijile.com'

feed:
  type:
    - atom
    - rss2
  path:
    - atom.xml
    - feed/rss/index.xml
  # limit: 20
  # hub:
  # content:
  # content_limit: 140
  # content_limit_delim: ' '
  # order_by: -date
  # icon: icon.png
  # autodiscovery: true
  # template:

  # Generate both atom and rss2 feeds

sitemaps:
  path: 
    - sitemap1.xml
    - sitemap1.txt
    - sitemap.html
  template: ./sitemap_template.xml
  template_txt: ./sitemap_template.txt
  template_html: ./sitemap_template.html
  # rel: true
  tags: true
  categories: true

sitemap:
  path: 
    - sitemap.xml
    - sitemap.txt
    # - sitemap.html
  template: ./sitemap_template.xml
  template_txt: ./sitemap_template.txt
  # template_html: ./sitemap_template.html
  rel: true
  tags: true
  categories: true

Others

如果升级到最新版(7.3.0),将无法运行 hexo s。 If you upgrade to the latest version (7.3.0), you will not be able to run hexo s.

FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: tab.repeat is not a function
    at C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo-util\dist\highlight.js:73:44        
    at String.replace (<anonymous>)
    at replaceTabs (C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo-util\dist\highlight.js:73:16)
    at highlightUtil (C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo-util\dist\highlight.js:35:20)
    at Hexo.highlightFilter (C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo\dist\plugins\highlight\highlight.js:41:12)
    at SyntaxHighlight.exec (C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo\dist\extend\syntax_highlight.js:21:24)
    at C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo\dist\plugins\filter\before_post_render\backtick_code_block.js:49:44
    at String.replace (<anonymous>)
    at Hexo.backtickCodeBlock (C:\Users\yjl\Documents\hexo-yijile\node_modules\hexo\dist\plugins\filter\before_post_render\backtick_code_block.js:11:36)
...

升级后的 package.json Upgraded package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "7.3.0"
  },
  "dependencies": {
    "hexo": "^7.3.0",
    "hexo-algolia": "^1.3.2",
    "hexo-browsersync": "^0.3.0",
    "hexo-deployer-git": "^4.0.0",
    "hexo-filter-nofollow": "^2.0.2",
    "hexo-generator-alias": "^1.0.0",
    "hexo-generator-archive": "^2.0.0",
    "hexo-generator-category": "^2.0.0",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-index": "^4.0.0",
    "hexo-generator-json-content": "^4.2.3",
    "hexo-generator-search": "^2.4.3",
    "hexo-generator-sitemap": "^3.0.1",
    "hexo-generator-tag": "^2.0.0",
    "hexo-html-minifier": "^1.0.0",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-jade": "^0.3.0",
    "hexo-renderer-less": "^4.0.0",
    "hexo-renderer-marked": "^6.2.0",
    "hexo-renderer-stylus": "^3.0.1",
    "hexo-server": "^3.0.0",
    "hexo-sitemap-generator": "^1.0.2",
    "hexo-submit-urls-to-search-engine": "^2.1.0"
  },
  "scripts": {
    "dev": "hexo server -p $PORT",
    "build": "hexo generate"
  }
}