Giter Site home page Giter Site logo

Comments (8)

Ritsuka314 avatar Ritsuka314 commented on August 23, 2024

My suspicion is that our code block is hijacked by hexo's syntax highlight plugin and isn't processed my pandoc at all.

Can you try and see if any of the following two approaches works?

  1. if you don't want hexo's syntax highlight, then, in your _config.yml, add
highlight:
  enable: false

to turn off hexo's syntax highlight, and use the following syntax to pass preserve-tabs to pandoc (note the colon!!)

pandoc:
  extra:
    - preserve-tabs:  # note this colon!!

Then your code block will be processed by pandoc and have tabs preserved.

  1. if you want hexo's syntax highlight, then of course pandoc's --preserve-tabs won't be effective. In this case, add to _config.yml the following:
highlight:
  enable: false
  tab_replace: '	' # or put a tab character between the quotes instead

from hexo-renderer-pandoc.

seekstar avatar seekstar commented on August 23, 2024

None of them works:

1

highlight:
  enable: false
pandoc:
  extra:
    - preserve-tabs:  # note this colon!!

2

highlight:
  enable: false
  tab_replace: '	'

3

highlight:
  enable: true
  tab_replace: '	'

I suspect that hexo-theme-tree I use hijacks the highlighting of the code blocks. Because I have uninstalled almost all unnecessary npm modules. All modules remained are as follows:

➜  blog git:(master) ✗ npm list
[email protected] /home/searchstar/git/blog
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

I don't think there is any other module that can hijack the highlighting of code blocks.

from hexo-renderer-pandoc.

seekstar avatar seekstar commented on August 23, 2024

I removed all code related to highlighting in hexo-theme-tree: seekstar/blog@299bdce

And the code blocks become plain, e.g., http://localhost:4000/2022/09/30/c-panic/:

image

But each tab is still replaced with four whitespaces.

from hexo-renderer-pandoc.

Ritsuka314 avatar Ritsuka314 commented on August 23, 2024

I need your help to pin-point the location of the issue.

Can you locate the following code in node_modules/hexo-renderer-pandoc/index.js

  var res = spawnSync(pandoc_path, args, {
    cwd: process.cwd(),
    env: process.env,
    encoding: "utf8",
    input: src
  });

and change it to

  console.log(args) // ADDED
  console.log(data) // ADDED
  var res = spawnSync(pandoc_path, args, {
    cwd: process.cwd(),
    env: process.env,
    encoding: "utf8",
    input: src
  });
  console.log(res) // ADDED

Then render a minimal working example, such as the one below:

---
title: test codeblock
---

begin

```
function () {
    // <- put a tab here before the slashes
}
```

Then post the content of stdout here. By looking at the output I may be able to see what's causing the issue.

from hexo-renderer-pandoc.

Ritsuka314 avatar Ritsuka314 commented on August 23, 2024

Also, please don't post urls that contain localhost (like your http://localhost:4000/2022/09/30/c-panic/). Those urls are only accessible on your own machine.

from hexo-renderer-pandoc.

seekstar avatar seekstar commented on August 23, 2024

I've already tried console.log. When it is added before pandocRenderer, it prints to stdout. But when it is added in pandocRenderer, it does not print anything, even when refreshing the blog page. I suspect that the output is printed elsewhere.

By the way, the URL http://localhost:4000/2022/09/30/c-panic/ was posted to indicate the source blog post of the screenshot. It is useful if you (or someone else) clone my blog repo and hexo g && hexo s to reproduce the problem.

from hexo-renderer-pandoc.

seekstar avatar seekstar commented on August 23, 2024

I accidentally found that the re-rendering of a blog post can only be triggered by pressing ctrl+s in the post in vscode, and the tabs in the re-rendered posts are perfectly preserved. Do you have any suggestions about re-rendering all blog posts without discarding the deployment history?

from hexo-renderer-pandoc.

seekstar avatar seekstar commented on August 23, 2024

Do you have any suggestions about re-rendering all blog posts without discarding the deployment history?

I accidentally found that hexo clean && hexo g works fine.

In conclusion, a solution to this issue is disabling the highlight of hexo and passing --preserve-tabs to pandoc:

highlight:
  enable: false
pandoc:
  extra:
    - preserve-tabs:  # note this colon!!

And then hexo clean && hexo g and optionally hexo s or hexo d to make the changes take effect. This works for hexo-theme-tree I use out-of-the-box, i.e., there is no need to remove highlight-related code, and the theme can still highlight the tabs-preserved code blocks outputted by pandoc.

Thank you for your attention!

from hexo-renderer-pandoc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.