te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>html - Add a Hyperlinked Image with CSS Classes in Jekyll Chirpy Theme - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Add a Hyperlinked Image with CSS Classes in Jekyll Chirpy Theme - Stack Overflow

programmeradmin3浏览0评论

I want to add hyperlinks to the images in a blockquote that are switched by the dark/light mode toggle. I am using the modified template, generated from Jekyll chirpy-starter.

I have two cases:

Case 1 (Markdown Syntax)

[![Alt Text](/assets/images/header/image-dark.png){: .dark .w-25 }]()

In the Case 1 output:

❌ Hyperlink appears
✅ CSS classes (.dark w-25) don't appear

Case 2 (HTML Syntax)

<a href=";>
    <img src="/assets/images/header/image-dark.png" class="dark w-25" alt="Alt Text">
</a>

In the Case 2 output:

❌ Hyperlink does not appear
✅ CSS classes (.dark w-25) appear

Desired behavior:

  • Hyperlink should appear.
    • Clicking the image will open the hyperlink on a new tab instead of the usual image pop-up in the chirpy theme.
  • CSS classes of the image (.dark .w-25) should appear.
    • .dark: The image should appear in dark mode only.
    • .w-25: The image width will be reduced to 25%.

Operations I already tried

To have both working hyperlink and CSS styling, I tried:

<a href=";>
    <img src="/assets/images/header/image-dark.png" class="dark-mode-img w-25" alt="Alt Text">
</a>

Then, in _sass/layout/urlimage.scss, I defined:

.mode-dark .dark-mode-img {
    content: url('/assets/images/header/image-dark.png');
}

But I couldn't get my desired output. What can I do?


As an example page _pages/testing.md:

---
layout: page
title: Testing
permalink: /testing/
---

Click the image to go to the source.  

1.
[![Alt Text](/assets/images/header/image-dark.png){: .dark .w-25 }]()

2.
<a href=";>
    <img src="/assets/images/header/image-dark.png" class="dark w-25" alt="Alt Text">
</a>

Solution (?)

<a href=";>
    <img src="/assets/images/header/image-dark.png" class="dark-mode-img w-25" alt="Alt Text">
</a>

The HTML conversion of the body content is like:

<div class="content" style="text-align: justify;">
  <style>
    .content ul, .content ol {
      text-align: left !important;
    }
  </style>

  <p>Click the image to go to the source.</p>

  <p>
    1.
    <a href="; class="img-link" target="_blank" rel="noopener noreferrer">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>

  <p>
    2.
    <a href="; target="_blank" rel="noopener noreferrer"> </a>
    <a href="/website-theme/assets/images/header/image-dark.png" class="popup img-link dark w-25">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>

  <p>Solution (?)</p>

  <p>
    <a href="; target="_blank" rel="noopener noreferrer"> </a>
    <a href="/website-theme/assets/images/header/image-dark.png" class="popup img-link dark-mode-img w-25">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>
</div>

I want to add hyperlinks to the images in a blockquote that are switched by the dark/light mode toggle. I am using the modified template, generated from Jekyll chirpy-starter.

I have two cases:

Case 1 (Markdown Syntax)

[![Alt Text](/assets/images/header/image-dark.png){: .dark .w-25 }](https://example/source)

In the Case 1 output:

❌ Hyperlink appears
✅ CSS classes (.dark w-25) don't appear

Case 2 (HTML Syntax)

<a href="https://example/source">
    <img src="/assets/images/header/image-dark.png" class="dark w-25" alt="Alt Text">
</a>

In the Case 2 output:

❌ Hyperlink does not appear
✅ CSS classes (.dark w-25) appear

Desired behavior:

  • Hyperlink should appear.
    • Clicking the image will open the hyperlink on a new tab instead of the usual image pop-up in the chirpy theme.
  • CSS classes of the image (.dark .w-25) should appear.
    • .dark: The image should appear in dark mode only.
    • .w-25: The image width will be reduced to 25%.

Operations I already tried

To have both working hyperlink and CSS styling, I tried:

<a href="https://example/source">
    <img src="/assets/images/header/image-dark.png" class="dark-mode-img w-25" alt="Alt Text">
</a>

Then, in _sass/layout/urlimage.scss, I defined:

.mode-dark .dark-mode-img {
    content: url('/assets/images/header/image-dark.png');
}

But I couldn't get my desired output. What can I do?


As an example page _pages/testing.md:

---
layout: page
title: Testing
permalink: /testing/
---

Click the image to go to the source.  

1.
[![Alt Text](/assets/images/header/image-dark.png){: .dark .w-25 }](https://example/source)

2.
<a href="https://example/source">
    <img src="/assets/images/header/image-dark.png" class="dark w-25" alt="Alt Text">
</a>

Solution (?)

<a href="https://example/source">
    <img src="/assets/images/header/image-dark.png" class="dark-mode-img w-25" alt="Alt Text">
</a>

The HTML conversion of the body content is like:

<div class="content" style="text-align: justify;">
  <style>
    .content ul, .content ol {
      text-align: left !important;
    }
  </style>

  <p>Click the image to go to the source.</p>

  <p>
    1.
    <a href="https://example/source" class="img-link" target="_blank" rel="noopener noreferrer">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>

  <p>
    2.
    <a href="https://example/source" target="_blank" rel="noopener noreferrer"> </a>
    <a href="/website-theme/assets/images/header/image-dark.png" class="popup img-link dark w-25">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>

  <p>Solution (?)</p>

  <p>
    <a href="https://example/source" target="_blank" rel="noopener noreferrer"> </a>
    <a href="/website-theme/assets/images/header/image-dark.png" class="popup img-link dark-mode-img w-25">
      <img src="/website-theme/assets/images/header/image-dark.png" alt="Alt Text" loading="lazy">
    </a>
  </p>
</div>
Share Improve this question edited yesterday raf asked Feb 17 at 13:55 rafraf 2551 gold badge3 silver badges16 bronze badges 9
  • Since the Markdown is converted to HTML, it should be the same case as only HTML, right? Or is it converted to different HTML? (use your browser's developer tools to inspect) – mb21 Commented Feb 18 at 8:30
  • I think so, they are converted to different HTML. – raf Commented Feb 18 at 10:07
  • Here's the example page if you want to inspect: github/rafisics/website-theme/blob/… rafisics.github.io/website-theme/testing – raf Commented Feb 18 at 10:11
  • can you edit your question and include to what html they are converted? – mb21 Commented Feb 18 at 10:23
  • @mb21 I have included that in the question. – raf Commented Feb 18 at 12:40
 |  Show 4 more comments

1 Answer 1

Reset to default 0

My issue is solved. I get my desired output if I simply use:

[![Alt Text](/assets/images/header/image-dark.png)](https://example/source)
{: .dark .w-25 }

✅ Hyperlink appears
✅ CSS classes (.dark .w-25) appear

发布评论

评论列表(0)

  1. 暂无评论