Skip to content
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

使用prism渲染出现的Bugs #4460

Closed
5 tasks done
jerryc127 opened this issue Aug 2, 2020 · 12 comments
Closed
5 tasks done

使用prism渲染出现的Bugs #4460

jerryc127 opened this issue Aug 2, 2020 · 12 comments
Labels
highlight non-english Requires the attention of a multi-lingual maintainer question Needs help in usage

Comments

@jerryc127
Copy link

jerryc127 commented Aug 2, 2020

Check List

Please check followings before submitting a new issue.

Expected behavior

Actual behavior

How to reproduce?

  • Step1
  • Step2
  • etc...

Is the problem still there under "Safe mode"?

Environment & Settings

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

Your site _config.yml (Optional)

Your theme _config.yml (Optional)

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

Your package.json package.json

Others

  1. 使用prism渲染 多出了一段文字 :hexoPostRenderEscape–>
    使用prism渲染代码,发现页面多了一段文字 :hexoPostRenderEscape–>
    试过用highlightjs渲染,并没有这段文字
    image

我用的是hexo-theme-unit-test的这篇文章code-highlight测试
还有这段文字上面的html代码没有line number生成。。
image

  1. prism没有适配hexo自带的标签外挂?
    image

我在适配prismjs有点疑问,希望能解答

  1. 按照hexo官网的教程,我引入了line-number.js(https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js),但是发现有些代码框并没有生成line-number,
    以上面那篇文字为例
    image
    image
    好几个代码块是没有插入line-number html

  2. 在pug中进行判断 config.prismjs && config.prismjs.enable 当配置文件中没有prisim这段配置(考虑到升级5.0的人没有去补全这段配置),运行会出现报错
    image

这个要怎么解决?

@jerryc127 jerryc127 changed the title 使用prism渲染 多出了一段文字 :hexoPostRenderEscape–> 使用prism渲染出现的Bugs Aug 2, 2020
@SukkaW SukkaW added highlight question Needs help in usage non-english Requires the attention of a multi-lingual maintainer labels Aug 2, 2020
@SukkaW
Copy link
Member

SukkaW commented Aug 10, 2020

  1. 使用prism渲染 多出了一段文字 :hexoPostRenderEscape–>
    使用prism渲染代码,发现页面多了一段文字 :hexoPostRenderEscape–>
    试过用highlightjs渲染,并没有这段文字

@stevenjoezhang @curbengh

hexoPostRenderEscape tags are added by backtick code block filter and should be removed by PostRenrCache#loadContent:

hexo/lib/hexo/post.js

Lines 26 to 29 in b7d15b9

loadContent(str) {
if (str.includes('hexoPostRenderEscape')) {
str = str.replace(/<!--hexoPostRenderEscape:/g, '').replace(/:hexoPostRenderEscape-->/g, '');
}

data.content = cacheObj.loadContent(content);

I am not sure but I wonder if disableNunjucks or marked.js built-in escape is the culprit. I will bring up the test cases then.

@SukkaW
Copy link
Member

SukkaW commented Aug 11, 2020

  1. 使用prism渲染 多出了一段文字 :hexoPostRenderEscape–>
    使用prism渲染代码,发现页面多了一段文字 :hexoPostRenderEscape–>
    试过用highlightjs渲染,并没有这段文字

The issue might be related with PrismJS/prism#2516.

@curbengh
Copy link
Contributor

prism没有适配hexo自带的标签外挂?

hexojs/hexo-util#227

@curbengh
Copy link
Contributor

curbengh commented Aug 14, 2020

renders fine for me in landscape theme, even without #4472

test

I'm using your prismjs config:

highlight:
  enable: false
  line_number: false
  auto_detect: false
  tab_replace: '  '
  hljs: true
  wrap: false

prismjs:
  enable: true
  preprocess: true
  line_number: true
  tab_replace: ''

Can you attach your _config.yml (remove any sensitive values if preferred) and package.json?

@jerryc127
Copy link
Author

I don't why,
i try in 'butterfly','next' and 'landscape', it have a same problem

Do you test this two case, it work ?

  1. In markdown, use the Tag Plugins, such as 'pullquote', there is no blank line in the list and code block, it will rendering errors
  2. In markdown, use the Tag Plugins, such as 'pullquote', the list and code block have blank lines, but there are spaces in front of the code block, it will rendering errors

I just only change the theme in _config

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Hexo
subtitle: ''
description: ''
keywords:
author: John Doe
language: en
timezone: ''

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
  enable: true # Open external links in new tab
  field: site # Apply to the whole site
  exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: false
  line_number: true
  auto_detect: false
  tab_replace: ''
  wrap: true
  hljs: false
prismjs:
  enable: true
  preprocess: true
  line_number: true
  tab_replace: ''

# 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: uncategorized
category_map:
tag_map:

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# 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
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

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

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: ''

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.0.0"
  },
  "dependencies": {
    "hexo": "github:SukkaW/hexo#fix-4460",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-index": "^1.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-marked": "^3.0.0",
    "hexo-renderer-pug": "^1.0.0",
    "hexo-renderer-stylus": "^1.1.0",
    "hexo-server": "^1.0.0",
    "hexo-theme-butterfly": "^3.0.0",
    "hexo-theme-next": "^8.0.0-rc.5"
  }
}

