-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Word count for markdown updated with test #1354
Conversation
".png)"; | ||
|
||
@Test | ||
@Transactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要 @transactional 注解,这里并没有任何数据库操作。
@Slf4j | ||
public class BasePostServiceImplTest { | ||
|
||
String markdownWithPicture = "字数测试,测试这篇文章加上图片有没有问题\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
希望能够增加更多的测试用例。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
真是 markdown 有很多种格式,希望能够考虑完全。建议先把测试用例写好,再写代码。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我会增加一些测试来完善
src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java
Outdated
Show resolved
Hide resolved
*/ | ||
|
||
public static long markdownWordCount(String originalContent) { | ||
originalContent = MarkdownUtils.renderHtml(originalContent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太明白你这里为什么要再渲染一次 Markdown,在上面已经渲染过了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
而且这应该处理的是 html 内容,而不是 Markdown,使用 Markdown 作为主线是不是有点问题?直接改为处理 HTML 就好了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里markdown都可以转为html,html直接去掉标签,再去掉一些特殊字符就可以直接取length了,这边的测试样例应该怎么写呢?是以markdown为基础测试还是以html为基础做测试呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里markdown都可以转为html,html直接去掉标签,再去掉一些特殊字符就可以直接取length了,这边的测试样例应该怎么写呢?是以markdown为基础测试还是以html为基础做测试呢?
以 html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以先写成markdown的形式再进行渲染,将渲染完的结果进行测试吗?
src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java
Outdated
Show resolved
Hide resolved
import run.halo.app.utils.MarkdownUtils; | ||
|
||
@Slf4j | ||
public class HTMLWordCountTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要增加一个复杂的测试用例(比如将以下所有测试用例合并)、空字符串、null 以及纯文本格式。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非常感谢你的 PR。如果能够再添加一个纯 html 文本的测试就更好了。同时修复一下 Checkstyle 问题。
* Word count for markdown updated with test * HTML word count updated with test * Convert pattern to static final variable * More HTML test added * Workaround URL added * CS304 issue link URL added * Pure HTML Test added, checkstyle checked Co-authored-by: MasterWanna <[email protected]>
Word count algorithm for markdown updated ignoring what should be removed.