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

Would like the ability to have basic markdown formatting in the description; field of a post. #1764

Closed
1 task done
steveng57 opened this issue May 20, 2024 · 5 comments
Closed
1 task done
Labels
duplicate This issue or pull request already exists

Comments

@steveng57
Copy link

Checklist

Is your feature request related to a problem? Please describe

The new description: field in the Front Matter YAML is awesome and works great. It would be even better if it could handle markdown used in the description, for bolding and italisizing etc.

For example:

description: This is a REALLY cool thing.
Would be rendered as:

This is a REALLY cool thing.

Describe the solution you'd like

The new description: field in the Front Matter YAML is awesome and works great. It would be even better if it could handle markdown used in the description, for bolding and italisizing etc.

Describe alternatives you've considered

No response

Additional context

No response

@steveng57 steveng57 added the enhancement New feature or request label May 20, 2024
@huanyushi
Copy link
Contributor

huanyushi commented May 20, 2024

Just delete escape in _includes/post-description.html, see here, can solve your problem.

{%- comment -%}
  Get post description or generate it from the post content.
{%- endcomment -%}

{%- assign max_length = include.max_length | default: 200 -%}

{%- capture description -%}
{%- if post.description -%}
  {{- post.description -}}
{%- else -%}
  {%- include no-linenos.html content=post.content -%}
  {{- content | markdownify | strip_html -}}
{%- endif -%}
{%- endcapture -%}

- {{- description | strip | truncate: max_length | escape -}}
+ {{- description | strip | truncate: max_length  -}}

Effect:
image

The function of escape in Liquid can be found here,

Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn’t change strings that don’t have anything to escape.

In Jekyll blogs, the 'escape' filter is typically used to HTML-escape the output, ensuring that when rendered on a webpage, it won't be interpreted as HTML tags, thereby mitigating potential security risks such as XSS (Cross-Site Scripting) attacks.

In the above code snippet in _includes/post-description.html, the 'escape' filter is applied after the 'truncate' filter. This means it ensures that the text after truncation does not contain any unescaped HTML tags. The purpose of this is to maintain the security of the page by ensuring that the truncated text length does not include any unescaped HTML tags.

If you delete escape, it may lead to potential bugs. I believe this is why the author closed the issues you previously opened.

@huanyushi
Copy link
Contributor

huanyushi commented May 20, 2024

For example, If you make the last word of the description displayed in home bold, you will find that all other post previews have become bold. Other layouts of the page will also be broken.

This is just one of the bugs I know about.

So I don't suggest you do this

@steveng57
Copy link
Author

Thanks for the detailed explanation, much appreciated! I am a bit smarter now.

would there be anything wrong with:

{%- capture description -%}
{%- if post.description -%}
  {{- post.description  | strip | truncate: max_length | markdownify | escape -}}
{%- else -%}

@huanyushi
Copy link
Contributor

huanyushi commented May 21, 2024

{%- capture description -%}
{%- if post.description -%}
  {{- post.description  | strip | truncate: max_length | markdownify | escape -}}
{%- else -%}

@steveng57 It doesn't work.

@cotes2020
Copy link
Owner

Duplicate of #1739

@cotes2020 cotes2020 marked this as a duplicate of #1739 May 25, 2024
@cotes2020 cotes2020 closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2024
@cotes2020 cotes2020 added duplicate This issue or pull request already exists and removed enhancement New feature or request labels May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants