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

Word count for markdown updated with test #1354

Merged
merged 7 commits into from
May 2, 2021
Merged

Word count for markdown updated with test #1354

merged 7 commits into from
May 2, 2021

Conversation

MasterWanna
Copy link
Contributor

Word count algorithm for markdown updated ignoring what should be removed.

@ruibaby ruibaby added the kind/bug Categorizes issue or PR as related to a bug. label Apr 18, 2021
".png)";

@Test
@Transactional
Copy link
Member

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" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

希望能够增加更多的测试用例。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

真是 markdown 有很多种格式,希望能够考虑完全。建议先把测试用例写好,再写代码。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我会增加一些测试来完善

*/

public static long markdownWordCount(String originalContent) {
originalContent = MarkdownUtils.renderHtml(originalContent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太明白你这里为什么要再渲染一次 Markdown,在上面已经渲染过了。

https://github.com/halo-dev/halo/pull/1354/files#diff-f9ad8998cd130957a3f023e24fdba020245e51c8fe132be355dc02200800fba9R285

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

而且这应该处理的是 html 内容,而不是 Markdown,使用 Markdown 作为主线是不是有点问题?直接改为处理 HTML 就好了。

Copy link
Contributor Author

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为基础做测试呢?

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以先写成markdown的形式再进行渲染,将渲染完的结果进行测试吗?

import run.halo.app.utils.MarkdownUtils;

@Slf4j
public class HTMLWordCountTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要增加一个复杂的测试用例(比如将以下所有测试用例合并)、空字符串、null 以及纯文本格式。

@MasterWanna MasterWanna requested review from JohnNiang and LIlGG April 30, 2021 13:05
Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常感谢你的 PR。如果能够再添加一个纯 html 文本的测试就更好了。同时修复一下 Checkstyle 问题。

@MasterWanna MasterWanna requested a review from JohnNiang May 2, 2021 03:31
@JohnNiang JohnNiang merged commit 15381e6 into halo-dev:master May 2, 2021
ruibaby pushed a commit to ruibaby/halo that referenced this pull request Jun 11, 2021
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants