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

首页文章摘要显示代码行号Bug #1591

Closed
oqyj opened this issue Apr 13, 2017 · 14 comments
Closed

首页文章摘要显示代码行号Bug #1591

oqyj opened this issue Apr 13, 2017 · 14 comments

Comments

@oqyj
Copy link

oqyj commented Apr 13, 2017

当我站点设置中开启代码行号:

highlight:
  enable: true
  line_number: true

并在主题设置中设置自动摘要:

auto_excerpt:
  enable: true
  length: 150

那么要出现一个问题,在首页生成的文件摘要会出现摘要显示为一串数字,应该是代码行号:

发表于 2017-03-17 | 分类于 JAVA
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import java.util.*;class Fruit { public String t ...
阅读全文 »

@Acris
Copy link
Collaborator

Acris commented Apr 14, 2017

确实有这个问题。
另外不建议使用自动摘要。

@ivan-nginx
Copy link
Collaborator

@ciitoo can u make screen to see it?
I'm not use auto excerpt, but it must work fine, i think.

@oqyj
Copy link
Author

oqyj commented Apr 21, 2017

You can visit the web site http://playwww.pw

@ivan-nginx
Copy link
Collaborator

@ciitoo can u show your .md file with that post?

@oqyj
Copy link
Author

oqyj commented Apr 21, 2017

@ivan-nginx Article as long as to ``` start will appear such problems
---
title: 文件的拷贝方式比较
categories: JAVA
date: 2017-3-16
---

```
public void test5 () throws Exception {

	FileInputStream fis = new FileInputStream ("D:\\aaa.chm");
	FileOutputStream fos = new FileOutputStream ("e:\\bbb.chm");
	
	//1===传统拷贝方式====
	byte[] buf = new byte[1024];
	int len = 0;
	while ((len = fis.read (buf)) != -1) {
		fos.write (buf, 0, len);
	}
	//===传统拷贝方式====
	
	FileChannel ii = fis.getChannel ();
	FileChannel io = fos.getChannel ();
	
	//2===文件通道方式===
	io.transferFrom (ii,0,ii.size ());
	ii.transferTo (0,ii.size (),io);
	//===文件通道方式===
	
	//3===文件内存映射方式(速度最快)===
	MappedByteBuffer mbb = ii.map (FileChannel.MapMode.READ_ONLY, 0, ii.size ());
	io.write (mbb);
	//===文件内存映射方式===
	
	ii.close ();
	io.close ();
}

```

@ivan-nginx
Copy link
Collaborator

ivan-nginx commented Apr 21, 2017

@ciitoo is that write in .md file? Why backslashes there?
Ok, u can try to make something like this:

---
title: 文件的拷贝方式比较
categories: JAVA
date: 2017-3-16
---

<!-- More -->

your code here...

@oqyj
Copy link
Author

oqyj commented Apr 21, 2017

@ivan-nginx Not, so just to let you see the source md file,

@ivan-nginx
Copy link
Collaborator

ivan-nginx commented Apr 21, 2017

@ciitoo u can may just screenshot with file.
I understand what code block in code block - not possible.

Also, try to change Theme from Next on anyone other. If same error will appear, then it's not theme Next bug and need to write issue on hexo-renderer-marked.

Awaiting for answer from u...

@oqyj
Copy link
Author

oqyj commented Apr 21, 2017

.......
@ivan-nginx
I know, I just don't want to join <!-- More --> in md file, I prefer the auto_excerpt, hope the theme author to fix this Bug

@ivan-nginx
Copy link
Collaborator

@ciitoo is this theme bug or not?

Also, try to change Theme from Next on anyone other. If same error will appear, then it's not theme Next bug and need to write issue on hexo-renderer-marked.

Awaiting for answer from u...

@oqyj
Copy link
Author

oqyj commented Apr 21, 2017

@ivan-nginx
Oh, I'm sorry, I just used this one theme, I saw many theme, also only like this one theme, I thought it was the theme of the Bug,sorry, thank you

@ivan-nginx
Copy link
Collaborator

@ciitoo but i'm not sure what is not theme bug. I just asked a question for u.
Need to find theme with autoexcerpt and test it.

@ivan-nginx
Copy link
Collaborator

ivan-nginx commented Apr 21, 2017

I find this plugin: https://github.com/akfish/hexo-filter-richer
And this plugin: https://github.com/chekun/hexo-excerpt

May be nice for fix auto_excerpt if this bug of Next theme.
P.S. I can't find any theme with auto_excerpt option. :/

@ivan-nginx
Copy link
Collaborator

ivan-nginx commented Apr 21, 2017

Ok, let i explain to you about autoexcerpt option.

In next/layout/_macro/post.swig is code to make autoexcerpt in Next theme:

        {% elif theme.auto_excerpt.enable %}
          {% set content = post.content | striptags %}
          {{ content.substring(0, theme.auto_excerpt.length) }}
          {% if content.length > theme.auto_excerpt.length %}...{% endif %}

And striptags function — is internal filter of swig engine (Next based in swig).
This function is located in node_modules/swig/lib/filters.js file and looks like this:

/**
 * Strip HTML tags.
 *
 * @example
 * // stuff = '<p>foobar</p>';
 * {{ stuff|striptags }}
 * // => foobar
 *
 * @param  {*}  input
 * @return {*}        Returns the same object as the input, but with all string values stripped of tags.
 */
exports.striptags = function (input) {
  var out = iterateFilter.apply(exports.striptags, arguments);
  if (out !== undefined) {
    return out;
  }

  return input.toString().replace(/(<([^>]+)>)/ig, '');
};

In swig docs we may found this function too and there is no additionsl arguments (allowed tags, for e.g. ):

// stuff = '<p>foobar</p>';
{{ stuff|striptags }}
// => foobar

In another words — striptags function strips all tags with autoexcerpt option and code blocks (<figure>/<pre>) too. So, there is not possible for now to exclude needed tags from autoexcerpt with standart scripts and functions.


Another way, u can install external module and use it instead of Next autoexcerpt option.


UPD: hexo-filter-richer is not working and repository is 3 years old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants