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

feat(prism): caption #227

Merged
merged 1 commit into from
Aug 15, 2020
Merged

feat(prism): caption #227

merged 1 commit into from
Aug 15, 2020

Conversation

curbengh
Copy link
Contributor

Feature requested in hexojs/hexo#4460 by @jerryc127

@coveralls
Copy link

coveralls commented Aug 13, 2020

Coverage Status

Coverage increased (+0.004%) to 97.428% when pulling 874e9a4 on curbengh:prism-caption into b34456a on hexojs:master.

lib/prism.js Outdated Show resolved Hide resolved
@SukkaW
Copy link
Member

SukkaW commented Aug 13, 2020

prismjs just doesn't support caption. Instead of adding caption support, what about simply ignoring it?

@curbengh
Copy link
Contributor Author

curbengh commented Aug 13, 2020

highlight.js doesn't support it either, but Hexo enhance the triple backtick to support it. It's currently available for hexo's highlight.js, this PR simply bring feature parity to prismjs.

@SukkaW
Copy link
Member

SukkaW commented Aug 13, 2020

So should we use other element instead? <figcaption> without <figure> is invalid.

@curbengh
Copy link
Contributor Author

curbengh commented Aug 14, 2020

Using figcaption is quite convenient because existing highlight.js style can be easily adapted since theme usually set it as display: block; to display it properly, not inline like below.

samp

Anyhow, we could try <samp class="caption">caption-text</samp>?

<kbd>, <sub> and <small> are another candidate.

@SukkaW
Copy link
Member

SukkaW commented Aug 14, 2020

<figure> element; the <figcaption> element must be its first or last child.
https://mdn.io/figcaption

<kbd> shouldn't be an option as well: most css already apply its own style: kbd

<small> is an inline element thus shouldn't be used as well.

My suggestion is add a <div><span>caption</span><a href="">link</a></div> right after <pre> and before <code>:

<pre>
  <div>
    <span>caption</span>
    <a href>link</a>
  </div>
  <code>
    <!-- code -->
  </code>
</pre>

@curbengh
Copy link
Contributor Author

curbengh commented Aug 14, 2020

backtick_code_block.js already wraps in <span>,

// just wrap in <div>?
const codeCaption = caption ? `<div>${caption}</div>` : '';

Edit: updated

will update highlight.js in next PR:

return `<pre>${figCaption}<code class="${classNames}">${content}</code></pre>`;

@curbengh curbengh merged commit bf42b66 into hexojs:master Aug 15, 2020
@curbengh curbengh deleted the prism-caption branch August 15, 2020 12:14
curbengh added a commit to curbengh/hexo-util that referenced this pull request Aug 15, 2020
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
curbengh added a commit to curbengh/hexo-util that referenced this pull request Aug 17, 2020
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
@curbengh curbengh mentioned this pull request Aug 17, 2020
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
nevilm-lt pushed a commit to nevilm-lt/hexo-util that referenced this pull request Apr 22, 2022
- BREAKING CHANGE: <figcaption> is replaced with <div> when wrap is disabled
- hexojs#227 (comment)
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.

3 participants