image

@curbengh
Copy link
Contributor

  1. In markdown, use the Tag Plugins, such as 'pullquote', there is no blank line in the list and code block, it will rendering errors
---
title: test one
date: 2019-11-05 00:00:01
---

{% pullquote %}

1. Test Test
```diff
+comments:
+  # Up to two comments system, the first will be shown as default
+  # Choose: Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments
+  use:
+  # - Valine
+  # - Disqus
+  text: true # Display the comment name next to the button
+  # lazyload: The comment system will be load when comment element enters the browser's viewport.
+  # If you set it to false, the comment count will be invalid
+  lazyload: false
+  count: false # Display comment count in top_img
```

{% endpullquote %}

test-one-result

  1. In markdown, use the Tag Plugins, such as 'pullquote', the list and code block have blank lines, but there are spaces in front of the code block, it will rendering errors
---
title: test two
date: 2019-11-06 00:00:01
---

{% pullquote %}

1. Test Test

  ```diff
  +comments:
  +  # Up to two comments system, the first will be shown as default
  +  # Choose: Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments
  +  use:
  +  # - Valine
  +  # - Disqus
  +  text: true # Display the comment name next to the button
  +  # lazyload: The comment system will be load when comment element enters the browser's viewport.
  +  # If you set it to false, the comment count will be invalid
  +  lazyload: false
  +  count: false # Display comment count in top_img
  ```

{% endpullquote %}

test-two

@curbengh
Copy link
Contributor

package.json

May not be related, but try upgrading hexo-generator-index and hexo-server to "^2.0.0".

@curbengh
Copy link
Contributor

I managed to temporarily reproduce the issue, I set 'next' theme:

# _config.yml
theme: next

even though I've removed it, then the rendered page showed landscape theme and the rendering issue.

Can you try installing the theme the previous way?

1 git clone https://github.com/theme-next/hexo-theme-next themes/next
2. rm -rf node_modules && npm install
3. hexo clean && hexo server

I'm guessing cache conflict.

@jerryc127
Copy link
Author

I managed to temporarily reproduce the issue, I set 'next' theme:

# _config.yml
theme: next

even though I've removed it, then the rendered page showed landscape theme and the rendering issue.

Can you try installing the theme the previous way?

1 git clone https://github.com/theme-next/hexo-theme-next themes/next
2. rm -rf node_modules && npm install
3. hexo clean && hexo server

I'm guessing cache conflict.

still rendering errors

@jerryc127
Copy link
Author

jerryc127 commented Aug 15, 2020

I managed to temporarily reproduce the issue, I set 'next' theme:

# _config.yml
theme: next

even though I've removed it, then the rendered page showed landscape theme and the rendering issue.

Can you try installing the theme the previous way?

1 git clone https://github.com/theme-next/hexo-theme-next themes/next
2. rm -rf node_modules && npm install
3. hexo clean && hexo server

I'm guessing cache conflict.

i delete the folder and run 'hexo init' in new folder
test the landscape and 'butterfly',
it work now
so it cause by cache conflict?

my blog folder still have this issues,
so i need to delete and run hexo-init to solve the problem?
have a another way to solve?

@curbengh
Copy link
Contributor

my blog folder still have this issues,
so i need to delete and run hexo-init to solve the problem?

you can backup "_config.yml" and "source/" folder, then delete blog and hexo-init, finally restore those files.

@curbengh
Copy link
Contributor

Looks like the issue is fixed?
#4472 #4476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
highlight non-english Requires the attention of a multi-lingual maintainer question Needs help in usage
Projects
None yet
Development

No branches or pull requests

3 participants