taufik-nurrohman / parsedown-extra-plugin

Configurable Markdown to HTML converter with Parsedown Extra.
MIT License
60 stars 13 forks source link

data-* attributes aren't copied to parent #26

Closed bricebou closed 3 years ago

bricebou commented 3 years ago

When I do:

``` {.language-shell .command-line data-output=2-20}

only classes are reported to the <pre> parent element even with

$Parsedown->codeAttributesOnParent = true;

Am I missing something?

taufik-nurrohman commented 3 years ago

Try:

$Parsedown->codeAttributesOnParent = ['class', 'data-output', 'id'];
bricebou commented 3 years ago

Yeah, that works great ! Is it possible to use a regular expression to replicate all data attributes ? Something like data-* ?

I was wondering also why there is $blockCodeClassFormat which permits to add "language-" while we find the blockFencedCode function in Parsedown which does the same ?

Thanks again and in advance :)

taufik-nurrohman commented 3 years ago

Is it possible to use a regular expression to replicate all data attributes ?

It is not possible for simplicity and maybe security too.

I was wondering also why there is $blockCodeClassFormat which permits to add language-

It was for the class name dot prefix behavior in my extension. See the feature about automatic language- prefix in code block.

bricebou commented 3 years ago

It is not possible for simplicity and maybe security too.

Yeah, seems logic :)

It was for the class name dot prefix behavior in my extension. See the feature about automatic language- prefix in code block.

I understand the logic but I've got this : language-language-class while doing this:

```shell

I I do that:

```{shell .command-line data-output="2-20"}

I get <pre class="command-line" data-output="2-20"><code shell="shell">.

I try this:

```shell {.command-line data-output="2-20"}

And I get <pre class="command-line" data-output="2-20"><code>...

What am I missing ?

taufik-nurrohman commented 3 years ago

I understand the logic but I've got this language-language-class

Looks like a bug to me.

For the second example, think of any characters between { and } as literal HTML attributes. It is just that .foo and #foo is special here.

In general, you can do foo="bar", foo='bar' and foo=bar. When you have attribute without value, it will be parsed to attribute="attribute" in the output.

Think of shell in {shell foo="bar"} as disabled and readonly in <input disabled readonly foo="bar">.

The third example should be invalid. If it works somehow, that will be out of the specs.

taufik-nurrohman commented 3 years ago

What happen if you do this?

``` {class="shell" data-output="2-20"}
bricebou commented 3 years ago

I get <pre class="shell" data-output="2-20"><code>.

bricebou commented 3 years ago

Is there a way to combine multiple attributes along with the auto prefix "language-" ?

Is there a way to get this

<pre class="language-shell command-line" data-output="2-20"><code>

besides of

``` {class="language-shell command-line" data-output="2-20"}

Thanks again !

taufik-nurrohman commented 3 years ago

I am afraid that this request will expand to other valid elements that have advance attribute features. You don’t want to have a heading tag with class names that automatically be prefixed by language-.

### Test {.foo}

Expect <h3 class="foo"> but get <h3 class="language-foo">.

bricebou commented 3 years ago

Right !

Anyway, maybe ParsedownExtraPlugin should test if there is a space between the code block tag ``` and the class:

```html

is already parsed by Parsedown as

<pre><code class="language-html">

ParsedownExtraPlugin should add 'language-' only when we have:

``` html

No ?

bricebou commented 3 years ago

Hum... Parsedown adds also "language-" when parsing :

``` html
bricebou commented 3 years ago

Thanks !