Generic bbcode wrapper for theme components

I added this feature a while back and realised I didn’t post about it. You can now use a special syntax in markdown to have it cooked and usable in theme components without having to write a plugin.

// wrapped in div.d-wrap
[wrap=baz foo=bar]Content[/wrap]

// wrapped in div.d-wrap
[wrap=baz foo=bar]
Content
[/wrap]

// wrapped in div.d-wrap
[wrap=baz foo=bar]
[/wrap]

// this one will be rendered as a span.d-wrap instead of a div.d-wrap
a [wrap=baz]Content[/wrap] b

The name of the component will be added as a data-attribute: data-wrap="baz" and every properties will also be data-attributes: data-foo="bar" on the element.

If you want to read about a real world use case, see

20개의 좋아요

Hello Joffrey,

Thanks for suggesting this feature in the other topic.

I was excited to try to use it and see if it worked for my case, however I encountered a problem.

It seems to ignore attribute names that has multiple hyphens in between and defaults to only pick the characters after the last hyphen.

I am using v2.4.0.beta2 +33, I apologize if this has been fixed in a newer commit since.

Examples:

// No multiple hyphen this works fine: data-bloodmallet="chart".
[wrap=test bloodmallet=chart]Content[/wrap]

// This way it omits "user" from the attribute name and output is data-id="1" instead of data-user-id="1".
[wrap=test2 user-id=1]Content[/wrap]

This following request is optional: Is there a way to not wrap the content inside the div with <p> tag?

Thanks for this feature and hopefully I can use it to fix my problem!

I can fix the first issue

1개의 좋아요

I just pushed a fix for this, slight difference is that I won’t support foo-bar but fooBar. So you can now write:

[wrap=foo userId=1]
[/wrap]

And you will get:

<div data-wrap="foo" data-user-id="1">
</div>
5개의 좋아요

안녕하세요 @j.jaffeux
이 기능에 감사드립니다! 다음과 같은 기능에 대해 어떻게 추가하는 것이 가장 좋은지 아시나요?

<button class="snipcart-add-item" data-item-id="product-1" data-item-url="/" data-item-name="Product #1" data-item-price="10.99">
  Add to cart
</button>

이것을 토픽에 사용하는 경우를 말입니다. 그리고 일반적으로 다음을 화이트리스트에 추가하는 방법도 궁금합니다.

class="snipcart-add-item" data-item-id="product-1"

동작하는 예시: https://codepen.io/thatfrankdev/pen/xxwRXQw

예를 들어 여기처럼, 테마 컴포넌트로 wrap을 장식해야 합니다: discourse-placeholder-theme-component/javascripts/discourse/initializers/setup.js at main · discourse/discourse-placeholder-theme-component · GitHub

4개의 좋아요

@j.jaffeux 멋진 조언 감사합니다!

최근에는 다음을 사용하여 일반 컴포넌트를 지원하도록 확장했습니다:

```customblock param=1
```

이것은 다음과 같이 변환됩니다:

<pre data-code-param="1" data-code-wrap="customblock"><code class="lang-nohighlight"></code></pre>

따라서 컴포넌트에서 data-code-wrap을 사용하여 특수한 처리를 결정할 수 있으며, 구문 강조는 비활성화됩니다.

이 패턴을 여기에서 사용했습니다:

이것은 공식 mermaid 테마 컴포넌트입니다.

9개의 좋아요