example.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {%- comment -%}
  2. Usage: include example.html content=markup [args],
  3. where content is a capture with the HTML content
  4. args can be one of the following:
  5. id - null (default)
  6. class - "bd-example" (default)
  7. optional: hide_preview - disabled (default)
  8. optional: hide_markup - disabled (default)
  9. {%- endcomment -%}
  10. {%- assign id = include.id -%}
  11. {%- assign class = include.class -%}
  12. {%- if include.hide_preview == null -%}
  13. <div{% if id %} id="{{ id }}"{% endif %} class="bd-example{% if class %} {{ class }}{% endif %}">
  14. {{- include.content -}}
  15. </div>
  16. {%- endif -%}
  17. {%- if include.hide_markup == null -%}
  18. {%- highlight html -%}
  19. {%- if include.content contains '<svg class="bd-placeholder-img' -%}
  20. {%- assign modified_content = include.content
  21. | replace: '<svg class="bd-placeholder-img', '✂️<svg class="bd-placeholder-img'
  22. | replace: '</svg>', '</svg>✂️'
  23. | split: '✂️' -%}
  24. {%- if include.content contains 'bd-placeholder-img ' -%}
  25. {%- assign image_class = include.content
  26. | replace_first: 'bd-placeholder-img', 'bd-placeholder-img ✂️'
  27. | replace: '" width="', '✂️" width="'
  28. | split: '✂️' -%}
  29. {%- assign image_class = image_class[1] | replace: 'bd-placeholder-img-lg', '' | strip -%}
  30. {%- endif -%}
  31. {%- for content_chunk in modified_content -%}
  32. {%- if content_chunk contains '<svg class="bd-placeholder-img' -%}
  33. {%- capture img_placeholder -%}
  34. <img src="..." {% if image_class %}class="{{ image_class }}" {% endif %}alt="...">
  35. {%- endcapture -%}
  36. {{- img_placeholder -}}
  37. {%- else -%}
  38. {{- content_chunk -}}
  39. {%- endif -%}
  40. {%- endfor -%}
  41. {%- else -%}
  42. {{- include.content -}}
  43. {%- endif -%}
  44. {%- endhighlight -%}
  45. {%- endif -%}