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

fix(highlight): code in blockquote #110

Closed
wants to merge 1 commit into from

Conversation

curbengh
Copy link
Contributor

@curbengh curbengh commented Oct 12, 2019

Currently, when inserting a codeblock inside a blockquote, e.g.

> ```json
> {
>   "test": 123
> }
> ```

results in,

> {
>  "test": 123
> }

Expected behavior is

{
 "test": 123
}

This fixes hexojs/hexo#2969 & hexojs/hexo#3318.

However, this fix doesn't apply to cmd or dos codeblock because the line may start with >, e.g.

> ipconfig

cmd codeblock in blockquote,

> ```cmd
>> ipconfig
> ```

would result in,

> ipconfig
>

A workaround is to remove > from the closing backtick,

https://pastebin.com/s94kaD4j

which should render as,

> ipconfig

or use {% blockquote %} tag plugin.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 95.23% when pulling f09d4fd on curbengh:blockquote into b292332 on hexojs:master.

html = html.replace(/>.*/g, (str) => {
str = str.replace(/^&gt;(\s)?(?!<\/span>)/, '');
return str;
}).trimRight();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a workaround to remove unnecessary new line from

>```

// https://github.com/hexojs/hexo/issues/2969
if (lang !== 'cmd' && lang !== 'dos') {
html = html.replace(/&gt;.*/g, (str) => {
str = str.replace(/^&gt;(\s)?(?!<\/span>)/, '');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<span> exclusion is a workaround to be compatible with sublanguage highlight.

@curbengh curbengh changed the title fix: code in blockquote fix(highlight): code in blockquote Oct 12, 2019
@curbengh curbengh requested a review from a team October 13, 2019 00:53
@curbengh curbengh mentioned this pull request Oct 13, 2019
27 tasks
@curbengh curbengh requested review from a team and removed request for a team October 13, 2019 23:34
@curbengh
Copy link
Contributor Author

curbengh commented Oct 13, 2019

In regards to https://github.com/hexojs/hexo-util/issues/108, it may be more suitable to put this workaround in backtick_code_block.js, but currently I'm not sure how well prism/atom handle blockquote.

If later we find prism/atom cannot handle blockquote, then this workaround shall be moved to hexo.

@seaoak
Copy link
Member

seaoak commented Oct 14, 2019

I think a workaround in the hexo (backtick_code_block.js) might be better
because the module is responsible to the extraction of code block (and blockquote).

I found examples of markdown notation in the GitHub Help:

There are many examples which current backtick_code_block.js can not process correctly:

As shown in Example 229,
the question "how many '>' at the head of line should be removed"
is only answerable by Markdown parser.
A code-highlighting module is not responsible to this question.
(And also it is not affected by "lang" parameter of the code block.)

I'm trying to improve backtick_code_block.js,
but it is almost like developing small set of "marked".
I started from check the behavior of "marked" about the examples....

@curbengh
Copy link
Contributor Author

Superseded by hexojs/hexo#3765.

@curbengh curbengh closed this Oct 14, 2019
@curbengh curbengh deleted the blockquote branch October 14, 2019 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The filter backtick_code_block makes markdown broken.
3 participants